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 进行部署。

Features

  • 类型化工具,带结构化 Pydantic 输出

  • 通用计算器和确定性目录示例

  • MCP 工具、资源和提示词

  • Bearer-token 边界与工具级作用域

  • 请求大小、主机和进程内速率限制

  • 关联 ID 和结构化请求日志

  • 公开的健康与就绪探针

  • 单元测试和 HTTP 集成测试

  • 生产风格的非 root Docker 镜像

  • 用于 lint、格式化、类型检查、测试、镜像构建、密钥和工作流的 CI

Related MCP server: MCP TypeScript SDK

Architecture

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-readercatalog:read

  • demo-operatorcatalog:read, calculator:use

使用 npx -y @modelcontextprotocol/inspector 运行 MCP 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

在生产环境拒绝不安全的 demo 认证

MCP_HOST / MCP_PORT

127.0.0.1 / 8000

绑定地址

MCP_AUTH_MODE

demo

demobearer 或仅限本地的 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=productionMCP_AUTH_MODE=bearer、由密钥管理的 MCP_BEARER_TOKENS 值,以及精确的公共主机白名单。在受信任的反向代理处终止 TLS。当需要用户委托或令牌生命周期管理时,请将入门套件中的令牌存储替换为你自己的 OAuth 2.1 资源服务器验证器。

许可证

MIT

A
license - permissive license
Not graded
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

View all related MCP servers

Related MCP Connectors

  • A Model Context Protocol server for Wix AI tools

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…

  • MCP server for secureFlows: token-free URL builders and integration-linting 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/Boyeep/python-mcp-server-kit'

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