Skip to content

Commit b9422f1

Browse files
authored
Make the per-version wire packages private (mcp_types._v*) (#3191)
1 parent 45f2a88 commit b9422f1

13 files changed

Lines changed: 133 additions & 127 deletions

File tree

.github/workflows/shared.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: mcp-types installs and imports standalone
5252
run: |
5353
uv run --isolated --no-project --with ./src/mcp-types python -c \
54-
"import mcp_types, mcp_types.jsonrpc, mcp_types.methods, mcp_types.version, mcp_types.v2025_11_25, mcp_types.v2026_07_28"
54+
"import mcp_types, mcp_types.jsonrpc, mcp_types.methods, mcp_types.version, mcp_types._v2025_11_25, mcp_types._v2026_07_28"
5555
5656
test:
5757
name: test (${{ matrix.python-version }}, ${{ matrix.dep-resolution.name }}, ${{ matrix.os }})

docs/migration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ continues to re-export the type names at the top level, so `from mcp import Tool
175175
unchanged. Only the `mcp.types` submodule and `mcp.shared.version` were removed. The
176176
package's API reference is at [`mcp_types`](api/mcp_types/index.md).
177177

178+
The supported import surface is `mcp_types`, `mcp_types.jsonrpc`, `mcp_types.methods`, and
179+
`mcp_types.version`. Underscore-prefixed submodules (`mcp_types._types`, and the generated
180+
per-protocol-version packages `mcp_types._v2025_11_25` / `mcp_types._v2026_07_28`) are internal
181+
validators with unstable class names; don't import from them.
182+
178183
**Why:** keeping the wire types in their own package lets tooling and lightweight clients
179184
depend on the protocol schema without pulling in `httpx2`, `starlette`, `uvicorn`, and the
180185
rest of the server/transport stack.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ max-complexity = 24 # Default is 10
218218
[tool.ruff.lint.per-file-ignores]
219219
"__init__.py" = ["F401"]
220220
# Generated by scripts/gen_surface_types.py: raw datamodel-codegen output (TID251 lifts the repo-wide RootModel ban for these generated validators).
221-
"src/mcp-types/mcp_types/v*/__init__.py" = ["D212", "E501", "I001", "TID251", "UP007", "UP037"]
221+
"src/mcp-types/mcp_types/_v*/__init__.py" = ["D212", "E501", "I001", "TID251", "UP007", "UP037"]
222222
"tests/server/mcpserver/test_func_metadata.py" = ["E501"]
223223
"tests/shared/test_progress_notifications.py" = ["PLW0603"]
224224

schema/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
JSON Schema files for each protocol version the SDK has a wire-shape surface
44
package for, vendored from the [spec repository] at the commit recorded in
55
`PINNED.json`. `scripts/gen_surface_types.py` reads these to regenerate
6-
`src/mcp-types/mcp_types/v<version>/__init__.py`; CI runs the generator with
7-
`--check`.
6+
`src/mcp-types/mcp_types/_v<version>/__init__.py` (underscore-private: internal
7+
validators, not public API); CI runs the generator with `--check`.
88

99
To bump: drop the new `schema.json` here as `<protocol-version>.json`, update
1010
the matching entry in `PINNED.json` (commit + sha256), and run

scripts/gen_surface_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Regenerate the per-version wire-shape surface packages from vendored schemas.
22
33
Runs `datamodel-code-generator` over each `schema/PINNED.json` entry and
4-
writes the result to `src/mcp-types/mcp_types/v<version>/__init__.py` with only the
5-
fixes the raw output needs: a small JSON pre-patch for the known
4+
writes the result to `src/mcp-types/mcp_types/_v<version>/__init__.py` (the
5+
underscore marks these as internal validators, not public API) with only
6+
the fixes the raw output needs: a small JSON pre-patch for the known
67
`number`-as-`integer` schema.json defect, a header, full URLs for the spec's
78
site-absolute doc links, and per-version epilogue aliases. Run with
89
`uv run --frozen --group codegen python scripts/gen_surface_types.py [--check]`.
@@ -270,7 +271,7 @@ def main(argv: list[str] | None = None) -> int:
270271

271272
drift = False
272273
for entry in load_pinned():
273-
target = TYPES_DIR / ("v" + entry["protocol_version"].replace("-", "_")) / "__init__.py"
274+
target = TYPES_DIR / ("_v" + entry["protocol_version"].replace("-", "_")) / "__init__.py"
274275
candidate = build(entry)
275276
if not args.check:
276277
target.parent.mkdir(parents=True, exist_ok=True)

src/mcp-types/mcp_types/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
One model per protocol construct, carrying every field from every supported
44
protocol version, so application code sees a single set of types regardless of
55
the negotiated version. Per-field docstrings note version availability. The
6-
`mcp_types.v*` surface packages carry the schema-exact wire shapes.
6+
`mcp_types._v*` surface packages carry the schema-exact wire shapes.
77
"""
88

99
from __future__ import annotations
File renamed without changes.
File renamed without changes.

src/mcp-types/mcp_types/_wire_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Shared pydantic base for the generated `mcp_types.v*` wire-shape packages."""
1+
"""Shared pydantic base for the generated `mcp_types._v*` wire-shape packages."""
22

33
from pydantic import BaseModel, ConfigDict
44

src/mcp-types/mcp_types/methods.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Per-version method maps and parse/serialize functions for MCP traffic.
22
3-
This module is supported public API; the `mcp_types.v*` packages it draws on
3+
This module is supported public API; the `mcp_types._v*` packages it draws on
44
are internal validators and not for direct import.
55
66
Surface maps key `(method, version)` to per-version wire types (key absence is
@@ -18,8 +18,8 @@
1818
from pydantic import BaseModel, TypeAdapter
1919

2020
import mcp_types as types
21-
import mcp_types.v2025_11_25 as v2025
22-
import mcp_types.v2026_07_28 as v2026
21+
import mcp_types._v2025_11_25 as v2025
22+
import mcp_types._v2026_07_28 as v2026
2323
from mcp_types.version import KNOWN_PROTOCOL_VERSIONS
2424

2525
__all__ = [

0 commit comments

Comments
 (0)