Skip to content

fix(mcp): add retry + separated timeouts to FastAPI MCP _api_get (BUY-60518) - #16

Open
BuyWhere wants to merge 3 commits into
masterfrom
fix/mcp-timeout-retry-buy-60518
Open

fix(mcp): add retry + separated timeouts to FastAPI MCP _api_get (BUY-60518)#16
BuyWhere wants to merge 3 commits into
masterfrom
fix/mcp-timeout-retry-buy-60518

Conversation

@BuyWhere

Copy link
Copy Markdown
Collaborator

Problem

The MCP HTTP endpoint's in used a bare with no retry logic. When the 154M-row products table hits contention, the single-attempt HTTP call fails immediately, surfacing as -32603 errors in MCP tool calls.

Changes

  • 3-attempt retry with exponential backoff on /
  • **Separated **: connect scales with attempt (5s→7s→9s), read=25s (configurable), write=10s, pool=5s
  • env var (default 25s) for read timeout tuning
  • env var for base URL (consistent with standalone )
  • Aligns with the retry pattern already in

Why 25s read timeout?

Backend DB queries carry (8s). A 25s HTTP read timeout gives the backend query + connection overhead ample room while still failing fast enough for MCP UX. The retry mechanism handles transient contention pulses.

Testing

  • Syntax validation passed ()
  • No existing MCP-specific tests in the repo
  • Deploy and monitor MCP probe success rate for stability

Deployment

Merge → CI deploys to Cloud Run. Set env var on the service if not already inherited.

BuyWhere added 3 commits July 17, 2026 07:13
…-60518)

The MCP HTTP endpoint's _api_get used a bare timeout=10.0 with no retry.
When the 154M-row products table hits statement_timeout contention, the
single-attempt HTTP call fails immediately.

Changes:
- 3-attempt retry with exponential backoff on timeout/transport errors
- Separated httpx.Timeout: connect scales with attempt, read=25s (configurable),
  write=10s, pool=5s
- BUYWHERE_API_TIMEOUT env var (default 25s) for read timeout tuning
- BUYWHERE_API_URL env var for base URL (consistent with mcp_server.py)
- aligns with the retry pattern already in mcp_server.py

Also includes the country_code passthrough for get_deals tool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant