test: fix WS test port race; narrow to single smoke test covering both transport ends (#2267)
This commit is contained in:
parent
7826ade12b
commit
67201a9bbd
1 changed files with 97 additions and 187 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue