Notes from a 2 AM On-Call: Why Our Stitch MCP Server Died Silently on Tool Timeouts

At 2:14 AM PST, our Stitch MCP server process (stitch-skills) running against Claude Code agents went dark. No crash logs. No stderr output. Just a silent exit 0 and a socket EOF on the client side.

The raw symptom:

[claude-code] Error: MCP server connection lost (code: 0) [stitch-skills] (no output, clean exit) [docker stats] stitch-skills container: 137 (OOMKilled? No.) 

No OOM. No segfault. Just a graceful suicide.

The Red Herring

Every MCP tutorial tells you to wrap tool handlers in try-catch. We did:

// What the docs recommend server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const result = await executeSkill(request.params.name, request.params.arguments); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } }); 

This handles synchronous exceptions. It does not handle the case where executeSkill() spawns a long-running subprocess (like git clone or npm install in a skill) that hangs indefinitely, and the MCP JSON-RPC transport times out before the Promise settles.

What actually happened: Claude Code sent a tools/call request to execute the git_clone_skill from stitch-skills. The skill spawned git clone https://massive-monorepo.git (4.2 GB). After 30 seconds, the stdio transport's implicit read timeout fired, but our handler was still await-ing the git process. The transport layer closed the stdio pipe, the process received SIGPIPE, and Node.js default SIGPIPE handler called process.exit(0).

No exception. No stderr. Silent death.

The Root Cause & Runnable Fix

The @modelcontextprotocol/sdk stdio transport has an implicit 30s read timeout, but does not expose a timeout config option in the current stable release (0.5.x). When a tool handler exceeds this, the transport closes, but unhandled SIGPIPE kills the process.

The 3-line fix:

// server.ts - Add at the top of your Stitch MCP server entrypoint process.on('SIGPIPE', () => { console.error('[SIGPIPE] Transport closed mid-execution, graceful shutdown'); process.exit(1); // Non-zero for monitoring }); server.setRequestHandler(CallToolRequestSchema, async (request) => { const SKILL_TIMEOUT_MS = 25000; // Under transport's 30s limit try { const result = await Promise.race([ executeSkill(request.params.name, request.params.arguments), new Promise((_, reject) => setTimeout(() => reject(new Error('Skill timeout')), SKILL_TIMEOUT_MS) ) ]); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } catch (error) { console.error(`[tool:${request.params.name}] ${error.message}`); return { content: [{ type: "text", text: `Execution failed: ${error.message}` }], isError: true }; } }); 

Key changes:

  1. Explicit SIGPIPE handler logs the failure mode.
  2. Promise.race() enforces a 25s skill timeout, guaranteeing handler completion before transport timeout.
  3. Timeout errors are now caught and returned as proper MCP error responses.

Production Config for Claude Code

When integrating stitch-skills with Claude Code, add monitoring to your claude_desktop_config.json:

{ "mcpServers": { "stitch": { "command": "node", "args": ["/path/to/stitch-skills/dist/server.js"], "env": { "NODE_OPTIONS": "--max-old-space-size=512", "SKILL_TIMEOUT_MS": "25000" } } } } 

For production deployments routing through a relay gateway (e.g., when benchmarking multi-model fallback through B-Lost's relay at https://b-lost.com/v1), add health checks:

// health-check.ts import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; const transport = new StdioClientTransport({ command: 'node', args: ['./dist/server.js'] }); const client = new Client({ name: 'health-check', version: '1.0.0' }, { capabilities: {} }); await client.connect(transport); const tools = await client.listTools(); console.log(`Stitch MCP healthy: ${tools.tools.length} skills registered`); await client.close(); 

Invariant Rule

Never trust MCP tool handlers to complete within transport timeouts. Every async skill execution must be wrapped in Promise.race() with a timeout 5-10s shorter than your transport's read deadline. The stdio transport's 30s limit is implicit and non-configurable in SDK 0.5.x.

For skills executing git operations, subprocess spawns, or HTTP calls to external APIs, this is non-negotiable. The alternative is silent process death and confused on-call engineers at 2 AM.

When testing stitch-skills against Claude Code or Cursor, monitor for exit 0 events without preceding error logs—that's your canary for unhandled transport closure.