Split protocol types into a standalone `mcp-types` package

Merged
KL
5mo ago
+1040-867

What

Extract the protocol wire types from src/mcp/types/ into a separate distribution, mcp-types (imported as mcp_types), wired into the existing uv workspace as a member under src/mcp-types/ (same nesting as httpx2/httpcore2).

mcp-types depends only on pydantic + typing-extensions, so tooling and lightweight clients can (de)serialize MCP traffic without pulling in httpx, starlette, uvicorn, and the rest of the server/transport stack.

Key changes

  • src/mcp/types/ → src/mcp-types/mcp_types/ (_types, jsonrpc, _wire_base, methods, v2025_11_25/, v2026_07_28/), moved with git mv so history is preserved.
  • src/mcp/shared/version.py → src/mcp-types/mcp_types/version.py. It is a pure leaf with no mcp dependencies, which is what lets mcp_types depend on nothing in mcp (methods.py needs KNOWN_PROTOCOL_VERSIONS).
  • mcp.types and mcp.shared.version are removed (no shim). All importers are rewritten to mcp_types / mcp_types.version.
  • mcp.__init__ still re-exports the type names from mcp_types, so from mcp import Tool is unchanged.
  • Workspace/build wiring: [tool.uv.workspace] member, [tool.uv.sources], mcp dependency, pyright include, ruff per-file-ignore, coverage source + [tool.coverage.paths] mapping, and scripts/gen_surface_types.py output path + --base-class.

Breaking change

from mcp.types import X and from mcp.shared.version import X no longer work; use from mcp_types import X / from mcp_types.version import X. The top-level from mcp import X re-exports are unchanged. Documented in docs/migration.md.

Verification

  • 2714 tests pass; pyright reports 0 errors; ruff/format clean.
  • 100.00% coverage, strict-no-cover clean.
  • mcp-types builds standalone (wheel includes py.typed and all modules).
  • scripts/gen_surface_types.py --check regenerates the v* validators identically from the new path.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.