# Directory Structure ``` ├── .gitignore ├── claude-code-server │ ├── .env.example │ ├── build │ │ └── index.js │ ├── package-lock.json │ ├── src │ │ ├── declarations.d.ts │ │ └── index.ts │ └── tsconfig.json ├── Dockerfile ├── LICENSE ├── package.json ├── pnpm-lock.yaml └── README.md ``` # Files -------------------------------------------------------------------------------- /claude-code-server/.env.example: -------------------------------------------------------------------------------- ``` 1 | CLAUDE_BIN= 2 | LOG_LEVEL=info 3 | ``` -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- ``` 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- ```markdown 1 | # claude-code-mcp Project 2 | 3 | 4 | ## [0.1.6] - 2025-09-11 5 | 6 | ### Security Update 7 | - Update @anthropic-ai/claude-code version. 8 | 9 | ## Overview 10 | 11 | The claude-code-mcp project is an MCP server for Claude Code. 12 | 13 | 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 adopts Base64 encoding to smoothly process special characters (newlines, quotation marks, etc.) in natural language text, resulting in improved stability and flexibility. Its main roles are receiving requests, encoding input, generating and executing commands, and returning execution results in JSON format. 14 | This project has been confirmed to work in Claude Code CLI environments (Ubuntu/WSL2, etc.). 15 | 16 | <a href="https://glama.ai/mcp/servers/@KunihiroS/claude-code-mcp"> 17 | <img width="380" height="200" src="https://glama.ai/mcp/servers/@KunihiroS/claude-code-mcp/badge" alt="claude-code-mcp MCP server" /> 18 | </a> 19 | 20 | 💡 21 | MCP Host with less capable LLM, can tame and make use of Claude power💪! 22 | With claude-code-mcp, you can also call Claude Code from Claude Desktop!! 😇😜😎 (unconfirmed) 23 | 24 | ## Functions 25 | 26 | The main roles of the server are: 27 | 28 | - **Request Reception:** Receive JSON format tool requests from clients (e.g. `code`, `context`, `focus_areas`, etc.). 29 | - **Input Processing:** Internally Base64 encode the received natural language text. 30 | - **Tool Selection and Command Generation:** Based on the tool name in the request, assemble a command string for the query using a fixed template or free format (`your_own_query`). 31 | - **Command Execution:** Use Node.js's `child_process.spawn` to execute the assembled command and get the result from standard output. 32 | - **Result Return:** Return the execution result to the client in JSON format. 33 | 34 | ## Getting Started 35 | 36 | ### Prerequisites 37 | 38 | - Node.js (>= v18 recommended, tested with v22.14.0) 39 | - npm (or yarn) 40 | - Claude Code command installed and auth completed. 41 | https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview 42 | 43 | ### Installation & Usage 44 | 45 | There are several ways to use `claude-code-mcp`: 46 | 47 | **1. Using npx (Recommended for quick use)** 48 | 49 | You can run the server directly without installation using `npx`: 50 | 51 | ```bash 52 | npx @kunihiros/claude-code-mcp 53 | ``` 54 | 55 | **2. Global Installation** 56 | 57 | Install the package globally: 58 | 59 | ```bash 60 | npm install -g claude-code-mcp 61 | ``` 62 | 63 | Then, you can run it as a command: 64 | 65 | ```bash 66 | claude-code-mcp 67 | ``` 68 | 69 | **3. Local Installation (For development)** 70 | 71 | Clone the repository and install dependencies: 72 | 73 | ```bash 74 | git clone https://github.com/KunihiroS/claude-code-mcp.git 75 | cd claude-code-mcp/claude-code-server 76 | npm install 77 | npm run build 78 | ``` 79 | You can then run the built script directly: 80 | ```bash 81 | node build/index.js 82 | ``` 83 | 84 | ### Configuration 85 | 86 | **Environment Variables:** 87 | 88 | Regardless of the installation method, you need to configure the environment variables. Create **one** of the following files: 89 | 90 | 1. **Using MCP Host Settings (Recommended for `npx`):** Configure environment variables directly within your MCP Host's settings (see "MCP Host Configuration" below). This is the easiest way when using `npx`. 91 | 2. **Using a `.env` file:** Create a `.env` file in the directory where you run the `npx @kunihiros/claude-code-mcp` command. 92 | 3. **Using a global config file:** Create a `.claude-code-mcp.env` file in your home directory (`~/.claude-code-mcp.env`). 93 | 94 | If using a file (`.env` or `~/.claude-code-mcp.env`), add the following content, adjusting the `CLAUDE_BIN` path: 95 | 96 | ```dotenv 97 | # .env or ~/.claude-code-mcp.env 98 | CLAUDE_BIN=/path/to/your/claude/executable # REQUIRED: Set the full path to your Claude CLI 99 | LOG_LEVEL=info # Optional: Set log level (e.g., debug, info, warn, error) 100 | ``` 101 | 102 | **MCP Host Configuration (Recommended for `npx`):** 103 | 104 | Add the following to your MCP Host application settings (e.g., Claude Desktop settings). This method allows you to set environment variables directly. 105 | 106 | ```json 107 | "claude-code-server": { 108 | "command": "npx", 109 | "args": [ 110 | "-y", 111 | "@kunihiros/claude-code-mcp" 112 | ], 113 | "env": { 114 | "CLAUDE_BIN": "/path/to/your/claude/executable", // REQUIRED: Set the absolute path 115 | "LOG_LEVEL": "info" // Optional: Set log level 116 | }, 117 | "disabled": false 118 | } 119 | ``` 120 | *(Restarting the host application might be required.)* 121 | 122 | **Alternative MCP Host Configuration (Global Install / Local Dev):** 123 | 124 | If you installed the package globally or are running it locally from the cloned repository, and the `claude-code-mcp` command is in your system's PATH, you can use: 125 | 126 | ```json 127 | "claude-code-server": { 128 | "command": "claude-code-mcp", 129 | "disabled": false 130 | } 131 | ``` 132 | In this case, you **must** configure environment variables using a `.env` file or the global `~/.claude-code-mcp.env` file as described above. 133 | 134 | ## Environment Variables Details 135 | 136 | This server uses the following environment variables (set via MCP Host `env` settings, `.env`, or `~/.claude-code-mcp.env`): 137 | 138 | - `CLAUDE_BIN`: Specifies the path to the Claude CLI executable. **(Required)** 139 | Example: `/home/linuxbrew/.linuxbrew/bin/claude` or `C:\Users\YourUser\AppData\Local\bin\claude.exe` 140 | - `LOG_LEVEL`: Specifies the log level. (Optional, defaults to `info`). Possible values: `debug`, `info`, `warn`, `error`. 141 | 142 | ## Available Tools 143 | 144 | The `claude-code-mcp` server provides the following tools: 145 | 146 | - `explain_code`: Provides a detailed explanation of the given code. 147 | - `review_code`: Reviews the given code. 148 | - `fix_code`: Fixes bugs or issues in the given code. 149 | - `edit_code`: Edits the given code based on instructions. 150 | - `test_code`: Generates tests for the given code. 151 | - `simulate_command`: Simulates the execution of a given command. 152 | - `your_own_query`: Sends a custom query with context. 153 | 154 | ## Note 155 | 156 | - Log file (`claude-code-mcp.log`) location: 157 | - Attempts to create in the project root first. 158 | - Falls back to the user's home directory (`~/.claude-code-mcp.log`). 159 | - Finally falls back to `/tmp/claude-code-mcp.log`. 160 | - Log rotation is not implemented yet (be careful with log file size). 161 | - Primarily tested with Claude CLI on Ubuntu/WSL2. 162 | 163 | ## License 164 | 165 | This project is licensed under the MIT License - see below for details. 166 | 167 | ``` 168 | MIT License 169 | 170 | Copyright (c) 2024 KunihiroS 171 | 172 | Permission is hereby granted, free of charge, to any person obtaining a copy 173 | of this software and associated documentation files (the "Software"), to deal 174 | in the Software without restriction, including without limitation the rights 175 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 176 | copies of the Software, and to permit persons to whom the Software is 177 | furnished to do so, subject to the following conditions: 178 | 179 | The above copyright notice and this permission notice shall be included in all 180 | copies or substantial portions of the Software. 181 | 182 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 183 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 184 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 185 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 186 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 187 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 188 | SOFTWARE. 189 | ``` 190 | 191 | ## Disclaimer 192 | 193 | 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. 194 | 195 | The project uses the Claude CLI as a dependency, but is an independent, community-driven effort. Users should ensure they comply with Anthropic's terms of service when using this project. 196 | 197 | The maintainers of this project are not responsible for any misuse of the software or violations of the terms of service of any third-party APIs or services. ``` -------------------------------------------------------------------------------- /claude-code-server/tsconfig.json: -------------------------------------------------------------------------------- ```json 1 | { 2 | "compilerOptions": { 3 | "module": "ES2020", 4 | "target": "ES2020", 5 | "moduleResolution": "node", 6 | "outDir": "build", 7 | "strict": true, 8 | "esModuleInterop": true, 9 | "types": ["node"], 10 | "skipLibCheck": true 11 | }, 12 | "include": ["src"] 13 | } 14 | ``` -------------------------------------------------------------------------------- /claude-code-server/src/declarations.d.ts: -------------------------------------------------------------------------------- ```typescript 1 | declare module '@modelcontextprotocol/sdk/server/index.js' { 2 | export class Server { 3 | constructor(config: { name: string, version: string }, options: { capabilities: { resources: any, tools: any } }); 4 | setRequestHandler(schema: any, handler: (request: any) => Promise<any>): void; 5 | connect(transport: any): Promise<void>; 6 | close(): Promise<void>; 7 | onerror: (error: any) => void; 8 | } 9 | export default Server; 10 | } 11 | 12 | declare module '@modelcontextprotocol/sdk/server/stdio.js' { 13 | export class StdioServerTransport {} 14 | } 15 | 16 | declare module '@modelcontextprotocol/sdk/types.js' { 17 | export const CallToolRequestSchema: any; 18 | export const ListToolsRequestSchema: any; 19 | export class McpError extends Error { 20 | constructor(code: number, message: string); 21 | } 22 | } 23 | ``` -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- ```dockerfile 1 | # Dockerfile for claude-code-mcp 2 | FROM node:18-alpine 3 | 4 | # Set working directory 5 | WORKDIR /app 6 | 7 | # Install required OS packages (git may be needed by optional deps) 8 | RUN apk add --no-cache git 9 | 10 | # Use pnpm with Corepack (falls back to npm-global if corepack path changes) 11 | RUN corepack enable && corepack prepare [email protected] --activate || npm i -g pnpm 12 | 13 | # Copy only lockfiles first to maximize layer cache 14 | COPY package.json pnpm-lock.yaml ./ 15 | 16 | # Install dependencies using the exact locked versions 17 | RUN pnpm install --frozen-lockfile 18 | 19 | # Copy the rest of the source 20 | COPY . . 21 | 22 | # Build the project (generates claude-code-server/build/index.js) 23 | RUN pnpm run build 24 | 25 | # Environment 26 | ENV NODE_ENV=production 27 | 28 | # NOTE: You must provide CLAUDE_BIN at runtime, e.g. 29 | # docker run --rm -e CLAUDE_BIN=/path/in/container/claude image 30 | # or mount the host CLI binary into the container and point CLAUDE_BIN to it. 31 | 32 | # Run the MCP server over stdio 33 | CMD ["node", "claude-code-server/build/index.js"] ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- ```json 1 | { 2 | "name": "@kunihiros/claude-code-mcp", 3 | "version": "0.1.6", 4 | "description": "MCP server for Claude Code", 5 | "main": "claude-code-server/build/index.js", 6 | "type": "module", 7 | "bin": { 8 | "claude-code-mcp": "./claude-code-server/build/index.js" 9 | }, 10 | "files": [ 11 | "claude-code-server/build/**/*", 12 | "README.md", 13 | "LICENSE", 14 | "claude-code-server/.env.example" 15 | ], 16 | "scripts": { 17 | "build": "cd claude-code-server && npx tsc && chmod +x build/index.js", 18 | "start": "node claude-code-server/build/index.js", 19 | "prepublishOnly": "npm run build" 20 | }, 21 | "dependencies": { 22 | "@modelcontextprotocol/sdk": "^1.0.0", 23 | "dotenv": "^16.4.5", 24 | "winston": "^3.13.0" 25 | }, 26 | "devDependencies": { 27 | "@anthropic-ai/claude-code": ">=1.0.105", 28 | "@types/dotenv": "^8.2.0", 29 | "@types/node": "^20.17.43", 30 | "typescript": "^4.9.5" 31 | }, 32 | "keywords": [ 33 | "claude", 34 | "claude-code", 35 | "mcp", 36 | "anthropic", 37 | "ai", 38 | "model-context-protocol" 39 | ], 40 | "author": "KunihiroS", 41 | "license": "MIT", 42 | "repository": { 43 | "type": "git", 44 | "url": "git+https://github.com/KunihiroS/claude-code-mcp.git" 45 | }, 46 | "bugs": { 47 | "url": "https://github.com/KunihiroS/claude-code-mcp/issues" 48 | }, 49 | "homepage": "https://github.com/KunihiroS/claude-code-mcp#readme", 50 | "engines": { 51 | "node": ">=18" 52 | } 53 | } ```