Skip to content

feat: add retry logic to MCP server operations #1554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

rm-openai
Copy link
Collaborator

Summary

  • allow configuring retries with exponential backoff when listing tools or calling a tool on an MCP server via max_retry_attempts (supporting -1 for unlimited retries) and retry_backoff_seconds_base
  • propagate the retry parameters through the stdio, SSE, and streamable HTTP server implementations so callers can tune retries when constructing these servers
  • test that call_tool and list_tools retry appropriately

Testing

  • make lint
  • make mypy
  • make test (fails: No rule to make target 'test')
  • make tests
  • make old_version_tests (fails: Request failed after 3 retries (tunnel error))

https://chatgpt.com/codex/tasks/task_i_68a73cab8b9c8321876f6f3dd1dfcd20

Copy link

@brandonbaker-openai brandonbaker-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two super nits, feel free to ignore - thanks!

@@ -267,15 +290,17 @@ async def list_tools(
"""List the tools available on the server."""
if not self.session:
raise UserError("Server not initialized. Make sure you call `connect()` first.")
session = self.session
assert session is not None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: Feels silly to assert is not None right below the early exception on if not self.session

@@ -290,8 +315,10 @@ async def call_tool(self, tool_name: str, arguments: dict[str, Any] | None) -> C
"""Invoke a tool on the server."""
if not self.session:
raise UserError("Server not initialized. Make sure you call `connect()` first.")
session = self.session
assert session is not None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same super nit

@rm-openai rm-openai merged commit 2c5041d into main Aug 21, 2025
6 checks passed
@rm-openai rm-openai deleted the codex/add-retry-and-backoff-configuration-to-call_tool branch August 21, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants