mcp-server-python-mt9e4j8z
MCP サーバーテンプレート (Python)
Render 向けの最小限の Model Context Protocol サーバーテンプレートです。フォークして、独自のツールを追加し、デプロイしてください。
含まれるもの
Streamable HTTP トランスポート対応の MCP Python SDK を使用した、動作する MCP サーバー
MCP_API_TOKENによるベアラートークン認証(デプロイ時に自動生成)パターンを示すサンプルツール(
hello)が1つRender のヘルスチェック用の
/healthエンドポイントワンクリックデプロイ用の
render.yamlBlueprintAI コーディングアシスタントが新しいツールの雛形を作成できるようにする
AGENTS.md
注: このテンプレートはデフォルトでフリープランにデプロイされます。フリーサービスは15分間非アクティブが続くとスピンダウンし、次のリクエスト時に30〜60秒のコールドスタートが発生します。この遅延中に MCP クライアントがタイムアウトする可能性があります。確実に使用するには、Render Dashboard で 有料プラン にアップグレードしてください — Starter プランなら、サービスを継続的に稼働させ続けられます。
Related MCP server: MCP Server Template (TypeScript)
ローカルで始める
git clone https://github.com/render-examples/mcp-server-python.git
cd mcp-server-python
pip install -r requirements.txt
python server.pyサーバーは http://localhost:10000 で起動します。MCP エンドポイントは /mcp です。
テストの実行
pip install -r requirements.txt
pytest認証
サーバーはベアラートークンを使用してリクエストを認証します。Render の Blueprint は、初回デプロイ時にランダムな MCP_API_TOKEN を自動生成します。
デプロイ後にトークンを確認するには、Render Dashboard > お使いのサービス > Environment に移動し、MCP_API_TOKEN の値をコピーしてください。
クライアントは Authorization ヘッダーにトークンを含める必要があります:
Authorization: Bearer YOUR_TOKENMCP_API_TOKEN が設定されていない場合(例: ローカル開発中など)、認証は無効になり、すべてのリクエストが許可されます。
トークンの管理
初回デプロイ後は、トークンを自分で管理できます:
ローテーションするには、Render Dashboard の Environment で
MCP_API_TOKENを更新します。サービスは新しい値で自動的に再起動します。新しいトークンを生成するには、次のいずれかを使用します:
openssl rand -base64 32python3 -c "import secrets; print(secrets.token_urlsafe(32))"パスワードマネージャーのジェネレーター(1Password、Bitwarden など)
トークンをコミットしないでください。ソース管理にコミットせず、環境変数または
.envファイル(.gitignoreに含まれています)を使用してください。マルチユーザーまたは本番環境のセットアップでは、OAuth 2.1 へのアップグレードを検討してください。
MCP サーバーへの接続
Render へのデプロイ後、MCP エンドポイントは次の場所で利用できます:
https://your-service-name.onrender.com/mcpCursor
プロジェクトの .cursor/mcp.json に追加します:
{
"mcpServers": {
"my-mcp-server": {
"url": "https://your-service-name.onrender.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_TOKEN"
}
}
}
}Claude Desktop
Claude Desktop の設定に追加します:
{
"mcpServers": {
"my-mcp-server": {
"type": "streamable-http",
"url": "https://your-service-name.onrender.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_TOKEN"
}
}
}
}Codex
codex mcp add --transport streamable-http \
--url https://your-service-name.onrender.com/mcp \
--header "Authorization: Bearer YOUR_TOKEN" \
my-mcp-serverまたは .codex/config.toml に追加します:
[mcp_servers.my-mcp-server]
url = "https://your-service-name.onrender.com/mcp"
http_headers = { Authorization = "Bearer YOUR_TOKEN" }ツールの追加
server.py で関数を @mcp.tool() でデコレートして、ツールを追加します:
@mcp.tool()
def fetch_weather(city: str, units: str = "celsius") -> str:
"""Get the current weather for a city."""
# your implementation here
return f"Weather for {city}"docstring がツールの説明になります。MCP クライアントはこの説明を LLM に表示します。必ず明確な説明を書きましょう。
このリポジトリには
AGENTS.mdファイルが含まれています。AI コーディングアシスタント(Cursor、Copilot、Codex、Windsurf など)を使用している場合は、「新しいツールを追加して」と頼むと、AGENTS.mdの規約に従って自動的に新しいツールを追加してくれます。
プロジェクト構造
server.py MCP server with example tool and health check
requirements.txt Python dependencies
render.yaml Render Blueprint for deployment
.env.example Environment variable reference
tests/test_server.py Test suite (auth, health, tool calls)
pyproject.toml pytest configuration
AGENTS.md Instructions for AI coding assistants
CLAUDE.md Pointer to AGENTS.md for Claude Code詳細
This server cannot be deployed
Maintenance
Related MCP Connectors
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
A Model Context Protocol server for Wix AI tools
Enable secure connectivity between Sentry issues and debugging data, and LLM clients, using a Model Context Protocol (MCP) server.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA minimal template for deploying Model Context Protocol servers on Render with Streamable HTTP transport, bearer token authentication, and an example hello tool.-
- FlicenseNot gradedqualityCmaintenanceA minimal Model Context Protocol server template deployable on Render, providing Streamable HTTP transport, bearer token authentication, and a pattern for adding custom tools.-
- FlicenseNot gradedqualityCmaintenanceA minimal Model Context Protocol server template for Render with bearer token authentication, an example tool, and a health check endpoint. Enables deploying custom MCP tools quickly on Render.-
- FlicenseNot gradedqualityCmaintenanceThis template enables developers to quickly scaffold, deploy, and extend a Model Context Protocol server on Render, with bearer-token authentication and a streamable HTTP endpoint, by adding custom tools via Python.-