@@ -228,6 +228,89 @@ async def list_client_tasks(name: str, arguments: dict[str, Any]) -> list[types.
228228 assert "Found 3 tasks" in result .content [0 ].text
229229
230230
231+ @pytest .mark .anyio
232+ async def test_server_queries_client_get_task_payload_not_found ():
233+ """Test server querying client for non-existent task payload."""
234+ server_task_store = InMemoryTaskStore ()
235+ client_task_store = InMemoryTaskStore ()
236+ server = Server ("test" , task_store = server_task_store )
237+
238+ @server .list_tools ()
239+ async def list_tools () -> list [types .Tool ]:
240+ return [
241+ types .Tool (
242+ name = "query_nonexistent_payload" ,
243+ description = "Query nonexistent task payload" ,
244+ inputSchema = {"type" : "object" , "properties" : {}, "required" : []},
245+ )
246+ ]
247+
248+ @server .call_tool ()
249+ async def query_nonexistent_payload (name : str , arguments : dict [str , Any ]) -> list [types .TextContent ]:
250+ try :
251+ session = server .request_context .session
252+ await session .get_task_result ("nonexistent-task" , types .ClientResult )
253+ return [types .TextContent (type = "text" , text = "Should have failed" )]
254+ except Exception as e :
255+ return [types .TextContent (type = "text" , text = f"Error: { str (e )} " )]
256+
257+ async with create_connected_server_and_client_session (server ) as client_session :
258+ client_session ._task_store = client_task_store
259+ await client_session .initialize ()
260+
261+ result = await client_session .call_tool ("query_nonexistent_payload" , {})
262+
263+ assert len (result .content ) == 1
264+ assert isinstance (result .content [0 ], types .TextContent )
265+ assert "Error" in result .content [0 ].text
266+ assert "Task not found" in result .content [0 ].text or "INVALID_PARAMS" in result .content [0 ].text
267+
268+
269+ @pytest .mark .anyio
270+ async def test_server_queries_client_get_task_payload_not_completed ():
271+ """Test server querying client for task payload when task is not completed."""
272+ server_task_store = InMemoryTaskStore ()
273+ client_task_store = InMemoryTaskStore ()
274+ server = Server ("test" , task_store = server_task_store )
275+
276+ # Create a task that is NOT completed
277+ task_id = "client-pending-task"
278+ task_meta = types .TaskMetadata (taskId = task_id , keepAlive = 60000 )
279+ request = types .ServerRequest (types .PingRequest ())
280+ await client_task_store .create_task (task_meta , "req-1" , request .root )
281+ await client_task_store .update_task_status (task_id , "submitted" )
282+
283+ @server .list_tools ()
284+ async def list_tools () -> list [types .Tool ]:
285+ return [
286+ types .Tool (
287+ name = "query_incomplete_payload" ,
288+ description = "Query incomplete task payload" ,
289+ inputSchema = {"type" : "object" , "properties" : {}, "required" : []},
290+ )
291+ ]
292+
293+ @server .call_tool ()
294+ async def query_incomplete_payload (name : str , arguments : dict [str , Any ]) -> list [types .TextContent ]:
295+ try :
296+ session = server .request_context .session
297+ await session .get_task_result (task_id , types .ClientResult )
298+ return [types .TextContent (type = "text" , text = "Should have failed" )]
299+ except Exception as e :
300+ return [types .TextContent (type = "text" , text = f"Error: { str (e )} " )]
301+
302+ async with create_connected_server_and_client_session (server ) as client_session :
303+ client_session ._task_store = client_task_store
304+ await client_session .initialize ()
305+
306+ result = await client_session .call_tool ("query_incomplete_payload" , {})
307+
308+ assert len (result .content ) == 1
309+ assert isinstance (result .content [0 ], types .TextContent )
310+ assert "Error" in result .content [0 ].text
311+ assert "not 'completed'" in result .content [0 ].text or "INVALID_PARAMS" in result .content [0 ].text
312+
313+
231314@pytest .mark .anyio
232315async def test_server_list_tasks_empty ():
233316 """Test server querying client with empty task list."""
0 commit comments