Skip to content

Commit 5abe554

Browse files
committed
Fix PendingRequest delay when not found
1 parent 91e7561 commit 5abe554

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/mcp/shared/request.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,14 @@ async def _task_handler(
165165
"""
166166
# Poll for completion
167167
task: GetTaskResult
168+
poll_interval = DEFAULT_POLLING_INTERVAL * 1000.0
168169
while True:
169170
try:
170171
task = await self.session.get_task(task_id)
171172
except McpError as e:
172173
if e.error.code == INVALID_PARAMS:
173174
# Task may not exist yet
175+
await anyio.sleep(poll_interval / 1000.0)
174176
continue
175177
raise
176178
await on_task_status(task)
@@ -179,8 +181,8 @@ async def _task_handler(
179181
break
180182

181183
# Wait before polling again
182-
poll_frequency = task.pollInterval if task.pollInterval is not None else DEFAULT_POLLING_INTERVAL * 1000
183-
await anyio.sleep(poll_frequency / 1000.0)
184+
poll_interval = task.pollInterval if task.pollInterval is not None else DEFAULT_POLLING_INTERVAL * 1000
185+
await anyio.sleep(poll_interval / 1000.0)
184186

185187
# Retrieve and return the result
186188
return await self.session.get_task_result(task_id, self.result_type)

0 commit comments

Comments
 (0)