Skip to main content
Glama
truongvanhaoem-0111

MCP Server Template (Python)

MCP Server Template (Python)

最小限の Model Context Protocol サーバーテンプレート(Render 用)です。フォークして、独自のツールを追加し、デプロイしてください。

含まれるもの

  • MCP Python SDK を使用した、Streamable HTTP トランスポート対応の MCP サーバー

  • MCP_API_TOKEN による Bearer トークン認証(デプロイ時に自動生成)

  • パターンを示す 1 つのサンプルツール(hello

  • Render のヘルスチェック用の /health エンドポイント

  • ワンクリックデプロイ用の render.yaml Blueprint

  • AI コーディングアシスタントが新しいツールの雛形を作成できるようにする AGENTS.md

注: このテンプレートはデフォルトで無料プランでデプロイされます。無料サービスは 15 分間アイドル状態が続くとスピンダウンし、次のリクエスト時に 30 〜 60 秒のコールドスタートが発生します。この遅延の間に MCP クライアントがタイムアウトする可能性があります。確実に使用するには、Render ダッシュボードで 有料プラン にアップグレードしてください。Starter プランではサービスが継続的に稼働します。

Related MCP server: MCP Server Template (Python)

ローカルで始める

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

認証

サーバーは Bearer トークンを使用してリクエストを認証します。Render の Blueprint は初回デプロイ時にランダムな MCP_API_TOKEN を自動生成します。

デプロイ後にトークンを見つけるには、Render ダッシュボード > お使いのサービス > Environment に移動し、MCP_API_TOKEN の値をコピーしてください。

クライアントは Authorization ヘッダーにトークンを含める必要があります:

Authorization: Bearer YOUR_TOKEN

MCP_API_TOKEN が設定されていない場合(例: ローカル開発時)、認証は無効になり、すべてのリクエストが許可されます。

トークンの管理

最初のデプロイ後、トークンはお客様が管理できます:

  • ローテーションするには、Render ダッシュボードの EnvironmentMCP_API_TOKEN を更新します。サービスは新しい値で自動的に再起動します。

  • 新しいトークンを生成するには、次のいずれかを使用します:

    • openssl rand -base64 32

    • python3 -c "import secrets; print(secrets.token_urlsafe(32))"

    • パスワードマネージャーの生成機能(1Password、Bitwarden など)

  • トークンをソース管理にコミットしないでください。環境変数または .env ファイル(.gitignore に含まれています)を使用してください。

  • 複数ユーザーまたは本番環境のセットアップでは、OAuth 2.1 へのアップグレードを検討してください。

MCP サーバーへの接続

Render にデプロイした後、MCP エンドポイントは次の場所で利用できます:

https://your-service-name.onrender.com/mcp

Cursor

プロジェクトの .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

詳細情報

F
license - not found
-
quality - not tested
C
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
    -
    quality
    C
    maintenance
    A minimal MCP server template for Python with Streamable HTTP transport, bearer token authentication, and a hello tool, designed for deployment on Render.
  • F
    license
    -
    quality
    C
    maintenance
    A minimal MCP server template for Render with Streamable HTTP transport, bearer token authentication, and an example 'hello' tool. Enables developers to quickly scaffold and deploy their own MCP servers.
  • F
    license
    -
    quality
    C
    maintenance
    A minimal MCP server template for Render with Streamable HTTP transport, bearer token authentication, and an example 'hello' tool.
  • F
    license
    -
    quality
    C
    maintenance
    A minimal MCP server template for Render with Streamable HTTP transport, bearer token authentication, and an example 'hello' tool.

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…

  • An MCP server for Arcjet - the runtime security platform that ships with your AI code.

  • Remote ChromaDB vector database MCP server with streamable HTTP transport

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/truongvanhaoem-0111/mcp-server-python-msx1l7h1'

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