Claude代码MCP服务器

一个允许在单次运行模式下绕过权限自动执行Claude代码的模型上下文协议服务器,适用于代码生成、文件操作和复杂多步骤工作流。

  • by charles-future
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 charles-future/claude-code-mcp

使用说明

克劳德代码MCP服务器

一种MCP(模型上下文协议)服务器,允许在单次模式下运行Claude代码,并自动绕过权限。

您是否注意到Cursor有时会遇到复杂的、多步骤的编辑或操作?这台服务器,以其强大的统一 claude_code 该工具旨在使Claude成为您编码任务中更直接、更有能力的代理。

概述

此MCP服务器提供了一个LLM可以用来与Claude Code交互的工具。当与Claude Desktop或其他MCP客户端集成时,它允许LLM:

  • 绕过所有权限运行Claude代码(使用 --dangerously-skip-permissions)
  • 在没有许可中断的情况下,以任何提示执行克劳德代码
  • 直接访问文件编辑功能
  • 默认情况下启用特定工具

好处

  • Claude/Windsurf在编辑文件时经常遇到问题。Claude Code在这方面做得更好更快。
  • 多个命令可以排队,而不是直接执行。这节省了上下文空间,因此更重要的内容保留的时间更长,压缩的次数更少。
  • 文件操作、git或其他操作不需要昂贵的模型。如果您注册Antropic Max,Claude Code非常划算。您可以在Max模式下使用Gemini或o3,并通过将任务卸载到更便宜的型号来节省成本。
  • Claude有更广泛的系统访问权限,可以做Cursor/Windsurf不能做(或认为他们不能做)的事情,所以每当他们被卡住时,只要问他们“使用Claude代码”,它通常会解除他们的卡住。
  • 代理人规则中的代理人。

先决条件

  • Node.js v20或更高版本(使用fnm或nvm安装)
  • Claude CLI已在本地安装(运行它并呼叫/director) -dangerously-skip-permissions 认可的。

配置

环境变量

  • CLAUDE_CLI_NAME:覆盖Claude CLI二进制名称或提供绝对路径(默认值: claude).这允许您使用自定义的Claude CLI二进制文件。这有助于:

    • 使用自定义的Claude CLI包装器
    • 使用模拟二进制文件进行测试
    • 并行运行多个Claude CLI版本

    支持的格式:

    • 简单名称: CLAUDE_CLI_NAME=claude-custom 或 CLAUDE_CLI_NAME=claude-v2
    • 绝对路径: CLAUDE_CLI_NAME=/path/to/custom/claude

    相对路径(例如。, ./claude 或 ../claude)不允许,并将抛出错误。

    当设置为简单名称时,服务器将在以下位置查找指定的二进制文件:

    1. 系统路径(而不是默认路径 claude 命令)

    注意:本地用户安装路径(~/.claude/local/claude)仍将被选中,但仅限于默认值 claude 二元的。

  • MCP_CLAUDE_DEBUG:启用调试日志记录(设置为 true 用于详细输出)

安装与使用

建议使用此服务器的方法是使用以下命令安装它 npx.

    "claude-code-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@steipete/claude-code-mcp@latest"
      ]
    },

要使用自定义的Claude CLI二进制名称,可以指定环境变量:

    "claude-code-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@steipete/claude-code-mcp@latest"
      ],
      "env": {
        "CLAUDE_CLI_NAME": "claude-custom"
      }
    },

重要的首次设置:接受权限

在MCP服务器能够成功使用之前 claude_code 工具,您必须首先使用以下命令手动运行一次Claude CLI --dangerously-skip-permissions 标记、登录并接受条款。

这是Claude CLI的一次性要求。

npm install -g @anthropic-ai/claude-code
claude --dangerously-skip-permissions

按照提示接受。一旦完成,MCP服务器将能够非交互式地使用该标志。

macOS可能会在工具第一次运行时要求所有类型的文件夹权限,然后第一次运行失败。后续运行将正常工作。

连接到您的MCP客户端

设置服务器后,您需要配置MCP客户端(如Cursor或其他使用 mcp.json 或 mcp_config.json).

MCP配置文件

配置通常在JSON文件中完成。名称和位置可能因客户而异。

光标

光标使用 mcp.json.

  • macOS: ~/.cursor/mcp.json
  • 窗户: %APPDATA%\\Cursor\\mcp.json
  • Linux: ~/.config/cursor/mcp.json

帆板运动

Windsurf用户使用 mcp_config.json

  • macOS: ~/.codeium/windsurf/mcp_config.json
  • 窗户: %APPDATA%\\Codeium\\windsurf\\mcp_config.json
  • Linux: ~/.config/.codeium/windsurf/mcp_config.json

(注意:在某些混合设置中,如果还安装了Cursor,这些客户端可能会重新使用Cursor的 ~/.cursor/mcp.json 路径。如果使用Codeium扩展,请优先考虑Codeium特定的路径。)

如果此文件不存在,请创建它。添加或更新的配置 claude_code:

提供的工具

此服务器公开了一个主要工具:

claude_code

使用Claude Code CLI直接执行提示 --dangerously-skip-permissions.

论据:

  • prompt (string,必填):发送给Claude Code的提示。
  • options (对象,可选):
    • tools (字符串数组,可选):启用特定的Claude工具(例如。, Bash, Read, Write).默认情况下启用常用工具。

MCP请求示例:

{
  "toolName": "claude_code:claude_code",
  "arguments": {
    "prompt": "Refactor the function foo in main.py to be async."
  }
}

示例

以下是服务器运行的一些可视化示例:

修复ESLint设置

以下是一个使用Claude Code MCP工具通过删除旧配置文件并创建新配置文件来交互式修复ESLint设置的示例:

列出文件示例

下面是一个Claude Code工具列出目录中文件的示例:

关键用例

该服务器通过其统一 claude_code 该工具通过让您的AI直接访问Claude Code CLI,解锁了一系列强大的功能。以下是您可以实现的一些示例:

  1. 代码生成、分析和重构:

    • "Generate a Python script to parse CSV data and output JSON."
    • "Analyze my_script.py for potential bugs and suggest improvements."
  2. 文件系统操作(创建、读取、编辑、管理):

    • 创建文件: "Your work folder is /Users/steipete/my_project\n\nCreate a new file named 'config.yml' in the 'app/settings' directory with the following content:\nport: 8080\ndatabase: main_db"
    • 编辑文件: "Your work folder is /Users/steipete/my_project\n\nEdit file 'public/css/style.css': Add a new CSS rule at the end to make all 'h2' elements have a 'color: navy'."
    • 移动/复制/删除: "Your work folder is /Users/steipete/my_project\n\nMove the file 'report.docx' from the 'drafts' folder to the 'final_reports' folder and rename it to 'Q1_Report_Final.docx'."
  3. 版本控制(Git):

    • "Your work folder is /Users/steipete/my_project\n\n1. Stage the file 'src/main.java'.\n2. Commit the changes with the message 'feat: Implement user authentication'.\n3. Push the commit to the 'develop' branch on origin."
  4. 运行终端命令:

    • "Your work folder is /Users/steipete/my_project/frontend\n\nRun the command 'npm run build'."
    • "Open the URL https://developer.mozilla.org in my default web browser."
  5. 网络搜索和摘要:

    • "Search the web for 'benefits of server-side rendering' and provide a concise summary."
  6. 复杂的多步骤工作流:

    • 自动化版本升级、更新更新日志和标记发布: "Your work folder is /Users/steipete/my_project\n\nFollow these steps: 1. Update the version in package.json to 2.5.0. 2. Add a new section to CHANGELOG.md for version 2.5.0 with the heading '### Added' and list 'New feature X'. 3. Stage package.json and CHANGELOG.md. 4. Commit with message 'release: version 2.5.0'. 5. Push the commit. 6. Create and push a git tag v2.5.0."
  7. 修复有语法错误的文件:

    • "Your work folder is /path/to/project\n\nThe file 'src/utils/parser.js' has syntax errors after a recent complex edit that broke its structure. Please analyze it, identify the syntax errors, and correct the file to make it valid JavaScript again, ensuring the original logic is preserved as much as possible."
  8. 与GitHub交互(例如,创建Pull请求):

    • "Your work folder is /Users/steipete/my_project\n\nCreate a GitHub Pull Request in the repository 'owner/repo' from the 'feature-branch' to the 'main' branch. Title: 'feat: Implement new login flow'. Body: 'This PR adds a new and improved login experience for users.'"
  9. 与GitHub交互(例如,检查PR CI状态):

    • "Your work folder is /Users/steipete/my_project\n\nCheck the status of CI checks for Pull Request #42 in the GitHub repository 'owner/repo'. Report if they have passed, failed, or are still running."

更正GitHub操作工作流

复杂的多步骤操作

此示例说明 claude_code 处理更复杂、多步骤的任务,例如通过创建分支、更新多个文件来准备发布(package.json, CHANGELOG.md)提交更改和发起拉取请求,所有这些都在一个连贯的操作中完成。

关键:记住在文件系统或git操作的提示中提供当前工作目录(CWD)上下文(例如。, "Your work folder is /path/to/project\n\n...your command...").

故障排除

  • “找不到命令”(claude代码mcp): 如果全局安装,请确保npm全局bin目录在系统的PATH中。如果使用 npx,确保 npx 它本身正在工作。
  • “找不到命令”(claude或~/.claude/local/claude): 确保正确安装了Claude CLI。跑 claude/doctor 或查看其文档。
  • 权限问题: 确保您已经运行了“重要的首次设置”步骤。
  • 来自服务器的JSON错误: 如果 MCP_CLAUDE_DEBUG 是 true,错误消息或日志可能会干扰MCP的JSON解析。设为 false 正常运行。
  • ESM/导入错误: 确保您使用的是Node.js v20或更高版本。

开发者:本地设置和贡献

如果您想开发或贡献此服务器,或从克隆的存储库运行它进行测试,请参阅我们的 本地安装和开发设置指南.

测试

该项目包括全面的测试套件:

# Run all tests
npm test

# Run unit tests only
npm run test:unit

# Run e2e tests (with mocks)
npm run test:e2e

# Run e2e tests locally (requires Claude CLI)
npm run test:e2e:local

# Watch mode for development
npm run test:watch

# Coverage report
npm run test:coverage

有关详细的测试文档,请参阅我们的 E2E测试指南.

通过环境变量进行配置

服务器的行为可以使用以下环境变量进行自定义:

  • CLAUDE_CLI_PATH:Claude CLI可执行文件的绝对路径。
    • 默认值:检查 ~/.claude/local/claude,然后回落到 claude (预计在PATH中)。
  • MCP_CLAUDE_DEBUG:设置为 true 用于此MCP服务器的详细调试日志记录。违约: false.

这些可以在您的shell环境中设置,也可以在 env 你的块 mcp.json 服务器配置(尽管 env 挡住 mcp.json 为了简单起见,示例被删除了,如果需要,这仍然是为服务器进程设置示例的有效方法)。

贡献

欢迎投稿!请参阅 本地安装和开发设置指南 有关设置环境的详细信息。

向提交问题并拉取请求 GitHub存储库.

许可证

麻省理工学院