Logo di MCP Forge

MCP Forge

Community
mlzoo

这是一个专为开发企业级MCP server而设计的通用开发框架

Autoremlzoo
Repositorymcp_forge
LinguaPython
Fork
36
Stelle
208
Strumenti disponibili
0
Tipo di trasportostdio
LicenzaMIT
Link
  • Collega gli strumenti ai flussi di lavoro IA

    MCP Forge mette a disposizione funzionalità MCP utilizzabili da client e agenti IA compatibili.

  • 0 strumenti disponibili

    Esplora le azioni richiamabili qui sotto, con nomi e descrizioni quando forniti dal server.

  • Configurazione pronta da copiare

    Usa gli esempi di installazione per configurare questo server nel tuo client MCP preferito.

  • Indicatori di interesse open source

    208 stelle e 36 fork nel repository collegato.

MCP Server Development Framework

中文文档

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
# Install dependencies and set up the development environment
make install

Launch Example Service

bash
# Start the development server
make dev

Once the service is running, you can:

  • Access the API documentation at http://localhost:5000/docs
  • Connect to the MCP endpoint at http://localhost:5000/mcp using an MCP client (e.g., Cursor, Claude Desktop)

Project Structure

.
├── main.py                    # Application entry point and route definitions
├── services/                  # Service layer implementations
│   └── parking_service.py     # Example service (replaceable with custom services)
├── pyproject.toml             # Project configuration and dependency definitions
└── Makefile                   # Development and build tasks

MCP Tool Development Guide

Development Process Overview

  1. Define Service Interfaces: Create abstract base classes to define service contracts
  2. Implement Services: Develop Mock or Real implementations based on requirements
  3. Create API Endpoints: Develop API interfaces using FastAPI
  4. Enable MCP Service: Expose endpoints as AI tools through FastAPI-MCP

Service Interfaces and Implementations

python
# 1. Service Interface Definition
from abc import ABC, abstractmethod
from typing import Dict, Any

class DataService(ABC):
    @abstractmethod
    def get_data(self, id: str) -> Dict[str, Any]:
        """Data retrieval interface"""
        pass

# 2A. Mock Implementation - for development and testing
class DataServiceMockImpl(DataService):
    def get_data(self, id: str) -> Dict[str, Any]:
        return {"id": id, "name": "Test Data", "mock": True}

# 2B. Real Implementation - for production environment
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})

# 3. Dependency Injection Configuration
def get_data_service() -> DataService:
    # Choose implementation based on environment
    return DataServiceMockImpl() # or return DataServiceImpl(settings.DATABASE_URL)

API and MCP Tool Definition

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

app = FastAPI()

# Request model
class ItemRequest(BaseModel):
    query: str = Field(..., description="Search query parameter")
    limit: int = Field(10, description="Result limit")

# API endpoint - automatically converted to an MCP tool
@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"])}

# Create and mount MCP service
mcp = FastApiMCP(
    app,
    name="example-service",
    description="Example MCP service",
    base_url="http://localhost:5000",
    include_operations=["search_items"]
)

# Mount MCP service at specified path
mcp.mount(mount_path="/mcp")

Dependency Injection Explained

FastAPI's dependency injection system is an integral part of this framework, providing powerful and flexible dependency management capabilities.

Dependency Injection Fundamentals

Dependency injection is a design pattern that allows dependencies (such as services, database connections, etc.) to be injected into components that use them, rather than having components create and manage dependencies themselves. In FastAPI, dependency injection is implemented through the Depends function.

python
from fastapi import Depends

def get_db():
    """Database connection provider"""
    db = connect_to_db()
    try:
        yield db  # Using yield enables lifecycle management of dependencies
    finally:
        db.close()

@app.get("/items/")
async def get_items(db = Depends(get_db)):
    return db.query(Item).all()

Dependency Types

FastAPI supports several types of dependency injection:

  1. Function Dependencies: As shown above, using functions as dependency providers
  2. Class Dependencies: Using classes as dependencies for more complex dependency management
python
class DatabaseDependency:
    def __init__(self, settings = Depends(get_settings)):
        self.settings = settings

    def __call__(self):
        db = connect_to_db(self.settings.db_url)
        try:
            yield db
        finally:
            db.close()

@app.get("/users/")
async def get_users(db = Depends(DatabaseDependency())):
    return db.query(User).all()
  1. Nested Dependencies: Dependencies can depend on other dependencies, forming a dependency tree

Application in MCP Tool Development

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 Features

Automatic MCP Tool Generation

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

python
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

# Define a standard FastAPI endpoint
@app.post("/predict", operation_id="predict_sentiment")
async def predict_sentiment(text: str):
    return {"sentiment": "positive", "confidence": 0.92}

# Create and mount MCP service - automatically converts the above endpoint to an MCP tool
mcp = FastApiMCP(
    app,
    name="sentiment-analysis",
    description="Sentiment analysis service",
    base_url="http://localhost:5000",
    include_operations=["predict_sentiment"]
)

# Mount MCP service at specified path
mcp.mount(mount_path="/mcp")

Tool Naming Best Practices

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
# Recommended: Explicitly set operation_id
@app.post("/parking/nearby", operation_id="find_nearby_parking")
async def find_nearby(request: NearbyRequest):
    # Implementation logic...
    pass

# Not recommended: Relying on auto-generated operation_id (generates something like "find_nearby_parking_nearby_post")
@app.post("/parking/nearby")
async def find_nearby(request: NearbyRequest):
    # Implementation logic...
    pass

Testing and Quality Assurance

This framework supports multi-level testing strategies:

bash
# Run code quality checks
make check

# Run test suite
make test

Testing Strategies

  • Unit Testing: Test individual components using Mock service implementations
  • Integration Testing: Test interactions between components
  • API Testing: Verify HTTP interface behavior
  • MCP Tool Testing: Validate AI tool functionality

Performance Optimization

To ensure high performance of MCP tools, we recommend:

  • Asynchronous Processing: Leverage FastAPI's async features for concurrent request handling
  • Caching Strategies: Implement caching for frequently requested data
  • Batch Processing: Design APIs that support batch operations to reduce call frequency

Contribution Guidelines

Contributions to this framework are welcome:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Create a Pull Request

License

MIT License

References

Usa MCP MCP Forge con più modelli IA

TypingMind collega gli strumenti MCP a livello di area di lavoro: una volta connesso MCP Forge, puoi usarlo con diversi modelli IA in TypingMind, senza configurarlo separatamente per ogni modello. Questa integrazione MCP viene eseguita localmente sul tuo dispositivo tramite il connettore MCP di TypingMind.

Guida alla configurazione del connettore locale

Usa questo metodo quando il server MCP deve accedere a file locali, app o risorse private sul tuo computer.

1

Apri le impostazioni MCP

In TypingMind, vai su Impostazioni, Impostazioni avanzate, poi su Model Context Protocol e scegli Configura MCP.

  1. Apri TypingMind nel tuo browser.
  2. Fai clic sull'icona Impostazioni.
  3. Vai a Impostazioni avanzate.
  4. Apri la sezione Model Context Protocol.
  5. Fai clic su Configura MCP e scegli Questo dispositivo.
Schermata di configurazione del connettore MCP di TypingMind con Questo dispositivo selezionato
2

Esegui il comando del connettore

Scegli Questo dispositivo, copia il comando da TypingMind ed eseguilo nel terminale. Lascia il processo in esecuzione mentre usi MCP.

  1. Copia il comando di configurazione mostrato da TypingMind.
  2. Apri Terminale su macOS o Windows Terminal su Windows.
  3. Incolla ed esegui il comando.
  4. Conferma l'installazione del pacchetto se il terminale ti chiede di procedere.
  5. Tieni aperta la finestra del terminale con il processo in esecuzione mentre usi gli strumenti MCP.
3

Aggiungi MCP Forge come server

Quando lo stato del connettore è Pronto, fai clic su Modifica server e incolla la configurazione del server MCP.

  1. Attendi che lo stato del connettore sia Pronto.
  2. Fai clic su Modifica server.
  3. Incolla la configurazione del server MCP di MCP Forge.
  4. Salva l'elenco dei server.
  5. Aggiorna per verificare che il connettore sia ancora pronto.
Impostazioni MCP di TypingMind con un server attivo e il pulsante Modifica server
{
  "mcpServers": {
    "mcp-forge": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Usa la connessione con diversi modelli

Salva l'elenco dei server, apri Plugin, abilita gli strumenti MCP di MCP Forge, poi seleziona un modello IA supportato in TypingMind e usa gli strumenti in chat o assegnali a un agente IA.

  1. Apri la pagina Plugin in TypingMind.
  2. Abilita gli strumenti MCP di MCP Forge.
  3. Avvia una chat e scegli il modello IA che vuoi usare.
  4. Usa gli strumenti MCP in chat o assegnali a un agente IA.
  5. Passa a un altro modello IA quando serve, senza riconnettere MCP.
Chat di TypingMind che usa gli strumenti MCP abilitati con un modello IA selezionato
Puoi usare MCP Forge per aiutarmi con questa attività?
MCP Forge
Certo. Ho letto.
Ecco cosa ho trovato con MCP Forge.

Domande frequenti

A cosa serve il server MCP MCP Forge?

MCP Forge è un server MCP che consente ai client IA compatibili di accedere a strumenti e informazioni di contesto esterni. In TypingMind puoi aggiungere questo server MCP una sola volta e rendere disponibili i suoi strumenti nella tua area di lavoro IA.

Posso usare MCP Forge MCP con più modelli IA in TypingMind?

Sì. TypingMind collega gli strumenti MCP a livello di area di lavoro, quindi puoi usare MCP Forge con diversi modelli IA come Claude, ChatGPT, Gemini o altri modelli che hai configurato in TypingMind, senza dover configurare il server MCP separatamente per ogni modello.

Perché usare il connettore MCP MCP Forge con TypingMind?

TypingMind è una delle migliori interfacce per chattare con gli LLM perché riunisce più modelli IA, prompt, plugin, agenti IA, chiavi API e strumenti MCP in un'unica area di lavoro. Collegando MCP Forge, puoi usare i suoi strumenti MCP con i tuoi modelli preferiti e mantenere organizzato il tuo flusso di lavoro in chat su TypingMind.

Come collego MCP Forge MCP a TypingMind?

MCP Forge funziona tramite il connettore MCP locale di TypingMind. È la soluzione ideale quando il server MCP deve accedere a file locali, app desktop, strumenti da riga di comando o risorse private sul tuo computer.

Quali strumenti offre MCP Forge MCP in TypingMind?

MCP Forge mette a disposizione funzionalità MCP che puoi attivare dalla pagina Plugin di TypingMind e usare in chat o assegnare agli agenti IA.

Devo condividere le mie chiavi API con TypingMind per usare MCP Forge MCP?

No. TypingMind privilegia il funzionamento in locale e ti permette di mantenere il controllo su fornitori di modelli, chiavi API, prompt e configurazione MCP. Se MCP Forge richiede l'autenticazione, aggiungi le intestazioni, le impostazioni OAuth o la configurazione locale necessarie per quel server MCP quando crei la connessione.

Server MCP correlati

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇