Skip to content

[BUG] 30-second timeout causes MCP server connections to fail #2

@arisgrout

Description

@arisgrout

Describe the bug

The mcp-code-wrapper has a hardcoded 30-second timeout that causes connections to some HTTP-based MCP servers to fail during tool extraction. When the server takes longer than 30 seconds to respond, the connection times out with Error: Request timeout, preventing successful MCP server integration.

Steps to reproduce

  1. Create .mcp.json with an HTTP-based MCP server configuration (see MCP Configuration below)
  2. Run command: bunx mcp-code-wrapper .
  3. Select the affected MCP servers from the list
  4. Observe error during tool extraction: Error: Request timeout

Expected behavior

The wrapper should:

  1. Support longer timeouts for slower MCP servers
  2. Provide a configurable timeout option via CLI flags
  3. Have a more reasonable default timeout (e.g., 120 seconds)

Actual behavior

The connection fails after exactly 30 seconds with:

Error: Request timeout
    at Timeout._onTimeout (file:///tmp/bunx-1000-mcp-code-wrapper@latest/node_modules/mcp-code-wrapper/dist/executor.js:110:28)

Environment

  • OS: Linux (Fedora 43)
  • Node version: 25.5.0
  • Package version: mcp-code-wrapper@0.1.0-beta.38

MCP Configuration

{
  "mcpServers": {
    "web-search-prime": {
      "type": "stdio",
      "command": "bunx",
      "args": [
        "@z_ai/mcp-server",
        "--server",
        "https://api.z.ai/api/mcp/web_search_prime/mcp"
      ],
      "env": {
        "Z_AI_API_KEY": "${ZAI_API_KEY}",
        "Z_AI_MODE": "ZAI"
      }
    }
  }
}

Additional context

Root Cause:

In three files, the timeout is hardcoded to 30000ms (30 seconds):

executor.js (line 142-112):

// Timeout after 30s
setTimeout(() => {
  if (this.pendingRequests.has(id)) {
    this.pendingRequests.delete(id);
    reject(new Error('Request timeout'));
  }
}, 30000);

runtime-executor.js (line 107-85):

setTimeout(() => {
  if (this.pendingRequests.has(id)) {
    this.pendingRequests.delete(id);
    reject(new Error(`Request timeout: ${method}`));
  }
}, 30000);

generator.js (line 116-121):

setTimeout(() => {
  if (this.pendingRequests.has(id)) {
    this.pendingRequests.delete(id);
    reject(new Error(`Request timeout: ${method}`));
  }
}, 30000);

Suggested Fix:

  1. Make timeout configurable: Add CLI flag --timeout <ms> to allow users to specify custom timeout values
  2. Increase default timeout: Change default from 30s to 120s for better compatibility with slower servers
  3. Add timeout constants: Define timeout in one place and reuse across files to avoid inconsistency

Workaround:

Manually patch the three files in /tmp/bunx-1000-mcp-code-wrapper@latest/node_modules/mcp-code-wrapper/dist/ to increase timeout from 30000ms to 120000ms (120 seconds):

sed -i 's/}, 30000);/}, 120000);/g' \
  /tmp/bunx-1000-mcp-code-wrapper@latest/node_modules/mcp-code-wrapper/dist/executor.js \
  /tmp/bunx-1000-mcp-code-wrapper@latest/node_modules/mcp-code-wrapper/dist/runtime-executor.js \
  /tmp/bunx-1000-mcp-code-wrapper@latest/node_modules/mcp-code-wrapper/dist/generator.js

Note:

The @z_ai/mcp-server --server <url> flag internally handles HTTP-to-stdio conversion, so no external bridging tool is required. Refer to #1 for details regarding refusal to run using http transfer protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions