zai-org / zai-org/feedback

[Bug] stdio MCP server 全链路正常(进程运行/握手成功/UI 显示 27 工具)但会话工具列表未注入

Open
#194 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

已搜索 #107(args 含空格解析)、#139(enable/enabled 字段冲突)、#150(HTTP fetch failed)等 MCP 相关 issue,均与本问题不同:本 issue 的核心是 stdio MCP server 全链路正常(进程运行、stdio 通道连接、tools/list 返回 27 工具、UI 显示 connected),但会话工具列表未注入,与 args 解析、enable 字段、HTTP 连接均无关。

问题类别 · Category

工具调用 / MCP · Tool use / MCP

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻断 · Blocker(自定义 stdio MCP server 完全无法在会话中使用)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

在 ZCode 桌面客户端配置一个自定义 stdio MCP server(基于 FastMCP 3.0.2 的 Python 服务)。该 server 的连接、握手、工具注册在所有技术层面均正常,但工具始终未被注入到会话可用工具列表,AI 在会话内完全无法调用。

关键矛盾点:Settings → MCP UI 显示该 server 为 "connected" 且能列出 27 个工具,但会话内 AI 的工具列表中不存在任何该 server 的工具mcp__fairygui-tools__* 缺失)。同时,ZCode 内置 MCP(mcp__4_5v_mcp__mcp__node_repl__mcp__web_reader__)正常可用。

日志层面,每次 session/resume 都报告 "mcpServerCount":0, "mcpServerNames":[],但内置 MCP 同样不被计入此字段却能正常使用,因此该字段的语义存疑,无法作为判断依据。

复现步骤 · Steps to reproduce
  1. 准备一个自定义 stdio MCP server(本例为 FastMCP 3.0.2 实现的 FairyGUI 编辑器自动化工具,27 个工具)。
  2. 在 Settings → MCP 新建一个 MCP server,作用域分别尝试 工作区用户
    • 类型:stdio
    • 命令:python
    • 参数:-c "<一段含空格和分号的 Python 内联脚本>"
  3. 确认列表中该 server 状态为 connected,且显示 27 个工具。
  4. 新建会话(在添加 MCP 之后)。
  5. 让 AI 列出可用的 mcp__fairygui-tools__* 工具 —— 结果为空。
期望表现 · Expected behavior

会话创建后,该 server 的 27 个工具应出现在 AI 的可用工具列表中(形如 mcp__fairygui-tools__fg_list_packages),与内置 MCP 一样可被调用。

实际表现 · Actual behavior

AI 会话内工具列表只有 3 组内置 MCP(mcp__4_5v_mcp__mcp__node_repl__mcp__web_reader__),自定义 stdio MCP 的工具完全不出现。

诊断证据 · Diagnostic evidence

以下证据表明 server 在所有技术环节均正常,问题出在 ZCode 客户端"已连接 MCP → 会话工具注入"这一内部环节:

① MCP server 进程正常运行,stdio 通道连接正确

PID 58828 (python.exe) — fairygui MCP server
  ↑ parent
PID 92112 (ZCode.exe, "app-server --stdio")
  ↑ parent
PID 75004 (ZCode.exe)
  ↑ parent
PID 92888 (ZCode.exe, 主进程)

进程命令行完整正确(单条 -c 脚本字符串),进程启动后保持运行(内存约 140MB,CPU 约 1s,表明完成握手后空闲等待请求)。

② 手动对 server 进程发 MCP 协议握手,完全正常
通过 stdio 向 server 发送标准 initialize + notifications/initialized + tools/list,server 正确返回:

{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","serverInfo":{"name":"fairygui-tools","version":"3.0.2"}}}
{"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"fg_list_packages",...}, ...共 27 个工具]}}

③ Settings → MCP UI 显示 connected + 27 工具(用户确认)

④ 但日志 session/resume 始终报告 mcpServerCount: 0

[session/resume] {"mcpServerCount":0,"mcpServerNames":[],...}

注:内置 MCP(node_repl 等)也不被计入 mcpServerCount,但它们能正常使用,所以该字段语义不明。

⑤ 作用域已尝试"工作区"和"用户"两种,问题一致

  • 工作区级:配置文件 <workspace>/.zcode/config.json(此处 .zcode 是指向 .claude 的符号链接,疑似相关)
  • 用户级:配置文件 ~/.zcode/cli/config.json
    两种作用域下,server 进程都正常启动、UI 都显示 connected+27 工具,但会话工具都不注入。
已排除的假设 · Ruled out causes
假设 排除依据
server 起不来 / crash 进程正常运行,手动握手成功
args 被 UI 按空格拆分(#107) 配置文件里确实被拆分,但 ZCode spawn 时重新合并,进程实际命令行是正确的单条字符串
enable:false 停用(#139) 配置里无 enable 字段;且尝试用户级/工作区级均如此
cwd 错误导致 server 找不到项目根 进程命令行正确,手动握手返回正确工具
会话创建早于 MCP 连接(时序问题) 已确认"先添加 MCP、确认 connected 后再新建会话",顺序正确
工程级符号链接导致加载失败 改为用户级(~/.zcode/cli/config.json,无符号链接)后问题依旧
ZCode 版本 · ZCode version

3.5.2.3869

设备 / 系统 · Device / OS

Windows 11 企业版 10.0.26200 (x64)

附注 · Notes
  • 内置 MCP(mcp__4_5v_mcp__mcp__node_repl__mcp__web_reader__)的配置在所有配置文件、插件 manifest 中均找不到,疑似 ZCode 客户端硬编码内置,走与配置文件 MCP 不同的注入通道。若如此,希望官方文档能说明"内置/插件 MCP"与"配置文件 MCP"在工具注入上的差异,以及为何后者会失败。
  • 该问题导致所有自定义 stdio MCP server 无法使用,影响面较大。盼官方排查"host 层 MCP 连接成功 → 会话工具注入"这条链路在 stdio + 配置文件场景下的断点。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the configured stdio MCP path with the built-in MCP path, using the Settings → MCP state and session/resume logs as evidence. Inspect MCP configuration loading for /.zcode/config.json and ~/.zcode/cli/config.json, then trace where connected servers are added to a new session. Done means the configured server's 27 tools appear in the session tool list and can be called.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.