Skip to main content
Glama

Webサイト

素晴らしいMCP FastAPI

成熟した FastAPI エコシステムを活用し、強化されたツール レジストリ機能を備えた強力な FastAPI ベースのモデル コンテキスト プロトコル (MCP) 実装。

概要

Awesome MCP FastAPIは、モデルコンテキストプロトコル(MCP)の実稼働対応実装であり、FastAPIの堅牢なエコシステムと統合することで、標準MCP機能を強化・拡張します。このプロジェクトは、大規模言語モデル(LLM)向けのAIツールの作成、管理、ドキュメント化を容易にする、改良されたツールレジストリシステムを提供します。

Related MCP server: production-grade-mcp-agentic-system

これが標準のMCPよりも優れている理由

モデル コンテキスト プロトコルは AI モデルをツールやデータ ソースに接続するための強固な基盤を提供しますが、私たちの実装にはいくつかの大きな利点があります。

FastAPIの成熟したエコシステム

  • 本番環境対応の Web フレームワーク: OpenAPI ドキュメントの自動生成機能を備えた高性能の最新 Web フレームワークである FastAPI 上に構築されています。

  • 依存性注入: FastAPI の強力な依存性注入システムを活用して、より保守しやすくテストしやすいコードを作成します。

  • ミドルウェア サポート: 認証、監視、その他のミドルウェア コンポーネントとの簡単な統合。

  • 組み込み検証: 堅牢なリクエスト/レスポンス検証とデータ モデリングのための Pydantic 統合。

  • 非同期サポート: 高同時実行アプリケーション向けの async/await パターンに対するファーストクラスのサポート。

強化されたツールレジストリ

私たちの実装は、次の点で標準の MCP ツール レジストリを改善します。

  • 自動ドキュメント生成: ツールは、MCP 形式と OpenAPI 仕様の両方で自動的にドキュメント化されます。

  • 型ヒントの改善: 型情報の抽出が強化され、ツールと IDE サポートが向上しました。

  • より豊富なスキーマ定義: ツールの入力と出力のためのより表現力豊かな JSON スキーマ定義。

  • 改善されたエラー処理: 詳細な情報を含む構造化されたエラー応答。

  • 強化された Docstring サポート: Python の docstring からのドキュメントの抽出が改善されました。

追加機能

  • CORS サポート: クロスオリジン リクエストに対応しており、Web アプリケーションとの統合が容易になります。

  • ライフスパン管理: FastAPI のライフスパン API による適切なリソースの初期化とクリーンアップ。

はじめる

前提条件

  • Python 3.10以上

インストール

# 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 .

サーバーの実行

uvicorn src.main:app --reload

OpenAPI ドキュメントを参照するには、 http://localhost:8000/docsにアクセスしてください。

使用法

ツールの作成

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}"}

MCP 経由でツールにアクセスする

LLMはモデルコンテキストプロトコルを通じてツールを検出し、使用できます。Claudeを使用した例:

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

Claude は自動的に計算ツールを見つけて使用し、計算を実行します。

建築

私たちのアプリケーションはモジュール型アーキテクチャに従っています。

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 サポート

Docker でビルドして実行します。

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

貢献

貢献を歓迎します!お気軽にプルリクエストを送信してください。

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細については LICENSE ファイルを参照してください。

Maintenance

ActivityInactive
ResponsivenessUnresponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A production-ready MCP server that integrates OpenAI with FastAPI and Redis to provide streaming agentic chat capabilities and session memory. It features built-in tools for weather, calculations, and Wikipedia searches while supporting enterprise-grade features like rate limiting and structured logging.
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A plugin-based MCP server built on FastAPI that supports dynamic tool loading, hot reloading, and API key authentication for extensible AI tool integrations.
    -
  • F
    license
    A
    quality
    D
    maintenance
    A production-grade MCP server that provides a centralized microservice toolkit for LLM agents, enabling web search and extensible tool integration.
    1
    -