claude-code-mcp
by: KunihiroS
MCP Server connects with claude code local command.
📌Overview
Purpose: The claude-code-mcp project serves as a versatile MCP server for interacting with Claude Code, enabling users to execute various coding tasks seamlessly.
Overview: The claude-code-mcp project is built on Node.js and the MCP SDK, facilitating communication between clients and the Claude Code command-line interface. It efficiently handles requests, processes natural language input using Base64 encoding, and returns results in a structured JSON format. Compatible with various environments, it enhances code generation and management tasks by leveraging Claude's capabilities.
Key Features:
-
Request Reception: Accepts JSON formatted tool requests from clients, allowing for dynamic interaction based on user needs.
-
Tool Selection and Command Generation: Assembles commands based on specified tools, providing flexibility for users to utilize predefined or custom queries in their requests.
claude-code-mcp Project
Update
Now this MCP Server works without local install by npx!!
Overview
The claude-code-mcp project is an MCP server for Claude Code.
It calls the locally installed Claude Code command and provides the following tools: explain_code
, review_code
, fix_code
, edit_code
, test_code
, simulate_command
, and your_own_query
. The server is implemented using Node.js and the MCP SDK, receiving JSON format requests from clients via stdio. Internally, it uses Base64 encoding to handle special characters in natural language text, improving stability and flexibility. Its main roles are receiving requests, encoding input, generating and executing commands, and returning results in JSON format.
This project has been confirmed to work in Claude Code CLI environments (Ubuntu/WSL2, etc.).
Functions
The main roles of the server are:
- Request Reception: Receive JSON format tool requests from clients (e.g.
code
,context
,focus_areas
, etc.). - Input Processing: Base64 encode the received natural language text.
- Tool Selection and Command Generation: Assemble a command string for the query based on the tool name using a fixed template or free format (
your_own_query
). - Command Execution: Use Node.js's
child_process.spawn
to execute the command and get the result. - Result Return: Return the execution result in JSON format.
Getting Started
Prerequisites
- Node.js (>= v18 recommended, tested with v22.14.0)
- npm (or yarn)
- Claude Code command installed and auth completed. See the official Claude Code documentation for details.
Installation & Usage
There are several ways to use claude-code-mcp
:
1. Using npx (Recommended for quick use)
Run the server directly without installation using npx
:
npx @kunihiros/claude-code-mcp
2. Global Installation
Install the package globally:
npm install -g claude-code-mcp
Then run it as a command:
claude-code-mcp
3. Local Installation (For development)
Clone the repository and install dependencies:
git clone https://github.com/KunihiroS/claude-code-mcp.git
cd claude-code-mcp/claude-code-server
npm install
npm run build
Run the built script directly:
node build/index.js
Configuration
Environment Variables:
Configure one of the following for environment variables:
- Configure environment variables in your MCP Host's settings (recommended for
npx
). - Create a
.env
file in the directory where you run the command. - Create a
.claude-code-mcp.env
file in your home directory (~/.claude-code-mcp.env
).
Example environment variables content:
CLAUDE_BIN=/path/to/your/claude/executable # REQUIRED: full path to Claude CLI
LOG_LEVEL=info # Optional: log level (debug, info, warn, error)
MCP Host Configuration (Recommended for npx
):
Add this configuration in your MCP Host application settings to run with npx
:
"claude-code-server": {
"command": "npx",
"args": [
"-y",
"@kunihiros/claude-code-mcp"
],
"env": {
"CLAUDE_BIN": "/path/to/your/claude/executable",
"LOG_LEVEL": "info"
},
"disabled": false
}
Alternative MCP Host Configuration (Global Install / Local Dev):
If installed globally or running locally and claude-code-mcp
is in PATH, use:
"claude-code-server": {
"command": "claude-code-mcp",
"disabled": false
}
In this case, configure environment variables via .env
file or ~/.claude-code-mcp.env
.
Environment Variables Details
CLAUDE_BIN
(Required): Path to the Claude CLI executable.LOG_LEVEL
(Optional): log level, defaults toinfo
. Options:debug
,info
,warn
,error
.
Available Tools
explain_code
: Provides a detailed explanation of the given code.review_code
: Reviews the given code.fix_code
: Fixes bugs or issues in the given code.edit_code
: Edits the given code based on instructions.test_code
: Generates tests for the given code.simulate_command
: Simulates the execution of a given command.your_own_query
: Sends a custom query with context.
Notes
- Log file (
claude-code-mcp.log
) attempts creation in the following order: project root, user home (~/.claude-code-mcp.log
), then/tmp/claude-code-mcp.log
. - Log rotation is not implemented; monitor log file size.
- Primarily tested with Claude CLI on Ubuntu/WSL2.
License
MIT License
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.
Disclaimer
This software is provided for educational and research purposes only. This project is not officially associated with or endorsed by Anthropic. Claude is a trademark of Anthropic.
This project uses the Claude CLI as a dependency but is an independent, community-driven effort. Users should ensure compliance with Anthropic's terms of service when using this project.
The maintainers are not responsible for misuse or violations of third-party terms.