MCP & Connectors

How do you handle timeout errors in MCP server calls?

QUICK ANSWER

In your client connector code, wrap requests in timeout wrappers that reject after a threshold (e.g., 60 seconds) and ensure your server yields status updates for long-running processes.

Handling timeouts in client code

async function fetchWithTimeout(client, requestParams, timeoutMs = 30000) {
  const timeoutPromise = new Promise((_, reject) => 
    setTimeout(() => reject(new Error("MCP request timed out")), timeoutMs)
  );
  return Promise.race([
    client.request(requestParams),
    timeoutPromise
  ]);
}
Verified against: MCP SDK v0.7.0