Skip to main content
Glama
w0odst0ck

mcp-server-template

by w0odst0ck

MCP Server テンプレート

汎用 MCP Server スキャフォールディング — FastAPI + FastMCP 統合テンプレート

これは何か

MCP (Model Context Protocol) サービスを迅速に構築するためのクリーンなスタートポイントです。

MCP は、AI モデルが外部ツールを呼び出すためのプロトコル標準です。このテンプレートを使用すると、最小限の設定で任意の機能を AI が呼び出し可能なツールとして公開できます。

你的业务代码 → MCP Server → AI 智能体(Cursor / Claude / 自定义应用)

Related MCP server: Simple Remote MCP Server

アーキテクチャ

FastAPI(主容器)
├── CORS 中间件
├── 生命周期管理
├── FastAPI 路由(传统 HTTP)
└── FastMCP 子应用(MCP 协议)
    └── @mcp.tool() 工具

中核的な特徴:

  • 1 つのデコレータ = MCP プロトコル + HTTP インターフェースを同時にサポート

  • 複数モジュールの独立したマウント、各モジュールは互いに干渉しない

  • すぐに使えるログ、設定、Docker デプロイ

クイックスタート

前提条件

  • Python >= 3.12

  • uv

インストール

# 克隆模板
git clone <your-repo-url> my-mcp-server
cd my-mcp-server

# 安装依赖
uv sync

# 配置环境变量
cp .env-sample .env

起動

# 方式一:uvicorn(推荐)
uv run uvicorn app.main:app --reload

# 方式二:python
uv run python -m app.main

# 方式三:fastapi CLI
uv run fastapi dev app/main.py

検証

# HTTP 端点
curl http://127.0.0.1:8000/example/hello
# => "Hello, World! Running mcp-server-template v0.1.0"

# MCP 协议端点(返回 MCP 端点信息,非 404 即挂载成功)
curl http://127.0.0.1:8000/example

プロジェクト構造

mcp-server-template/
│
├── app/                    # 应用主目录
│   ├── routers/            # MCP 工具 + FastAPI 路由
│   │   ├── example.py      #   示例模块(供复制参考)
│   │   └── __init__.py
│   ├── utils/              # 工具函数
│   │   └── log.py          #   日志(loguru)
│   ├── __init__.py
│   ├── config.py           # 配置管理(pydantic-settings)
│   ├── dependencies.py     # 依赖注入
│   └── main.py             # 应用入口
│
├── docs/                   # 文档
├── migrations/             # Alembic 数据库迁移(可选)
├── scripts/                # 开发脚本
├── tests/                  # 测试
│
├── .env-sample             # 环境变量模板
├── .gitignore
├── .python-version
├── alembic.ini
├── docker-compose.yaml
├── Dockerfile
├── pyproject.toml
└── README.md

新しいビジネスモジュールの追加

テンプレートには、参考として example.py が組み込まれています。新しいモジュールを作成するには:

  1. app/routers/example.py をコピーして app/routers/your_module.py とする

  2. モジュールの内容を修正 — 名前変更、ルートプレフィックス変更、ツール関数の作成

  3. app/main.py に登録

# app/main.py
from app.routers import your_module
from fastmcp.utilities.lifespan import combine_lifespans

your_module_app = your_module.mcp.http_app(path="/", stateless_http=True)
app.include_router(your_module.router)
app.mount("/your_module", app=your_module_app)

# 同时把 your_module_app.lifespan 合并进 FastAPI 的 lifespan:
# app = FastAPI(lifespan=combine_lifespans(lifespan, your_module_app.lifespan))

ツール関数は、AI(MCP経由)とブラウザ(HTTP経由)の両方から同時に呼び出すことができます:

@mcp.tool()
@router.get("/search")
async def search(query: str) -> list:
    """搜索知识库(此描述会暴露给 AI)"""
    # 你的业务逻辑
    return results

テスト

uv run pytest tests/ -v

Docker デプロイ

# 构建
docker build -t mcp-server:latest .

# 启动
docker compose up -d

設定

すべての設定は環境変数または .env ファイルで管理します。詳細は .env-sample を参照してください。

主要な設定項目:

変数

説明

デフォルト

ENVIRONMENT

実行環境

dev

HOST

リッスンアドレス

127.0.0.1

PORT

リッスンポート

8000

DATABASE_URL

データベース接続(任意)

None

LOG_LEVEL

ログレベル

INFO

参考

F
license - not found
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    B
    quality
    D
    maintenance
    A template and demonstration project for building, testing, and deploying remote MCP servers using FastMCP and uv. It provides a foundational structure for creating MCP-compliant tools that can be hosted publicly and integrated with LLM agents.
    2
  • A
    license
    Not graded
    quality
    D
    maintenance
    A bare-bones FastMCP server template designed to serve as a starting point for building custom Model Context Protocol servers. It provides a foundational structure for implementing tools over HTTP and includes a built-in health check utility.
    GPL 3.0

View all related MCP servers

Related MCP Connectors

  • Primarily to be used as a template repository for developing MCP servers with FastMCP in Python, P…

  • MCP server for AI dialogue using various LLM models via AceDataCloud

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/w0odst0ck/MCPForge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server