Skip to content

Commit 95663d3

Browse files
committed
Make the per-version wire packages private (mcp_types._v*)
`mcp_types.v2025_11_25` and `mcp_types.v2026_07_28` are generated per-schema-era validators with unstable, codegen-derived class names (`Params1`, `Error1`, ...); their own docstrings and `methods.py` already describe them as internal, but the public-looking module names meant the API reference generator would publish ~350 of these classes as documented API. Rename them to `_v2025_11_25` / `_v2026_07_28` so the naming, the docs generator's underscore rule, and the stated intent agree. The supported surface (`mcp_types`, `.jsonrpc`, `.methods`, `.version`) is unchanged, and `methods.py`'s public maps still route through the same models. Update the codegen output path, the ruff per-file ignore, the standalone smoke import, and note the supported import surface in the migration guide.
1 parent 45f2a88 commit 95663d3

12 files changed

Lines changed: 131 additions & 125 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

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__ = [

src/mcp/server/elicitation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mcp_types import RequestId
88

99
# Internal surface package; imported as the gate's source of truth for spec-valid property schemas.
10-
from mcp_types.v2025_11_25 import PrimitiveSchemaDefinition
10+
from mcp_types._v2025_11_25 import PrimitiveSchemaDefinition
1111
from pydantic import BaseModel, ValidationError
1212
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
1313
from pydantic_core import core_schema

0 commit comments

Comments
 (0)