DB latency amplifies significantly across MCP tool calls
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 407
- Forks
- 57
- Avg merge
- 5h 6m
- Merged PRs (30d)
- 880
Description
Summary
A 5s per-TCP-segment latency on the Postgres connection results in 45-60s total time for a single MCP tool call (COLLECTION_CONNECTIONS_LIST). This is because each tool call involves multiple sequential DB roundtrips: authentication, permission checks, and the actual tool query.
Reproduction
Using the resilience test bed (tests/resilience/):
- Start the Docker stack
- Add 5s latency toxic to Postgres:
curl -X POST http://127.0.0.1:18474/proxies/postgres/toxics -d '{"type":"latency","attributes":{"latency":5000},"name":"db-slow"}' - Call any MCP tool and measure: a simple
COLLECTION_CONNECTIONS_LISTtakes ~45s - With 15s latency, health check (
SELECT 1) takes 15s but tool calls would take 2-3 minutes
Observed Behavior
| DB Latency | Health Check (SELECT 1) |
Tool Call (COLLECTION_CONNECTIONS_LIST) |
|---|---|---|
| 0ms | ~5ms | ~30ms |
| 5s/segment | ~5s | ~45-60s |
| 15s/segment | ~15s | 2-3min (estimated) |
Analysis
Each MCP tool call goes through this pipeline, each step hitting the DB:
- API key verification — look up key in
apikeystable - Session/user resolution — query user/session tables
- Organization resolution — query organization membership
- Permission check — query API key permissions
- Tool execution — the actual query (e.g., list connections)
- Audit logging — write audit log entry
With 5s latency per segment, 9+ DB roundtrips = 45s+ total.
Impact
- User experience: During DB slowdowns (e.g., vacuum, replication lag), users experience tool call timeouts even though the DB is technically "up"
- Connection pool exhaustion: Slow queries hold connections longer, reducing pool capacity for other requests
- Cascading failures: Health checks pass (single
SELECT 1is fast enough) while actual tool calls timeout — load balancers continue routing to degraded pods
Potential Mitigations
- Connection pooling with statement timeout: Set
statement_timeoutat the pool level so individual queries fail fast - Caching: Cache auth/permission lookups (they rarely change) to reduce DB roundtrips per tool call
- Circuit breaker on DB: If average query latency exceeds threshold, start failing fast instead of queuing
- Health check with representative query: Use a query that approximates real tool call cost, not just
SELECT 1
Found By
Resilience test bed: tests/resilience/scenarios/postgres-slow.test.ts
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/resilience/scenarios/postgres-slow.test.ts and the MCP tool-call path described in the issue. Trace the authentication, session, organization, permission, execution, and audit DB roundtrips, then confirm the selected mitigation with a slow-Postgres scenario. Done should include a maintainer-agreed fix and regression coverage; the issue lists alternatives but does not choose one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, postgres, typescript
- Domain
- backend, databases, performance, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100