6da7ba4f09
`warm(everything=True)` warmed every protocol version's routing surface - not "everything the SDK could ever build": the mcp package's own model roots (mcpserver settings, tool/prompt argument models) belong to the mcp layer that mcp-types cannot see, and they build during server construction and tool registration anyway, which is startup work rather than first-request work. Naming the flag `all_versions` says what it does; the recommended host recipe is unchanged (`warm(version)` for the version the transport negotiates). WarmReport becomes a frozen dataclass instead of a NamedTuple, so a later field addition does not disturb code that reads the existing fields, and `mcp.warm` stays the very same function as `mcp_types.methods.warm` (pinned by a test).
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""The `mcp` package namespace: lazy exports (PEP 562) that stay identical to the eager originals.
|
|
|
|
The import-footprint half of the contract (what `import mcp` may load) lives in
|
|
tests/test_import_guards.py, together with the other entry points' guards.
|
|
"""
|
|
|
|
import pytest
|
|
from mcp_types import methods
|
|
|
|
import mcp
|
|
import mcp.server.session
|
|
import mcp.server.stdio
|
|
import mcp.shared.exceptions
|
|
from mcp.client.session_group import ClientSessionGroup
|
|
|
|
|
|
def test_exported_name_is_the_home_module_object_and_is_cached_on_the_package():
|
|
"""SDK-defined: `mcp.MCPError` is `mcp.shared.exceptions.MCPError`, cached after first access."""
|
|
assert mcp.MCPError is mcp.shared.exceptions.MCPError
|
|
assert vars(mcp)["MCPError"] is mcp.shared.exceptions.MCPError
|
|
|
|
|
|
def test_client_and_server_reexports_are_the_defining_objects():
|
|
"""SDK-defined: `mcp.ServerSession`, `mcp.stdio_server` and `mcp.ClientSessionGroup`
|
|
resolve on first access to the very objects their defining modules export."""
|
|
assert mcp.ServerSession is mcp.server.session.ServerSession
|
|
assert mcp.stdio_server is mcp.server.stdio.stdio_server
|
|
assert mcp.ClientSessionGroup is ClientSessionGroup
|
|
|
|
|
|
def test_warm_is_the_types_layer_prewarm_helper_itself():
|
|
"""SDK-defined: `mcp.warm` is `mcp_types.methods.warm` - one helper, two spellings."""
|
|
assert mcp.warm is methods.warm
|
|
|
|
|
|
def test_dir_lists_every_export_and_the_bound_submodules():
|
|
"""SDK-defined: `dir(mcp)` reports all of `__all__` plus the submodules a bare import binds."""
|
|
listing = set(dir(mcp))
|
|
assert set(mcp.__all__) <= listing
|
|
assert {"client", "os", "server", "shared", "types"} <= listing
|
|
|
|
|
|
def test_unknown_attribute_raises_attribute_error():
|
|
"""SDK-defined: a name that is neither an export nor a submodule raises AttributeError."""
|
|
with pytest.raises(AttributeError):
|
|
getattr(mcp, "no_such_name")
|