Skip to content

[BUG] No timeout guard on DB fetches in MCP read tools — tools hang indefinitely on slow DB #457

Description

@Sofiyan-Shaikh

Description

All MCP read tools in mcp/tools/read-tools.ts call fetchAllProductsFromDb(), fetchAllProfilesFromDb(), fetchCachedEvents(), validateDiscountCode(), and raw dbPool.query() with no timeout guard at the MCP layer. If the database is slow, overloaded, or unreachable, every one of these tool calls will hang indefinitely — blocking the MCP server and the AI agent waiting on a response.

Current Behavior

The following DB calls across 7 registered tools have no timeout:

Tool Call Line
search_products fetchAllProductsFromDb() 231
get_product_details fetchAllProductsFromDb() 315
list_companies fetchAllProfilesFromDb() 375
get_company_details Promise.all([fetchAllProfilesFromDb(), fetchAllProductsFromDb(), fetchCachedEvents(31555)]) 423
get_reviews fetchCachedEvents(31555) 570
check_discount_code validateDiscountCode() 623
get_storefront dbPool.query() × 2, Promise.all([fetchAllProfilesFromDb(), fetchAllProductsFromDb()]) 689, 713, 765

A slow or hung DB connection causes the tool to wait forever with no error returned to the caller.

Expected Behavior

Each DB fetch in the MCP layer should be wrapped with a timeout (e.g. 10–30 seconds). If the deadline is exceeded, the tool should return a structured error response:

json
{
"error": "DB fetch timed out",
"code": "TIMEOUT",
"_meta": {
"responseTimeMs": 10000,
"dataSource": "cached_db"
}
}

This keeps the MCP server responsive and gives the AI agent a clear signal to retry or fall back.

Steps to Reproduce

  1. Simulate a slow DB by throttling the database connection or making fetchAllProductsFromDb() delay artificially (e.g. await new Promise(r => setTimeout(r, 60000))).
  2. Call any of the affected MCP tools: search_products, get_product_details, list_companies, get_company_details, get_reviews, check_discount_code, or get_storefront.
  3. Observe that the tool call never resolves — no timeout error, no response, no feedback.

Next.js Version

16.2.3

Operating System

macOS

Node.js Version

20.7.0

Browser

Chrome

Screenshots

No response

Additional Context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions