Cover image
Try Now
2025-02-22

Modèle MCP génial pour les constructeurs de Fastapi impressionnants

3 years

Works with Finder

1

Github Watches

6

Github Forks

26

Github Stars

Website

Awesome MCP FastAPI

A powerful FastAPI-based implementation of the Model Context Protocol (MCP) with enhanced tool registry capabilities, leveraging the mature FastAPI ecosystem.

Overview

Awesome MCP FastAPI is a production-ready implementation of the Model Context Protocol that enhances and extends the standard MCP functionality by integrating it with FastAPI's robust ecosystem. This project provides an improved tool registry system that makes it easier to create, manage, and document AI tools for Large Language Models (LLMs).

Why This Is Better Than Standard MCP

While the Model Context Protocol provides a solid foundation for connecting AI models with tools and data sources, our implementation offers several significant advantages:

FastAPI's Mature Ecosystem

  • Production-Ready Web Framework: Built on FastAPI, a high-performance, modern web framework with automatic OpenAPI documentation generation.
  • Dependency Injection: Leverage FastAPI's powerful dependency injection system for more maintainable and testable code.
  • Middleware Support: Easy integration with authentication, monitoring, and other middleware components.
  • Built-in Validation: Pydantic integration for robust request/response validation and data modeling.
  • Async Support: First-class support for async/await patterns for high-concurrency applications.

Enhanced Tool Registry

Our implementation improves upon the standard MCP tool registry by:

  • Automatic Documentation Generation: Tools are automatically documented in both MCP format and OpenAPI specification.
  • Improved Type Hints: Enhanced type information extraction for better tooling and IDE support.
  • Richer Schema Definitions: More expressive JSON Schema definitions for tool inputs and outputs.
  • Better Error Handling: Structured error responses with detailed information.
  • Enhanced Docstring Support: Better extraction of documentation from Python docstrings.

Additional Features

  • CORS Support: Ready for cross-origin requests, making it easy to integrate with web applications.
  • Lifespan Management: Proper resource initialization and cleanup through FastAPI's lifespan API.

Getting Started

Prerequisites

  • Python 3.10+

Installation

# Clone the repository
git clone https://github.com/yourusername/awesome-mcp-fastapi.git
cd awesome-mcp-fastapi

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e .

Running the Server

uvicorn src.main:app --reload

Visit http://localhost:8000/docs to see the OpenAPI documentation.

Usage

Creating a Tool

from fastapi import FastAPI
from src.utils.tools import auto_tool, bind_app_tools

app = FastAPI()
bind_app_tools(app)

@auto_tool(
    name="calculator",
    description="Perform basic arithmetic operations",
    tags=["math"]
)
@app.post("/api/calculator")
async def calculator(operation: str, a: float, b: float):
    """
    Perform basic arithmetic operations.
    
    Parameters:
    - operation: The operation to perform (add, subtract, multiply, divide)
    - a: First number
    - b: Second number
    
    Returns:
    The result of the operation
    """
    if operation == "add":
        return {"result": a + b}
    elif operation == "subtract":
        return {"result": a - b}
    elif operation == "multiply":
        return {"result": a * b}
    elif operation == "divide":
        if b == 0:
            return {"error": "Cannot divide by zero"}
        return {"result": a / b}
    else:
        return {"error": f"Unknown operation: {operation}"}

Accessing Tools Through MCP

LLMs can discover and use your tools through the Model Context Protocol. Example using Claude:

You can perform calculations using the calculator tool. Try calculating 42 * 13.

Claude will automatically find and use your calculator tool to perform the calculation.

Architecture

Our application follows a modular architecture:

src/
├── api/              # API endpoints
│   └── v1/           # API version 1
├── core/             # Core functionality
│   └── settings.py   # Application settings
├── db/               # Database connections
│   └── models/       # Database models
├── main.py           # Application entry point
└── utils/            # Utility functions
    └── tools.py      # Enhanced tool registry

Docker Support

Build and run with Docker:

docker build -t awesome-mcp-fastapi .
docker run -p 8000:8000 --env-file .env awesome-mcp-fastapi

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • jae-jae
  • MCP Server pour récupérer le contenu de la page Web à l'aide du navigateur sans tête du dramwright.

  • ravitemer
  • Un puissant plugin Neovim pour gérer les serveurs MCP (Protocole de contexte modèle)

  • patruff
  • Pont entre les serveurs Olllama et MCP, permettant aux LLM locaux d'utiliser des outils de protocole de contexte de modèle

  • pontusab
  • La communauté du curseur et de la planche à voile, recherchez des règles et des MCP

  • av
  • Exécutez sans effort LLM Backends, API, Frontends et Services avec une seule commande.

  • Mintplex-Labs
  • L'application tout-en-un desktop et Docker AI avec chiffon intégré, agents AI, constructeur d'agent sans code, compatibilité MCP, etc.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.

  • appcypher
  • Serveurs MCP géniaux - une liste organisée de serveurs de protocole de contexte de modèle

    Reviews

    5 (1)
    Avatar
    user_0tXgok4r
    2025-04-17

    I recently started using awesome-mcp-fastapi by MR-GREEN1337 and it has exceeded my expectations! The integration with FastAPI is seamless and it has greatly improved my development workflow. The well-documented repository on GitHub makes it easy to get started. Highly recommend it to anyone working with FastAPI!