Skip to main content

MCP Streamable HTTP for hayate across ASGI and Cloudflare Workers, with OAuth resource-server support

Project description

hayate-mcp

Mount an MCP server into a hayate app — a Streamable HTTP transport that bridges the official MCP Python SDK to WHATWG Request/Response. The @hono/mcp architecture, in Python.

Status: alpha (0.6.x). Tracks the SDK's latest revision — 2025-11-25 on CPython/ASGI (mcp ≥ 1.28), with MCP-Protocol-Version header 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 mode that runs on Cloudflare Workers (verified on workerd and a deployed Workers Paid application). On Workers the SDK is currently pinned to a 2025-06-18-capable version by Pyodide's pydantic-core wheel availability (DESIGN §6.2). 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 Behavior
POST JSON-RPC request → single JSON response (initialize mints an Mcp-Session-Id); notifications → 202
GET Server-initiated SSE stream (one per session; a second returns 409)
DELETE Explicit session termination

Plus spec-mandated Origin validation (DNS-rebinding defense) and an in-memory session store with idle eviction. Protocol handling — capabilities, tool dispatch, versioning — stays entirely in the official SDK: this package is transport only, so spec revisions ride SDK upgrades.

Authorization (OAuth 2.0 Resource Server)

Pass an Authorization to require Bearer tokens and serve RFC 9728 Protected Resource Metadata (MCP Authorization, 2025-06-18):

from hayate_mcp import Authorization, McpMount

McpMount(server, authorization=Authorization(
    resource="https://mcp.example.com",
    authorization_servers=["https://auth.example.com"],
    verify_token=verify,   # async (token) -> claims | None
)).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.

On Cloudflare Workers

Pass stateless=True and mount on a plain Worker — no Durable Object needed. Each request runs the SDK server to completion on its own, which is what makes it Workers-safe:

from hayate import Hayate
from hayate.adapters.workers import to_workers
from hayate_mcp import McpMount

app = Hayate()
McpMount(build_server(), stateless=True).register(app)
Default = to_workers(app)

See examples/workers (verified on workerd). Trade-off: stateless has no server-initiated GET stream and no cross-request session state — use the default stateful mode on ASGI (examples/echo) when you need those. (Import mcp lazily inside a handler on Workers, never at global scope — its dependency chain seeds entropy at import.)

Production verification uses a Workers Paid account: the cold lazy import of the MCP dependency chain takes roughly 3 seconds of CPU and exceeds the Free plan's Python runtime limiter. The application itself fits the Free plan's compressed bundle-size limit, but the SDK import does not complete there. Deployment measurements and the account/plan traps are recorded in docs/research/pyodide.md.

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-only — MCP on Python Workers was unclaimed territory. hayate-mcp runs there today (stateless mode, verified locally and on Workers Paid); the SDK imports and runs on Pyodide (docs/research/pyodide.md).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hayate_mcp-0.6.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hayate_mcp-0.6.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file hayate_mcp-0.6.1.tar.gz.

File metadata

  • Download URL: hayate_mcp-0.6.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_mcp-0.6.1.tar.gz
Algorithm Hash digest
SHA256 bbe46a62745d43826d7e9d97bfcb7a3a735bc34fcd37c1c2dbf104e9c0588600
MD5 88799486caca26e5ea7396f672158147
BLAKE2b-256 af9d67e189d2ddb094d81e7bbaba01d36c24e57e7bf17f908020ed8a6c9820e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_mcp-0.6.1.tar.gz:

Publisher: release.yml on hayatepy/hayate-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hayate_mcp-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: hayate_mcp-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hayate_mcp-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb07074cbcdbd766885586d575ef00fd090404b07c307ecfd237b0dbe570b661
MD5 fc5aa60eb47853a5b7c556243a4608f6
BLAKE2b-256 ef0455c090cb25b19eb4ba036c28424107967e037459e31c2e8b454c54324f98

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayate_mcp-0.6.1-py3-none-any.whl:

Publisher: release.yml on hayatepy/hayate-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page