Skip to content

Commit 0c6211e

Browse files
committed
Drop dead OpenWireModel; add --frozen to codegen invocations; tighten generated-file pyright suppression
1 parent 30ca8b9 commit 0c6211e

4 files changed

Lines changed: 8 additions & 17 deletions

File tree

.github/workflows/shared.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Surface types match vendored schema
3434
run: |
3535
uv sync --group codegen --frozen
36-
uv run --group codegen python scripts/gen_surface_types.py --check
36+
uv run --frozen --group codegen python scripts/gen_surface_types.py --check
3737
3838
# TODO(Max): Drop this in v2. Deliberate updates (e.g. the v2 status
3939
# banner) go through the 'override-readme-freeze' label.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ max-complexity = 24 # Default is 10
178178

179179
[tool.ruff.lint.per-file-ignores]
180180
"__init__.py" = ["F401"]
181-
# Generated by scripts/gen_surface_types.py: raw datamodel-codegen output.
181+
# Generated by scripts/gen_surface_types.py: raw datamodel-codegen output (TID251 lifts the repo-wide RootModel ban for these generated validators).
182182
"src/mcp/types/v*/__init__.py" = ["D212", "E501", "I001", "TID251", "UP007", "UP037"]
183183
"tests/server/mcpserver/test_func_metadata.py" = ["E501"]
184184
"tests/shared/test_progress_notifications.py" = ["PLW0603"]

scripts/gen_surface_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
writes the result to ``src/mcp/types/v<version>/__init__.py`` with only the
55
fixes the raw output needs: a small JSON pre-patch for the known
66
``number``-as-``integer`` schema.json defect, a header, and per-version
7-
epilogue aliases. Run with ``uv run --group codegen python scripts/gen_surface_types.py [--check]``.
7+
epilogue aliases. Run with ``uv run --frozen --group codegen python scripts/gen_surface_types.py [--check]``.
88
"""
99

1010
from __future__ import annotations
@@ -27,6 +27,7 @@
2727

2828
# schema.ts -> schema.json renders TypeScript ``number`` as JSON Schema
2929
# ``integer`` at these sites; patch the JSON before codegen so floats validate.
30+
# TODO: drop once modelcontextprotocol/modelcontextprotocol fixes the schema.ts -> schema.json number rendering.
3031
SCHEMA_PATCHES: dict[str, list[tuple[str, Any, Any]]] = {
3132
"2025-11-25": [
3233
("$defs/NumberSchema/properties/default/type", "integer", "number"),
@@ -93,7 +94,7 @@ def patch_schema(schema: dict[str, Any], patches: list[tuple[str, Any, Any]]) ->
9394
def run_codegen(schema_path: Path, output_path: Path) -> None:
9495
"""Run datamodel-code-generator (from the ``codegen`` dependency group)."""
9596
exe = shutil.which("datamodel-codegen")
96-
cmd = [exe] if exe else ["uv", "run", "--group", "codegen", "datamodel-codegen"]
97+
cmd = [exe] if exe else ["uv", "run", "--frozen", "--group", "codegen", "datamodel-codegen"]
9798
# fmt: off
9899
result = subprocess.run(
99100
[

src/mcp/types/_wire_base.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
"""Shared pydantic bases for the `mcp.types.v*` wire-shape packages.
2-
3-
No alias generator is configured: every wire name is an explicit
4-
`Field(alias=...)` so each surface file shows exactly what goes on the wire.
5-
"""
1+
"""Shared pydantic base for the generated ``mcp.types.v*`` wire-shape packages."""
62

73
from pydantic import BaseModel, ConfigDict
84

95

106
class WireModel(BaseModel):
11-
"""Base for surface-package models: unknown fields are accepted and dropped."""
12-
13-
model_config = ConfigDict(populate_by_name=True, extra="ignore")
14-
15-
16-
class OpenWireModel(BaseModel):
17-
"""Base for `_meta` carrier models: unknown fields are retained for round-tripping."""
7+
"""Base for generated wire models: enables ``populate_by_name``; subclasses set ``extra="allow"`` themselves."""
188

19-
model_config = ConfigDict(populate_by_name=True, extra="allow")
9+
model_config = ConfigDict(populate_by_name=True)

0 commit comments

Comments
 (0)