Skip to content

Commit 2a7fb0c

Browse files
committed
Keep PrimitiveSchemaDefinition reachable on mcp.server.elicitation
Its module-level import moved into the validation function that uses it, so the attribute would otherwise disappear from the module namespace. Resolve it on first access via a module-level __getattr__ (and keep it in dir()) so existing references to mcp.server.elicitation.PrimitiveSchemaDefinition keep working without reintroducing the import at module load.
1 parent 0237ed9 commit 2a7fb0c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎src/mcp/server/elicitation.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,21 @@ async def elicit_url(
191191
else: # pragma: no cover
192192
# This should never happen, but handle it just in case
193193
raise ValueError(f"Unexpected elicitation action: {result.action}")
194+
195+
196+
def __getattr__(name: str) -> Any:
197+
# `PrimitiveSchemaDefinition` used to be bound in this module by a
198+
# module-level import of the internal wire package; that import now
199+
# happens on first use (inside `_validate_rendered_properties`) so that
200+
# importing this module does not build the wire schema. Keep the attribute
201+
# resolving lazily for existing references to it.
202+
if name == "PrimitiveSchemaDefinition":
203+
from mcp_types._v2025_11_25 import PrimitiveSchemaDefinition
204+
205+
globals()[name] = PrimitiveSchemaDefinition
206+
return PrimitiveSchemaDefinition
207+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
208+
209+
210+
def __dir__() -> list[str]:
211+
return sorted({*globals(), "PrimitiveSchemaDefinition"})

‎tests/server/test_elicitation.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""`mcp.server.elicitation` module-level behaviour."""
2+
3+
import mcp_types._v2025_11_25 as wire
4+
5+
from mcp.server import elicitation
6+
7+
8+
def test_wire_schema_gate_type_is_still_reachable_on_the_module():
9+
"""`PrimitiveSchemaDefinition` used to be bound here by a module-level import; it now
10+
resolves lazily to the same class, and `dir()` still lists it."""
11+
assert elicitation.PrimitiveSchemaDefinition is wire.PrimitiveSchemaDefinition
12+
assert "PrimitiveSchemaDefinition" in dir(elicitation)

0 commit comments

Comments
 (0)