Skip to content

feat: implement MCP tool calling in REPL with Windows support#26

Open
coolinger2019-wq wants to merge 1 commit intolorryjovens-hub:workingfrom
coolinger2019-wq:feature/mcp-tool-calling
Open

feat: implement MCP tool calling in REPL with Windows support#26
coolinger2019-wq wants to merge 1 commit intolorryjovens-hub:workingfrom
coolinger2019-wq:feature/mcp-tool-calling

Conversation

@coolinger2019-wq
Copy link
Copy Markdown

Summary

实现了 REPL 中的 MCP 工具调用功能,使 AI 能够调用内置工具执行文件操作、命令执行等任务。同时修复了 Windows
平台兼容性问题。

Changes

1. MCP 命令改进

  • mcp addcommand 参数改为可选,支持只用 --path
  • 特殊处理 filesystem 工具,自动标记为 running 并注入能力

2. REPL 工具调用支持

  • 加载内置工具定义(file_read, file_write, execute_command, search
  • 注入 tools 到 API 请求
  • 处理 AI 返回的 tool_calls 响应
  • 实现工具执行循环,支持多轮工具调用

3. Windows 平台兼容

  • execute_command 工具:Windows 用 cmd /C,Unix 用 sh -c
  • search 工具:Windows 用 findstr,Unix 用 rggrep

4. UI 优化

  • 修复用户输入重复显示问题
  • 优化 typing indicator 动画

5. 代码清理

  • 消除未使用变量/导入的编译警告

Test Plan

  • claude-code mcp add filesystem --path "D:\xxx" 正常工作
  • claude-code mcp list 显示 filesystem (running)
  • REPL 中 AI 能够调用 execute_command 执行命令
  • REPL 中 AI 能够调用 file_read 读取文件
  • Windows 上命令执行正常(cmd /C
  • 无编译错误和警告

Files Changed

  • src/cli/mod.rs - MCP 命令参数定义
  • src/cli/args.rs - MCP 命令处理逻辑
  • src/cli/repl.rs - REPL 工具调用实现
  • src/cli/ui.rs - UI 显示修复
  • src/mcp/tools.rs - Windows 兼容性
  • src/mcp/mod.rs - filesystem 内置工具处理
  • src/config/mcp_config.rs - 配置结构修复

- Add tool definition injection to API requests in REPL
- Implement tool_calls response handling and execution loop
- Support filesystem as built-in MCP tool (no external process needed)
- Make mcp add command parameter optional, support --path only usage
- Fix command execution on Windows (use cmd /C instead of sh -c)
- Fix search tool on Windows (use findstr instead of rg)
- Fix UI duplicate user input display
- Clean up unused variable/import warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant