Skip to content

Commit ffacba6

Browse files
committed
Add tests for StC tasks without client store
1 parent 6951978 commit ffacba6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/mcp/client/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ async def _received_request(self, responder: RequestResponder[types.ServerReques
762762
types.ErrorData(code=types.INVALID_REQUEST, message="Task store not configured")
763763
)
764764

765-
case _:
765+
case _: # pragma: no cover
766766
# Other request types are not expected to be received by the client
767767
pass
768768

tests/client/test_server_to_client_tasks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,42 @@ async def query_client_result(name: str, arguments: dict[str, Any]) -> list[type
187187
assert "EmptyResult" in result.content[0].text
188188

189189

190+
@pytest.mark.anyio
191+
async def test_server_queries_client_get_task_payload_without_task_store():
192+
"""Test server querying client for task payload without task store configured."""
193+
server = Server("test", task_store=InMemoryTaskStore())
194+
195+
@server.list_tools()
196+
async def list_tools() -> list[types.Tool]:
197+
return [
198+
types.Tool(
199+
name="query_payload_no_store",
200+
description="Query payload without store",
201+
inputSchema={"type": "object", "properties": {}, "required": []},
202+
)
203+
]
204+
205+
@server.call_tool()
206+
async def query_payload_no_store(name: str, arguments: dict[str, Any]) -> list[types.TextContent]:
207+
try:
208+
session = server.request_context.session
209+
await session.get_task_result("some-task", types.ClientResult)
210+
return [types.TextContent(type="text", text="Should have failed")]
211+
except Exception as e:
212+
return [types.TextContent(type="text", text=f"Error: {str(e)}")]
213+
214+
async with create_connected_server_and_client_session(server) as client_session:
215+
# No task store on client
216+
await client_session.initialize()
217+
218+
result = await client_session.call_tool("query_payload_no_store", {})
219+
220+
assert len(result.content) == 1
221+
assert isinstance(result.content[0], types.TextContent)
222+
assert "Error" in result.content[0].text
223+
assert "Task store not configured" in result.content[0].text or "INVALID_REQUEST" in result.content[0].text
224+
225+
190226
@pytest.mark.anyio
191227
async def test_server_queries_client_list_tasks():
192228
"""Test server querying client's task list."""

0 commit comments

Comments
 (0)