hayate-mcp
Mounts MCP servers into Python web apps (ASGI/Workers) with Streamable HTTP transport, session management, and optional OAuth2 authorization.
README
hayate-mcp
Mount an MCP server into a hayate app: an official MCP Python SDK bridge for ASGI and a focused, Pydantic-free tools runtime for Cloudflare Python Workers, both over the same Streamable HTTP boundary.
Status: alpha (0.8.x). Tracks the latest stable revision — MCP 2025-11-25 on both CPython/ASGI and Cloudflare Python Workers, with
MCP-Protocol-Versionheader validation. Serves MCP Inspector, Claude Code, and the official SDK client — single-JSON POST plus the optional server-initiated GET SSE stream on ASGI, and a stateless tools runtime on Cloudflare Workers, verified in CI on workerd and by the official SDK client. The internal design memo (Japanese) lives in DESIGN.md; release history is in CHANGELOG.md.
from mcp.server.lowlevel import Server # official SDK — define your tools here
from hayate import Hayate
from hayate_mcp import McpMount
server = Server("my-tools")
# … @server.list_tools() / @server.call_tool() …
app = Hayate()
McpMount(server, path="/mcp").register(app) # that's the whole integration
Serve it with any ASGI server (uvicorn server:app), then connect:
npx @modelcontextprotocol/inspector --cli http://127.0.0.1:8000/mcp --transport http --method tools/list
claude mcp add my-tools --transport http http://127.0.0.1:8000/mcp
What it implements
| Verb | ASGI | Workers |
|---|---|---|
| POST | JSON-RPC → JSON/SSE; stateful initialize mints an Mcp-Session-Id |
JSON-RPC → single JSON; stateless |
| GET | Server-initiated SSE stream (one per session; a second returns 409) | 405 (not advertised) |
| DELETE | Explicit session termination | 200 stateless no-op |
POST requests must use Content-Type: application/json and advertise both
application/json and text/event-stream in Accept; notifications and
client responses receive an empty 202. GET must advertise SSE. Plus
spec-mandated Origin validation (DNS-rebinding defense) and an
in-memory session store with idle eviction. On ASGI, capabilities, dispatch,
and versioning stay in the official SDK. The Workers runtime implements only
the lifecycle, ping, and tools surface it advertises; resources, prompts,
logging, sampling, tasks, and server-initiated streams are omitted from
capabilities rather than partially implemented.
After initialize, clients send MCP-Protocol-Version on every subsequent
HTTP request. The Workers runtime accepts exactly 2025-11-25; because it
does not implement the older fallback revision, a missing or different header
returns 400.
Authorization (OAuth 2.0 Resource Server)
Pass an Authorization to require Bearer tokens and serve RFC 9728 Protected
Resource Metadata (MCP Authorization, 2025-11-25):
from hayate_mcp import Authorization, McpMount
McpMount(server, authorization=Authorization(
resource="https://mcp.example.com/mcp",
authorization_servers=["https://auth.example.com"],
verify_token=verify, # async (token) -> claims | None
scopes_supported=["mcp", "documents:read"],
required_scopes=["mcp"],
), tool_scopes={
"read_document": ["documents:read"],
}).register(app)
Unauthenticated requests get 401 with
WWW-Authenticate: Bearer resource_metadata="…/.well-known/oauth-protected-resource",
so clients (Claude, Inspector) discover the authorization server. Token
issuance is the AS's job — point verify_token at hayate-auth or any
RFC 6749 server.
Verified claims are normalized (subject, client_id, scopes) and are
available inside tool handlers:
from hayate_mcp import get_principal
@server.call_tool()
async def call_tool(name, arguments):
principal = get_principal()
assert principal is not None
# principal["subject"], principal["scopes"], ...
Insufficient global or per-tool scopes return 403 with the MCP 2025-11-25
WWW-Authenticate step-up challenge. Stateful sessions are bound to the
creating (issuer, client_id, subject) identity.
On Cloudflare Workers
Use WorkerMcpServer and WorkerMcpMount on a plain Worker — no Durable
Object, Pydantic, or old SDK line is needed:
from hayate import Hayate
from hayate.adapters.workers import to_workers
from hayate_mcp import WorkerMcpMount, WorkerMcpServer
app = Hayate()
server = WorkerMcpServer("my-tools", version="1.0.0")
@server.tool(
name="echo",
description="Echo text.",
input_schema={
"type": "object",
"properties": {"text": {"type": "string"}},
"required": ["text"],
"additionalProperties": False,
},
)
async def echo(arguments):
return f"echo: {arguments['text']}"
WorkerMcpMount(server).register(app)
Default = to_workers(app)
Tool input and structured output use JSON Schema 2020-12 and are validated
inside request scope, keeping workerd global initialization entropy-safe.
Expected failures can raise ToolError; unexpected exceptions are logged and
sanitized before reaching the model. OAuth and per-tool scopes use the same
Authorization and get_principal() APIs as the SDK-backed mount.
See examples/workers. The Workers surface is stateless and does not advertise server-initiated streams or session state. Use the default SDK-backed ASGI mount (examples/echo) when you need those. CI builds the local wheel in an isolated project, boots current workerd, and connects with the official MCP SDK client.
Why
- Python is MCP's largest ecosystem, yet mounting an MCP endpoint inside your own web app still goes through ASGI plumbing with known friction.
- Cloudflare's remote-MCP story (Agents SDK, McpAgent) is TypeScript-first. hayate-mcp supplies a Python Workers path that speaks the same stable MCP revision without requiring the Pydantic-based SDK in the edge bundle.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。