Prerequisites
Problem Statement
Currently, the project lacks a standardized way to expose application functionality to AI agents and LLM-powered tools. As AI-driven development workflows become more prevalent, there's no mechanism for:
- AI coding assistants to discover and invoke backend capabilities
- External MCP clients to interact with the application's services
- Controlled integration with third-party MCP servers
- Secure, rate-limited access to application tools via the Model Context Protocol
This limits the project's ability to participate in the emerging AI tooling ecosystem with external ecosystem and prevents seamless integration with modern AI development workflows.
Proposed Solution
Integrate FastMCP to provide a production-ready Model Context Protocol (MCP) server implementation with the following capabilities:
Core Features
-
Dual-Mode MCP Server
- Local
stdio transport for developer tools and IDE integrations
- Remote HTTP transport mounted into the existing FastAPI application
- Single codebase supporting both deployment modes
-
Curated Tool Registry
- Expose safe, read-only tools initially (health checks, metadata, search, fetch)
- Centralized tool registration to maintain explicit control over the API surface
- Pagination and response size limiting for production safety
-
Production Security
- JWT bearer authentication for remote HTTP access
- Redis-backed rate limiting per subject and endpoint
- Request logging with correlation IDs
- Prometheus metrics integration
-
Internal MCP Client Manager
- Connect to approved upstream MCP servers
- Support HTTP and stdio upstream transports
- Tool allowlisting and circuit breaker patterns
- Graceful connection lifecycle management
Implementation Approach
- Add MCP server under
src/app/shared/mcp/
- Reuse existing infrastructure (Redis, Prometheus, logging, JWT auth)
- Mount HTTP endpoint at configurable path (e.g.,
/mcp)
- Combine FastMCP lifespan with existing FastAPI lifespan
- Add comprehensive settings for server and client configuration
Configuration
Environment-based configuration for:
- Server enable/disable flags
- Transport modes (stdio/HTTP)
- Authentication requirements
- Rate limiting parameters
- Upstream server allowlist
- Tool enablement controls
Alternatives Considered
-
Custom MCP Implementation
- More control but significantly more development effort
- Would need to reimplement protocol handling, transport layers, and tooling
- FastMCP provides battle-tested implementation with FastAPI integration
-
Direct REST API Exposure
- Doesn't provide MCP protocol compatibility
- AI tools increasingly expect MCP for standardized discovery and invocation
- Lacks the structured tool/resource/prompt model MCP provides
-
Third-Party MCP Proxy
- Adds external dependency and deployment complexity
- Doesn't integrate with existing auth/observability stack
- Less control over security and rate limiting
-
Full API Auto-Generation
- Security risk: exposes entire API surface automatically
- Proposed solution uses curated, explicit tool registration
- Allows gradual, controlled expansion of MCP capabilities
Additional Context
Benefits
- AI-First Development: Enable AI coding assistants to interact with the application
- Ecosystem Integration: Join the growing MCP ecosystem (Claude Desktop, Cline, etc.)
- Controlled Expansion: Start with safe read-only tools, expand deliberately
- Production-Ready: Built-in auth, rate limiting, metrics, and observability
- Developer Experience: Local stdio mode for rapid development and testing
Technical Considerations
- FastMCP is built specifically for FastAPI integration
- Supports both SSE and HTTP POST transports
- Maintains compatibility with existing middleware and lifecycle management
- Minimal dependencies: reuses project infrastructure
Example Use Cases
- AI coding assistant queries application health and metadata
- External monitoring tools discover available endpoints via MCP
- Controlled integration with documentation or search MCP servers
- Future: AI agents perform complex multi-step operations via curated tools
References
Priority
Medium
Prerequisites
Problem Statement
Currently, the project lacks a standardized way to expose application functionality to AI agents and LLM-powered tools. As AI-driven development workflows become more prevalent, there's no mechanism for:
This limits the project's ability to participate in the emerging AI tooling ecosystem with external ecosystem and prevents seamless integration with modern AI development workflows.
Proposed Solution
Integrate FastMCP to provide a production-ready Model Context Protocol (MCP) server implementation with the following capabilities:
Core Features
Dual-Mode MCP Server
stdiotransport for developer tools and IDE integrationsCurated Tool Registry
Production Security
Internal MCP Client Manager
Implementation Approach
src/app/shared/mcp//mcp)Configuration
Environment-based configuration for:
Alternatives Considered
Custom MCP Implementation
Direct REST API Exposure
Third-Party MCP Proxy
Full API Auto-Generation
Additional Context
Benefits
Technical Considerations
Example Use Cases
References
Priority
Medium