Skip to content

SteerText codegraph tool names don't match actual MCP-prefixed names (causing 'unknown tool' errors) #4111

@ttmouse

Description

@ttmouse

问题描述

internal/codegraph/codegraph.go 中的 SteerText 常量用短名(如 codegraph_context)来文档化 codegraph 工具,但实际注册到工具注册表中的是 MCP 命名空间名(如 mcp__codegraph__codegraph_context)。

这意味着系统提示(system prompt)告诉模型去调用 codegraph_context,但实际可用的工具名为 mcp__codegraph__codegraph_context。模型如果按提示尝试调用短名,会收到 "unknown tool" 错误。

根因分析

  1. SteerText 路径: internal/codegraph/codegraph.go:33-41

    • 使用短名:codegraph_context, codegraph_search, codegraph_callers / codegraph_callees, 等
    • 不完整:遗漏了 codegraph_explore, codegraph_node, codegraph_status
  2. 实际注册名: MCP 插件按 mcp__<server>__<tool> 格式命名

    • plugin.ToolPrefix("codegraph") → mcp__codegraph__
    • 实际名称如 mcp__codegraph__codegraph_context
  3. 注入逻辑: internal/boot/boot.go:346-362

    • prefix := plugin.ToolPrefix("codegraph") 用于过滤工具列表
    • 但注入的 SteerText 用的是不带前缀的短名

影响

  • 模型调用 codegraph 工具时可能失败,因为提示中的名字和实际注册名不匹配
  • 新接触 Code Intelligence 功能的模型更容易被误导
  • 遗漏的工具列表让模型不知道 codegraph_explore, codegraph_node 等工具的存在

建议修复

有两种方向(需要决定):

方案 A: SteerText 使用 MCP 全名

  • codegraph_context 改为 mcp__codegraph__codegraph_context
  • 优点:与注册名完全一致
  • 缺点:名字冗长,可读性差

方案 B: 利用 StripRawPrefix 清除冗余前缀

  • internal/boot/boot.go:257 已设 StripRawPrefix: "codegraph_",但实际注册名 mcp__codegraph__codegraph_* 表明该功能未生效(名字中 codegraph_ 出现了两次)
  • 修复 StripRawPrefix 后,名称应为 mcp__codegraph__context
  • SteerText 可改用去掉 codegraph_ 前缀的名称
  • 但 SteerText 是在编译时确定的静态字符串,无法动态感知 StripRawPrefix 的实际效果

方案 C: 让 SteerText 动态生成,从注册表中提取实际工具名列表

当前会话中的实际工具名(供验证)

mcp__codegraph__codegraph_callees
mcp__codegraph__codegraph_callers
mcp__codegraph__codegraph_context
mcp__codegraph__codegraph_explore
mcp__codegraph__codegraph_files
mcp__codegraph__codegraph_impact
mcp__codegraph__codegraph_node
mcp__codegraph__codegraph_search
mcp__codegraph__codegraph_status
mcp__codegraph__codegraph_trace

参考代码位置

  • internal/codegraph/codegraph.go:31-41 — SteerText 常量
  • internal/boot/boot.go:255-258 — StripRawPrefix 配置
  • internal/boot/boot.go:346-362 — SteerText 注入逻辑
  • internal/plugin/plugin.go:840-850 — toolName / ToolPrefix 生成
  • internal/plugin/plugin.go:822-828 — StripRawPrefix 应用(eager 路径)
  • internal/plugin/lazy.go:264-270 — StripRawPrefix 应用(lazy 路径)

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentCore agent loop (internal/agent, internal/control)mcpMCP servers / plugins (internal/plugin, codegraph)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions