Skip to content

Retry MCP tool calls after closed-resource errors by refreshing session - #17

Closed
AminMahpour wants to merge 1 commit into
masterfrom
dev/investigate-closedresourceerror-in-mcp-follow-up
Closed

Retry MCP tool calls after closed-resource errors by refreshing session#17
AminMahpour wants to merge 1 commit into
masterfrom
dev/investigate-closedresourceerror-in-mcp-follow-up

Conversation

@AminMahpour

Copy link
Copy Markdown
Owner

Motivation

  • Follow-up MCP tool calls in the same chat session were failing with closedResourceError/"resource is closed" due to stale stateful MCP sessions and cached tool objects.

Description

  • Added retry handling in invoke_mcp_tool_command to catch closed-resource failures, refresh the MCP session scope, reload tools, and retry the same tool once in deepagent_runtime.py.
  • Extended _get_mcp_tools with a refresh flag to allow invalidating the _mcp_tools_cache and rebuilding tool objects on demand.
  • Added _refresh_mcp_scope to close/reset the current stateful MCP scope and _is_closed_mcp_resource_error to detect closed-resource error messages.
  • The retry path reloads tools for the candidate servers and attempts the tool invocation once more after refreshing state.

Testing

  • Ran python -m py_compile deepagent_runtime.py, which completed successfully.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant