Skip to main content
Glama
Suryakanta26

mcp-server-python-mt9e4j8z

by Suryakanta26

MCP Server Template (Python)

一个用于 Render 的极简 Model Context Protocol 服务器模板。Fork 它,添加你自己的工具,然后部署。

包含内容

  • 一个使用 MCP Python SDK 且支持 Streamable HTTP 传输的可用 MCP 服务器

  • 通过 MCP_API_TOKEN 进行 Bearer token 认证(部署时自动生成)

  • 一个示例工具(hello)用于展示模式

  • 一个用于 Render 健康检查的 /health 端点

  • 一个用于一键部署的 render.yaml Blueprint

  • 一个 AGENTS.md 文件,让 AI 编码助手可以为你搭建新工具

注意: 此模板默认在免费计划上部署。免费服务在闲置 15 分钟后会关闭,导致下一次请求时出现 30-60 秒的冷启动。MCP 客户端可能会在此延迟期间超时。为了可靠使用,请在 Render Dashboard 中升级到付费方案——Starter 计划可让你的服务持续运行。

Related MCP server: mcp-server-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 token 对请求进行认证。Render 的 Blueprint 在首次部署时会自动生成一个随机的 MCP_API_TOKEN

部署后查找你的 token:前往 Render Dashboard > 你的服务 > Environment,复制 MCP_API_TOKEN 的值。

客户端必须在 Authorization 头中包含该 token:

Authorization: Bearer YOUR_TOKEN

当未设置 MCP_API_TOKEN 时(例如在本地开发期间),认证被禁用,所有请求都会被放行。

管理你的 token

首次部署后,token 由你自行管理:

  • 轮换它:在 Render Dashboard 的 Environment 下更新 MCP_API_TOKEN。服务会自动使用新值重启。

  • 生成新 token,可使用以下任一方式:

    • openssl rand -base64 32

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

    • 密码管理器的生成器(1Password、Bitwarden 等)

  • 不要将 token 提交到源代码控制中。请使用环境变量或 .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
Not graded
quality - not tested
C
maintenance

Maintenance

UpdatingMaintainers
UpdatingResponse time
Release cycle
0Releases (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
    Not graded
    quality
    C
    maintenance
    A minimal template for deploying Model Context Protocol servers on Render with Streamable HTTP transport, bearer token authentication, and an example hello tool.
  • F
    license
    Not graded
    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
    Not graded
    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
    Not graded
    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

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/Suryakanta26/mcp-server-python-mt9e4j8z'

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