test: fix WS test port race; narrow to single smoke test covering both transport ends (#2267)

This commit is contained in:
Max Isbey 2026-03-18 15:48:30 +00:00 • committed by GitHub
commit 67201a9bbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,7 @@ import anyio
import pytest
from inline_snapshot import snapshot
from mcp import types
from mcp import MCPError, types
from mcp.client._memory import InMemoryTransport
from mcp.client.client import Client
from mcp.server import Server, ServerRequestContext
@ -175,6 +175,21 @@ async def test_read_resource(app: MCPServer):
)
async def test_read_resource_error_propagates():
"""MCPError raised by a server handler propagates to the client with its code intact."""
async def handle_read_resource(
ctx: ServerRequestContext, params: types.ReadResourceRequestParams
) -> ReadResourceResult:
raise MCPError(code=404, message="no resource with that URI was found")
server = Server("test", on_read_resource=handle_read_resource)
async with Client(server) as client:
with pytest.raises(MCPError) as exc_info:
await client.read_resource("unknown://example")
assert exc_info.value.error.code == 404
async def test_get_prompt(app: MCPServer):
"""Test getting a prompt."""
async with Client(app) as client: