claude-code-mcp

by KunihiroS
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

claude-code-mcp 项目

更新

现在,此 MCP 服务器无需通过 npx 本地安装即可运行!!

概述

claude-code-mcp 项目是 Claude Code 的 MCP 服务器。

它调用本地安装的 Claude Code 命令,并提供以下工具: explain_codereview_codefix_codeedit_codetest_codesimulate_commandyour_own_query 。服务端使用 Node.js 和 MCP SDK 实现,通过 stdio 接收客户端的 JSON 格式请求。内部采用 Base64 编码,平滑处理自然语言文本中的特殊字符(换行符、引号等),从而提高稳定性和灵活性。其主要作用是接收请求、编码输入、生成并执行命令以及以 JSON 格式返回执行结果。本项目已确认可在 Claude Code CLI 环境(Ubuntu/WSL2 等)上运行。

💡 即使 LLM 能力稍逊,MCP Host 也能驾驭并利用 Claude 的力量💪!有了 claude-code-mcp,你还能从 Claude 桌面调用 Claude 代码!😇😜😎(未经证实)

功能

服务器的主要作用是:

  • **请求接收:**接收来自客户端的 JSON 格式的工具请求(例如codecontextfocus_areas等)。
  • **输入处理:**内部对接收到的自然语言文本进行 Base64 编码。
  • **工具选择和命令生成:**根据请求中的工具名称,使用固定模板或自由格式( your_own_query )为查询组装命令字符串。
  • **命令执行:**使用 Node.js 的child_process.spawn执行组装的命令并从标准输出获取结果。
  • **结果返回:**将执行结果以JSON格式返回给客户端。

入门

先决条件

安装与使用

有几种使用claude-code-mcp方法:

1. 使用 npx(推荐快速使用)

您可以使用npx直接运行服务器而无需安装:

npx @kunihiros/claude-code-mcp

2.全局安装

全局安装包:

npm install -g claude-code-mcp

然后,您可以将其作为命令运行:

claude-code-mcp

3. 本地安装(用于开发)

克隆存储库并安装依赖项:

git clone https://github.com/KunihiroS/claude-code-mcp.git cd claude-code-mcp/claude-code-server npm install npm run build

然后您可以直接运行构建的脚本:

node build/index.js

配置

环境变量:

无论采用哪种安装方式,都需要配置环境变量。创建以下文件之一

  1. **使用 MCP 主机设置(推荐用于npx ):**直接在 MCP 主机的设置中配置环境变量(请参阅下文的“MCP 主机配置”)。这是使用npx时最简单的方法。
  2. **使用.env文件:**在运行npx @kunihiros/claude-code-mcp命令的目录中创建一个.env文件。
  3. **使用全局配置文件:**在您的主目录( ~/.claude-code-mcp.env )中创建一个.claude-code-mcp.env文件。

如果使用文件( .env~/.claude-code-mcp.env ),请添加以下内容,调整CLAUDE_BIN路径:

# .env or ~/.claude-code-mcp.env CLAUDE_BIN=/path/to/your/claude/executable # REQUIRED: Set the full path to your Claude CLI LOG_LEVEL=info # Optional: Set log level (e.g., debug, info, warn, error)

MCP 主机配置(推荐用于npx ):

将以下内容添加到您的 MCP Host 应用程序设置(例如,Claude Desktop 设置)。此方法允许您直接设置环境变量。

"claude-code-server": { "command": "npx", "args": [ "-y", "@kunihiros/claude-code-mcp" ], "env": { "CLAUDE_BIN": "/path/to/your/claude/executable", // REQUIRED: Set the absolute path "LOG_LEVEL": "info" // Optional: Set log level }, "disabled": false }

(可能需要重新启动主机应用程序。)

备选 MCP 主机配置(全局安装 / 本地开发):

如果您全局安装了该包或从克隆的存储库本地运行它,并且claude-code-mcp命令位于系统的 PATH 中,则可以使用:

"claude-code-server": { "command": "claude-code-mcp", "disabled": false }

在这种情况下,您必须使用.env文件或全局~/.claude-code-mcp.env文件配置环境变量,如上所述。

环境变量详细信息

该服务器使用以下环境变量(通过 MCP Host env设置、 .env~/.claude-code-mcp.env设置):

  • CLAUDE_BIN :指定 Claude CLI 可执行文件的路径。 **(必需)**例如: /home/linuxbrew/.linuxbrew/bin/claudeC:\Users\YourUser\AppData\Local\bin\claude.exe
  • LOG_LEVEL :指定日志级别。(可选,默认为info )。可能的值: debuginfowarnerror

可用工具

claude-code-mcp服务器提供以下工具:

  • explain_code :提供给定代码的详细解释。
  • review_code :审查给定的代码。
  • fix_code :修复给定代码中的错误或问题。
  • edit_code :根据指令编辑给定的代码。
  • test_code :为给定的代码生成测试。
  • simulate_command :模拟给定命令的执行。
  • your_own_query :发送带有上下文的自定义查询。

笔记

  • 日志文件( claude-code-mcp.log )位置:
    • 首先尝试在项目根目录中创建。
    • 回退到用户的主目录( ~/.claude-code-mcp.log )。
    • 最后回到/tmp/claude-code-mcp.log
  • 日志轮换尚未实现(注意日志文件的大小)。
  • 主要在 Ubuntu/WSL2 上使用 Claude CLI 进行测试。

执照

该项目根据 MIT 许可证获得许可 - 详情请见下文。

MIT License Copyright (c) 2024 KunihiroS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

免责声明

本软件仅供教育和研究之用。本项目与 Anthropic 无正式关联,亦未获得其认可。Claude 是 Anthropic 的商标。

该项目依赖 Claude CLI,但其本身是一个独立的、由社区驱动的项目。用户在使用本项目时应确保遵守 Anthropic 的服务条款。

本项目的维护者对任何软件的误用或任何第三方 API 或服务的服务条款的违反不承担任何责任。

-
security - not tested
A
license - permissive license
-
quality - not tested

本项目旨在构建一个 Claude Code MCP 服务器并实现其相关工具(explain_code、review_code、fix_code、edit_code、test_code、simulate_command 和 your_own_query)。该服务器使用 Node.js 和 MCP SDK 实现。它通过 Stdio 动态接收来自客户端的工具请求。

  1. Update
    1. Overview
      1. Functions
        1. Getting Started
          1. Prerequisites
          2. Installation & Usage
          3. Configuration
        2. Environment Variables Details
          1. Available Tools
            1. Note
              1. License
                1. Disclaimer
                  ID: 9dj2mvzg31