jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Bug: MCP tools registered but fail to execute with "Failed to send request"

Open lumenfield opened this issue 3 months ago • 1 comments

Bug Report: MCP tools registered but fail to execute with "Failed to send request"

Environment

  • jcode version: v0.79.1
  • OS: Linux x86_64
  • MCP Server: stos-mcp (custom STOS system MCP server)
  • Issue Type: MCP stdio connection failure

Problem Description

After adding a new MCP tool (self_repair) to the stos-mcp server, all MCP tools show as connected in jcode's tool list, but any tool call fails with:

Error: Failed to send request

The MCP server binary works correctly when tested manually via stdio, but jcode cannot maintain the connection.

Root Cause Analysis

1. Manual Test - SUCCESS

$ echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"self_repair","arguments":{}}}' | /mnt/data/STTT/stos/target/release/stos-mcp
{"jsonrpc":"2.0","id":1,"result":{"content":[{"text":"修复完成:共0项\n[]","type":"text"}],"isError":false}}

The MCP server responds correctly and returns valid JSON-RPC responses.

2. jcode Test - FAILURE

All tool calls return "Failed to send request" error immediately.

3. Zombie Process Issue

Multiple stos-mcp processes accumulate as zombies (defunct state):

ai 9586 0.0 0.0 0 0 ? Z 08:40 [stos-mcp] <defunct>
ai 9887 0.0 0.0 0 0 ? Z 08:41 [stos-mcp] <defunct>

This indicates jcode's MCP manager is not properly reaping child processes after they exit.

4. Schema Cache Mismatch

The mcp-schema-cache.json becomes stale when the MCP server binary is updated:

  • Old fingerprint: 16c73549c40dffa9
  • New binary hash: ee726ee69bf2c149bbcaccc23a131422

After clearing the cache and reconnecting, the tool list updates correctly (38 tools), but execution still fails.

Reproduction Steps

  1. Build stos-mcp with new self_repair tool:

    cd /mnt/data/STTT/stos
    cargo build --release --package stos-mcp
    
  2. Configure in ~/.jcode/mcp.json:

    {
      "mcpServers": {
        "stos-mcp": {
          "command": "/mnt/data/STTT/stos/target/release/stos-mcp",
          "args": [],
          "env": {},
          "shared": true
        }
      }
    }
    
  3. Connect to MCP server via jcode:

    mcp action=connect server=stos-mcp
    
  4. Tool list shows 38 tools including self_repair ✓

  5. Any tool call fails with "Failed to send request" ✗

Expected Behavior

  • MCP tools should be callable after registration
  • No zombie processes should accumulate
  • Schema cache should be invalidated when binary changes

Actual Behavior

  • Tool list displays correctly from cache
  • Tool execution fails immediately
  • Multiple zombie processes created
  • No error logs in stos-mcp stderr

Impact

  • All STOS MCP tools are unusable
  • System health monitoring blocked
  • Cell repair system (细胞修复) cannot be verified
  • 12-life-system health checks unavailable

Code Changes Made

1. New file: stos-mcp/src/self_repair_tools.rs

pub fn register_self_repair_tools(registry: &mut ToolRegistry, ctx: Arc<StosContext>) {
    let def = McpToolDef {
        name: "self_repair".into(),
        description: Some("执行信念库自我修复:权重越界修复、悬空引用清理、status清理".into()),
        input_schema: serde_json::json!({"type": "object", "properties": {}}),
    };
    // ... handler implementation
}

2. Modified: stos-mcp/src/main.rs

  • Added mod self_repair_tools;
  • Added registration call in main()

Suggestions

  1. For jcode: Add proper child process reaping in MCP manager
  2. For jcode: Invalidate schema cache on binary change detection
  3. For jcode: Add timeout and retry logic for stdio connections
  4. For stos-mcp: Add startup logging to diagnose silent failures

Related Issues

  • Issue with stdio stdio pipe management in jcode's MCP implementation
  • Need to verify if this affects all custom MCP servers or just stos-mcp

Attachments

  • stos-mcp source: /mnt/data/STTT/stos/stos-mcp/src/
  • Work records: /mnt/data/STTT/工作台/合参纪要/合参070_mcp故障排查/
  • Binary: /mnt/data/STTT/stos/target/release/stos-mcp (8.9MB)

lumenfield avatar Aug 23 '26 00:08 lumenfield

Thanks for the detailed report. The one-shot echo | stos-mcp check does not exercise MCP initialization or a long-lived stdio session, so we need a little more evidence to locate where the child exits.

Could you attach a redacted jcode log covering mcp connect through one failed tool call, plus the server's stderr/exit status from that same run? Please also confirm whether the server handles the MCP initialize/notifications/initialized handshake and remains alive after responding. If possible, reproduce with shared: false to show whether shared-process reuse is involved.

--- — Jcode agent (automated triage), on behalf of @1jehuang

1jehuang avatar Aug 24 '26 07:08 1jehuang