Skip to main content
Glama
Boyeep

Python MCP Server Kit

by Boyeep

Python MCP Server Kit

バックエンド専用の、セキュアで型付けされ、テスト可能なModel Context Protocolサーバー向けスターターです。公式Python SDK v2を介してMCP 2026-07-28 プロトコルを対象とし、デプロイにはステートレスなStreamable HTTPを使用します。

機能

  • 構造化されたPydantic出力を持つ型付きツール

  • 汎用計算機と決定論的カタログの例

  • MCPツール、リソース、プロンプト

  • ベアラートークンの境界とツール単位のスコープ

  • リクエストサイズ、ホスト、インプロセスのレート制限

  • 相関IDと構造化リクエストログ

  • 公開のヘルスプローブとレディネスプローブ

  • ユニットテストとHTTP統合テスト

  • 本番向け非root Dockerイメージ

  • lint、フォーマット、型チェック、テスト、イメージビルド、シークレット、ワークフロー向けCI

Related MCP server: EasyMCP

アーキテクチャ

HTTP request
  -> SecurityMiddleware (host, size, auth, rate limit, request ID)
  -> MCP Streamable HTTP transport
  -> typed tool/resource/prompt
  -> scope check
  -> deterministic domain function

プロトコル登録は src/mcp_server_kit/server.py にあります。再利用可能なドメインロジックは別モジュールに置かれます。TokenStore は意図的に置き換え可能なデプロイ境界であり、完全な認可サーバーではありません。

クイックスタート

Python 3.11+ が必要です。

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"
Copy-Item .env.example .env
.\scripts\dev.ps1

MCPエンドポイントは http://127.0.0.1:8000/mcp です。ヘルスプローブは /health と /ready で利用できます。ローカル専用のデモトークンは次のとおりです:

  • demo-reader — catalog:read

  • demo-operator — catalog:read, calculator:use

MCP Inspector を npx -y @modelcontextprotocol/inspector で実行し、Authorization: Bearer demo-operator ヘッダーを設定してください。資格情報を必要としないクライアント定義は examples/client.json にあります。ローカルでは MCP_CLIENT_TOKEN を注入してください。

コマンド

.\scripts\dev.ps1    # development server with reload
.\scripts\check.ps1  # lint, format check, mypy, and tests
docker compose up --build

設定

変数

デフォルト

目的

MCP_ENVIRONMENT

development

本番環境で安全でないデモ認証を拒否します

MCP_HOST / MCP_PORT

127.0.0.1 / 8000

バインドアドレス

MCP_AUTH_MODE

demo

demo、bearer、またはローカル専用のdisabled

MCP_BEARER_TOKENS

空

token:scope[,scope];... 形式のシークレット値

MCP_ALLOWED_HOSTS

ローカルホスト

完全一致で受け入れるHTTPホスト名

MCP_MAX_REQUEST_BYTES

1048576

宣言されたリクエストボディの最大サイズ

MCP_RATE_LIMIT_REQUESTS

60

サブジェクト/ウィンドウごとに許可されるリクエスト数

MCP_RATE_LIMIT_WINDOW_SECONDS

60

レート制限ウィンドウ

MCP_LOG_LEVEL

INFO

Uvicornのログレベル

.env をコミットしないでください。インターネットに公開するデプロイの前に セキュリティとデプロイ を参照し、レジストリを拡張するときは ツールの追加 を参照してください。

デプロイに関する注意

MCP_ENVIRONMENT=production、MCP_AUTH_MODE=bearer、シークレット管理されたMCP_BEARER_TOKENS値、および正確な公開ホスト許可リストを設定してください。信頼できるリバースプロキシでTLSを終端してください。ユーザー委任またはトークンのライフサイクル管理が必要な場合は、スターターのトークンストアをご自身のOAuth 2.1リソースサーバーベリファイアに置き換えてください。

ライセンス

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables developers to create and serve Model Context Protocol servers in TypeScript by declaratively defining tools, resources, resource templates, prompts, and roots with minimal boilerplate. It provides an Express-like API or experimental decorators, with optional context access for logging and progress reporting.
    5 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables developers to build Model Context Protocol servers in TypeScript with minimal boilerplate, declaring tools, prompts, resources, resource templates, and roots through either an Express-like API or an experimental decorators API that infers types and input schemas automatically. It also provides a context object for logging, progress reporting, and reading resources within tool handlers.
    5 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables developers to create Model Context Protocol servers in TypeScript with minimal boilerplate through an Express-like API or experimental decorators. It supports defining tools, prompts, resources, resource templates, and roots, with type safety and MCP capabilities like logging and progress reporting.
    5 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables developers to build Model Context Protocol servers in TypeScript with a simple Express-like API or experimental decorators for defining tools, prompts, resources, resource templates, and roots with minimal boilerplate.
    5 npm
    MIT