Add mcp.types as a permanent alias for mcp_types (#3190)
This commit is contained in:
parent
923341c98a
commit
b7c9a916d6
1 changed files with 467 additions and 364 deletions
|
|
@ -1,5 +1,12 @@
|
|||
import subprocess
|
||||
import sys
|
||||
from types import ModuleType
|
||||
from typing import Any
|
||||
|
||||
import mcp_types
|
||||
import mcp_types.jsonrpc
|
||||
import mcp_types.methods
|
||||
import mcp_types.version
|
||||
import pytest
|
||||
from inline_snapshot import snapshot
|
||||
from mcp_types import (
|
||||
|
|
@ -38,6 +45,12 @@ from mcp_types import (
|
|||
)
|
||||
from pydantic import ValidationError
|
||||
|
||||
import mcp
|
||||
import mcp.types
|
||||
import mcp.types.jsonrpc
|
||||
import mcp.types.methods
|
||||
import mcp.types.version
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_jsonrpc_request():
|
||||
|
|
@ -445,3 +458,48 @@ def test_input_required_result_requires_at_least_one_of_input_requests_or_reques
|
|||
with pytest.raises(ValidationError):
|
||||
InputRequiredResult(input_requests={})
|
||||
assert InputRequiredResult(request_state="s").input_requests is None
|
||||
|
||||
|
||||
def _assert_mirrors(mirror: ModuleType, source: ModuleType) -> None:
|
||||
# The mirror shares the source's `__all__` list object by construction (`from source import
|
||||
# __all__`), so the meaningful proof is that every exported name is the identical object.
|
||||
assert all(getattr(mirror, name) is getattr(source, name) for name in source.__all__)
|
||||
|
||||
|
||||
def test_mcp_types_namespace_mirrors_mcp_types_exactly():
|
||||
"""SDK-defined: `mcp.types` is a permanent alias whose every name is the `mcp_types` object."""
|
||||
_assert_mirrors(mcp.types, mcp_types)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mirror", "source"),
|
||||
[
|
||||
(mcp.types.jsonrpc, mcp_types.jsonrpc),
|
||||
(mcp.types.methods, mcp_types.methods),
|
||||
(mcp.types.version, mcp_types.version),
|
||||
],
|
||||
ids=["jsonrpc", "methods", "version"],
|
||||
)
|
||||
def test_mcp_types_submodules_mirror_mcp_types_submodules_exactly(mirror: ModuleType, source: ModuleType):
|
||||
"""SDK-defined: every supported `mcp_types` submodule has an `mcp.types` mirror, name for name."""
|
||||
_assert_mirrors(mirror, source)
|
||||
|
||||
|
||||
def test_bare_import_mcp_binds_the_types_submodule():
|
||||
"""SDK-defined: `import mcp` alone binds `mcp.types`, so v1's `mcp.types.Tool` idiom works.
|
||||
|
||||
A fresh interpreter is required to observe `import mcp` in isolation: this test process
|
||||
has already imported `mcp.types`, and reloading `mcp` here would rebind classes that other
|
||||
tests hold references to.
|
||||
"""
|
||||
# A regression hangs forever, so the bound only has to beat never (matches the suite's
|
||||
# other subprocess.run calls).
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import mcp; print(mcp.types.Tool.__name__)"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
timeout=20,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert result.stdout == snapshot("Tool\n")
|
||||
|
|
|
|||
Loading…
Reference in a new issue