{"slug": "notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool", "title": "Notes from a 2 AM On-Call: Why Our Stitch MCP Server Died Silently on Tool Timeouts", "summary": "A developer traced a silent 2:14 AM failure of the stitch-skills MCP server to an implicit 30-second read timeout in the @modelcontextprotocol/sdk stdio transport (0.5.x), which closed the pipe mid-execution and triggered an unhandled SIGPIPE that Node.js handled with a clean exit(0). Because the transport exposes no timeout configuration, the fix wraps tool handlers in a Promise.race with a 25-second skill timeout and registers a SIGPIPE handler that exits non-zero for monitoring.", "body_md": "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.\n\nThe raw symptom:\n\n```\n[claude-code] Error: MCP server connection lost (code: 0)\n[stitch-skills] (no output, clean exit)\n[docker stats] stitch-skills container: 137 (OOMKilled? No.)\n```\n\nNo OOM. No segfault. Just a graceful suicide.\n\nEvery MCP tutorial tells you to wrap tool handlers in try-catch. We did:\n\n```\n// What the docs recommend\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n  try {\n    const result = await executeSkill(request.params.name, request.params.arguments);\n    return { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n  } catch (error) {\n    return { content: [{ type: \"text\", text: `Error: ${error.message}` }], isError: true };\n  }\n});\n```\n\nThis 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.\n\nWhat 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)`.\n\nNo exception. No stderr. Silent death.\n\nThe `@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.\n\nThe 3-line fix:\n\n```\n// server.ts - Add at the top of your Stitch MCP server entrypoint\nprocess.on('SIGPIPE', () => {\n  console.error('[SIGPIPE] Transport closed mid-execution, graceful shutdown');\n  process.exit(1); // Non-zero for monitoring\n});\n\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n  const SKILL_TIMEOUT_MS = 25000; // Under transport's 30s limit\n  try {\n    const result = await Promise.race([\n      executeSkill(request.params.name, request.params.arguments),\n      new Promise((_, reject) => \n        setTimeout(() => reject(new Error('Skill timeout')), SKILL_TIMEOUT_MS)\n      )\n    ]);\n    return { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n  } catch (error) {\n    console.error(`[tool:${request.params.name}] ${error.message}`);\n    return { \n      content: [{ type: \"text\", text: `Execution failed: ${error.message}` }], \n      isError: true \n    };\n  }\n});\n```\n\n**Key changes:**\n\n`Promise.race()` enforces a 25s skill timeout, guaranteeing handler completion before transport timeout.\nWhen integrating `stitch-skills` with Claude Code, add monitoring to your `claude_desktop_config.json`:\n\n```\n{\n  \"mcpServers\": {\n    \"stitch\": {\n      \"command\": \"node\",\n      \"args\": [\"/path/to/stitch-skills/dist/server.js\"],\n      \"env\": {\n        \"NODE_OPTIONS\": \"--max-old-space-size=512\",\n        \"SKILL_TIMEOUT_MS\": \"25000\"\n      }\n    }\n  }\n}\n```\n\nFor 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:\n\n``` js\n// health-check.ts\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\n\nconst transport = new StdioClientTransport({\n  command: 'node',\n  args: ['./dist/server.js']\n});\n\nconst client = new Client({ name: 'health-check', version: '1.0.0' }, { capabilities: {} });\n\nawait client.connect(transport);\nconst tools = await client.listTools();\nconsole.log(`Stitch MCP healthy: ${tools.tools.length} skills registered`);\nawait client.close();\n```\n\n**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.\n\nFor 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.\n\nWhen 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.", "url": "https://wpnews.pro/news/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool", "canonical_source": "https://dev.to/lucas_vance/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool-timeouts-2l2b", "published_at": "2026-11-16 20:44:56+00:00", "updated_at": "2026-11-16 20:51:28.798432+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools", "mlops"], "entities": ["Claude Code", "@modelcontextprotocol/sdk", "stitch-skills", "Node.js", "B-Lost"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool", "markdown": "https://wpnews.pro/news/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool.md", "text": "https://wpnews.pro/news/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool.txt", "jsonld": "https://wpnews.pro/news/notes-from-a-2-am-on-call-why-our-stitch-mcp-server-died-silently-on-tool.jsonld"}}