FastAPIとModel Context Protocol (MCP)を使用してAPIをホスティングするためのテンプレートリポジトリです。
このプロジェクトは以下の技術を使用しています:
- FastAPI: 高性能なPythonウェブフレームワーク
- FastMCP: FastAPIとModel Context Protocol (MCP)を統合するライブラリ
- OpenAPI 3.0.3: APIドキュメントの自動生成
- FastAPIを使用したAPIホスティング
- FastMCPを使用したMCPサーバーホスティング
- OpenAPI 3.0.3に準拠したAPIドキュメントの自動生成
- サンプルAPIエンドポイントの実装
- サンプルMCPツールの実装
- Python 3.10以上
- Poetry(依存関係管理)
- Docker(オプション、コンテナ化に使用)
- リポジトリをクローン
git clone https://github.com/yourusername/fastapi-mcp-template.git
cd fastapi-mcp-template- Poetryを使用して依存関係をインストール
poetry install- 開発サーバーを起動
poetry run python -m app.mainまたは
poetry run uvicorn app.main:app --reload- ブラウザで以下のURLにアクセス
- API: http://localhost:8000/
- APIドキュメント: http://localhost:8000/docs
- MCPサーバー: http://localhost:8000/mcp
このプロジェクトでは以下のテスト環境を提供しています:
- pytestによる単体テスト
- pytest-covによるカバレッジ計測
- flake8による静的解析
- pytestによる結合テスト
- schemathesisによるE2Eテスト
- MCP InspectorによるMCPサーバーのテスト
- actによるGitHub Actionsのローカル実行
# すべてのテストを実行
poetry run pytest
# 単体テストのみ実行
poetry run pytest tests/unit
# 結合テストのみ実行
poetry run pytest tests/integration
# E2Eテストのみ実行
poetry run pytest tests/e2e
# カバレッジレポートを生成
poetry run pytest --cov=app --cov-report=html# Dockerイメージをビルド
docker build -t fastapi-mcp-template -f docker/Dockerfile .
# Dockerコンテナを実行
docker run -p 8000:8000 fastapi-mcp-template# CDKディレクトリに移動
cd cdk
# 依存関係をインストール
npm install
# CDKをデプロイ
npm run cdk deployfastapi-mcp-template/
├── app/ # アプリケーションコード
│ ├── __init__.py
│ ├── main.py # アプリケーションのエントリーポイント
│ ├── core/ # コア機能
│ │ └── config.py # 設定
│ ├── presentation/ # プレゼンテーション層
│ │ ├── api/ # APIエンドポイント
│ │ │ └── example_router.py
│ │ └── mcp/ # MCPツール
│ │ └── example_tools.py
├── cdk/ # AWS CDKコード
├── docker/ # Dockerファイル
├── docs/ # ドキュメント
├── scripts/ # スクリプト
├── tests/ # テスト
│ ├── unit/ # 単体テスト
│ ├── integration/ # 結合テスト
│ └── e2e/ # E2Eテスト
├── pyproject.toml # Poetryの設定
└── README.md # このファイル
MITライセンス