MCP Server Development Framework

SSE

by mlzoo

208 394 downloads Not rated yet MIT

About

A professional framework for enterprise-level Model Context Protocol (MCP) tool development, integrating FastAPI and FastAPI-MCP to automate converting traditional APIs into AI-callable MCP tools.

Details

Transport
SSE
License
MIT

Explore

- MCP Tool Standardization: Automatically convert traditional FastAPI endpoints into AI model-callable MCP tools
- Interface-Implementation Separation: Support clear separation between interface definitions and implementations, facilitating testing and environment switching
- Dependency Injection Design: Leverage FastAPI's dependency injection mechanism for flexible component composition and decoupling
- Complete Development Pipeline: Provide comprehensive toolchain support from development to testing and deployment
- Example-Driven Documentation: Demonstrate best practices through practical examples to accelerate onboarding

This framework is particularly suitable for:
- AI tool development teams
- Developers looking to transform existing APIs into AI tools
- Organizations implementing standardized microservice architectures

This framework uses uv as its package manager, providing faster dependency resolution and virtual environment management. For installation instructions, see the uv official documentation.


make install

class DataServiceImpl(DataService):
def __init__(self, database_url: str):
self.db = Database(database_url)

def get_data(self, id: str) -> Dict[str, Any]:
return self.db.query("SELECT * FROM data WHERE id = :id", {"id": id})

def get_data_service() -> DataService:

return DataServiceMockImpl() # or return DataServiceImpl(settings.DATABASE_URL)
```

get_health

Check the health status of the mcp-forge API.

validate_license

Check whether the license key is valid and retrieve plan identity (valid, reason, plan, tenant_id, valid_until). Always returns 200 — use reason when valid=false. For usage numbers, call get_quota instead.

get_quota

Check quota usage: plan, sources used, slots remaining and expiry date. Call this before any generate_from_* tool to warn the user if the quota is near the limit.

generate_from_openapi

Generate a production-ready MCP server from an OpenAPI/Swagger spec URL. Server-side parsing — provide only the spec URL.

generate_from_graphql

Generate an MCP server from a GraphQL endpoint via server-side introspection. Works on dev/staging APIs with introspection enabled.

generate_from_website

Generate an MCP server by analyzing API patterns on a website (HTML + JavaScript). Best for server-rendered pages; SPAs may yield partial results.

generate_async

Advanced: submit a generation job with a pre-parsed DiscoveryPayload (source_type + base_url). Use generate_from_openapi / generate_from_graphql / generate_from_website for automatic server-side parsing instead.

get_job_status

Check the status of an async generation job. Call this after generate_from_* or generate_async returns a job_id (generation was still running after ~37s).

from fastapi import FastAPI, Depends
from fastapi_mcp import FastApiMCP
from pydantic import BaseModel, Field

app = FastAPI()

@app.post("/items/search", operation_id="search_items")
async def search_items(
request: ItemRequest,
service: DataService = Depends(get_data_service)
):
result = service.search_items(request.query, request.limit)
return {"items": result["items"], "total": len(result["items"])}

In this framework, dependency injection is primarily used for:

1. Service Instance Management: Injecting service implementations into API endpoints
2. Environment Adaptation: Selecting different service implementations based on runtime environment
3. Resource Lifecycle Management: Managing the creation and release of resources like database connections

FastAPI-MCP can automatically convert FastAPI endpoints into MCP tools:

python
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

mcp = FastApiMCP(
app,
name="sentiment-analysis",
description="Sentiment analysis service",
base_url="http://localhost:5000",
include_operations=["predict_sentiment"]
)

MCP tool names default to the API endpoint's operation_id. We recommend following these naming conventions:

- Use clear, descriptive names
- Adopt a verb_noun format (e.g., predict_sentiment, find_nearby_parking)
- Explicitly set operation_id rather than relying on auto-generation

```python

中文文档

Overview

A professional framework designed for enterprise-level Model Context Protocol (MCP) tool development, standardizing the MCP server development process to help developers rapidly build high-quality AI tools. By integrating FastAPI with FastAPI-MCP, this framework enables seamless transformation from traditional APIs to AI-callable tools.

Key Features

- MCP Tool Standardization: Automatically convert traditional FastAPI endpoints into AI model-callable MCP tools
- Interface-Implementation Separation: Support clear separation between interface definitions and implementations, facilitating testing and environment switching
- Dependency Injection Design: Leverage FastAPI's dependency injection mechanism for flexible component composition and decoupling
- Complete Development Pipeline: Provide comprehensive toolchain support from development to testing and deployment
- Example-Driven Documentation: Demonstrate best practices through practical examples to accelerate onboarding

This framework is particularly suitable for:
- AI tool development teams
- Developers looking to transform existing APIs into AI tools
- Organizations implementing standardized microservice architectures

Architecture

Core Architecture

┌─────────────┐      ┌───────────────┐      ┌─────────────────┐
│   API Layer │ ──→  │ Service Layer │ ──→  │ Implementation  │
└─────────────┘      └───────────────┘      └─────────────────┘
       ↓
┌─────────────┐
│ MCP Endpoint│ ←── FastAPI-MCP Auto-Conversion
└─────────────┘

Key Components

- FastAPI Application: Provides the HTTP API service foundation
- FastAPI-MCP: Converts API endpoints to MCP tools
- Service Interface Layer: Defines service contracts through abstract base classes
- Dependency Injection Providers: Manages service instance creation and injection
- Implementation Classes: Includes Mock and Real implementations with environment-based switching

Technology Stack

- Python 3.10+: Utilizing latest language features and type annotations
- FastAPI: High-performance asynchronous web framework
- FastAPI-MCP: Automatically exposes FastAPI endpoints as MCP tools
- Development Toolchain: Includes code quality checking and testing tools

Quick Start

Environment Setup

This framework uses uv as its package manager, providing faster dependency resolution and virtual environment management. For installation instructions, see the uv official documentation.

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.