Coding Tools MCP
使用指南

Exec command 实用配方

前台、后台与交互式命令的常见使用模式。

这些示例刻意使用显式 exec_command。MCP server 不会猜项目类型、自动安装依赖,也不会替你决定 package manager cache policy。

前台与后台结果

Server 始终暴露同样四个 process tool:exec_command、write_stdin、read_output 和 kill_command。命令启动后不会动态新增 tool。

exec_command 默认最多等待 10 秒。如果命令在此期间退出,结果就是完整结果,不需要额外 polling。如果命令仍在运行,返回值会包含 command_id 和精确的 next_action:

{
  "status": "running",
  "command_id": "cmd_123",
  "next_action": {
    "tool": "write_stdin",
    "arguments": {
      "command_id": "cmd_123",
      "chars": "",
      "yield_time_ms": 10000
    }
  }
}

使用空 chars 调用 write_stdin 表示“等待 / poll”;非空 chars 用于与进程交互。read_output 用于读取被保留的 stdout/stderr,主要用于结果明确提示 output truncated,或你请求了 compact verbosity 的情况。它不是每个命令都必须执行的额外步骤。

相对路径始终相对于 workspace root 解析。如果命令必须在其他目录运行,请显式传 workdir。

需要依赖 cache、但又不希望在 Git worktree 中产生缓存文件时,使用 server_info 返回的外部 runtime HOME、TMPDIR 或 cache_dir。下面示例使用环境变量 expansion,因此假定 server 运行在 trusted mode:

MAVEN_USER_HOME="$HOME/.cache/m2" mvn test
GRADLE_USER_HOME="$HOME/.cache/gradle" ./gradlew test
npm_config_cache="$HOME/.cache/npm" npm ci && npm test
PIP_CACHE_DIR="$HOME/.cache/pip" python -m pip install -r requirements.txt && python -m pytest
GOCACHE="$HOME/.cache/go-build" GOMODCACHE="$HOME/.cache/go-mod" go test ./...
CARGO_HOME="$HOME/.cache/cargo" cargo test
cmake -S . -B "$TMPDIR/cmake-build" && cmake --build "$TMPDIR/cmake-build" && ctest --test-dir "$TMPDIR/cmake-build"

基础工具链探测:

java -version
javac -version
mvn -version
gcc --version
g++ --version
make --version
cmake --version
node --version
npm --version
python --version
pip --version
go version
cargo --version
rustc --version

依赖安装需要网络时,建议直接使用:

coding-tools-mcp --permission-mode trusted --workspace /path/to/repo

本页目录