claude code mcp
An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.
An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.
Claude Code MCP is an implementation of Claude Code as a Model Context Protocol (MCP) server. This project allows you to use Claude Code's powerful software engineering capabilities through the standardized MCP interface.
Claude Code is Anthropic's CLI tool for software engineering tasks, powered by Claude. It provides a set of tools and capabilities that help developers with:
The original implementation is available as a JavaScript module that defines prompts and tools for interacting with Claude's API.
The Model Context Protocol (MCP) is a standardized interface for AI models that enables consistent interaction patterns across different models and providers. MCP defines:
By implementing Claude Code as an MCP server, we make its capabilities available to any MCP-compatible client, allowing for greater interoperability and flexibility.
# Clone the repository
git clone https://github.com/auchenberg/claude-code-mcp.git
cd claude-code-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Start the server
npm start
Claude Code MCP can be used with any MCP client. Here's an example of how to connect to it using the MCP TypeScript SDK:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "node",
args: ["dist/index.js"]
});
const client = new Client(
{
name: "example-client",
version: "1.0.0"
},
{
capabilities: {
prompts: {},
resources: {},
tools: {}
}
}
);
await client.connect(transport);
// Use Claude Code through MCP
const result = await client.callTool({
name: "bash",
arguments: {
command: "ls -la"
}
});
console.log(result);
Claude Code MCP provides the following tools:
{
command: string; // The shell command to execute
timeout?: number; // Optional timeout in milliseconds (max 600000)
}
The bash tool includes security restrictions that prevent execution of potentially dangerous commands like curl
, wget
, and others.
{
file_path: string; // The absolute path to the file to read
offset?: number; // The line number to start reading from
limit?: number; // The number of lines to read
}
{
pattern: string; // The glob pattern to match files against
path?: string; // The directory to search in (defaults to current working directory)
}
{
pattern: string; // The regular expression pattern to search for
path?: string; // The directory to search in (defaults to current working directory)
include?: string; // File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")
}
file://{path}
)Returns the full text content of the specified file
directory: List directory contents (dir://{path}
)
Each object includes name, path, isDirectory, size, and modified date
environment: Get system environment information (env://info
)
Automatically includes environment details
codeReview: Prompt for reviewing code
Analyzes code for bugs, security vulnerabilities, performance issues, and best practices
prReview: Prompt for reviewing pull requests
Analyzes PR changes and provides comprehensive feedback
initCodebase: Initialize a new CLAUDE.md file with codebase documentation
# Run in development mode with auto-reload
npm run dev
Claude Code MCP is built with a modular architecture:
claude-code-mcp/
├── src/
│ ├── server/
│ │ ├── claude-code-server.ts # Main server setup
│ │ ├── tools.ts # Tool implementations
│ │ ├── prompts.ts # Prompt definitions
│ │ └── resources.ts # Resource implementations
│ ├── utils/
│ │ ├── bash.ts # Shell command utilities
│ │ └── file.ts # File system utilities
│ └── index.ts # Entry point
├── package.json
├── tsconfig.json
└── README.md
The implementation follows these key principles:
The main server is set up in claude-code-server.ts
:
export async function setupClaudeCodeServer(server: McpServer): Promise<void> {
// Set up Claude Code tools
setupTools(server);
// Set up Claude Code prompts
setupPrompts(server);
// Set up Claude Code resources
setupResources(server);
}
Tools are implemented using the MCP SDK's tool registration method:
server.tool(
"toolName",
"Tool description",
{
// Zod schema for tool arguments
param1: z.string().describe("Parameter description"),
param2: z.number().optional().describe("Optional parameter description")
},
async ({ param1, param2 }) => {
// Tool implementation
return {
content: [{ type: "text", text: "Result" }]
};
}
);
Resources are implemented using the MCP SDK's resource registration method:
server.resource(
"resourceName",
new ResourceTemplate("resource://{variable}", { list: undefined }),
async (uri, variables) => {
// Resource implementation
return {
contents: [{
uri: uri.href,
text: "Resource content"
}]
};
}
);
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
This project is not officially affiliated with Anthropic. Claude Code is a product of Anthropic, and this project is an independent implementation of Claude Code as an MCP server.
[
{
"description": "Execute a shell command",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"command": {
"description": "The shell command to execute",
"type": "string"
},
"timeout": {
"description": "Optional timeout in milliseconds (max 600000)",
"type": "number"
}
},
"required": [
"command"
],
"type": "object"
},
"name": "bash"
},
{
"description": "Read a file from the local filesystem",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"file_path": {
"description": "The absolute path to the file to read",
"type": "string"
},
"limit": {
"description": "The number of lines to read",
"type": "number"
},
"offset": {
"description": "The line number to start reading from",
"type": "number"
}
},
"required": [
"file_path"
],
"type": "object"
},
"name": "readFile"
},
{
"description": "Lists files and directories in a given path",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"path": {
"description": "The absolute path to the directory to list",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "listFiles"
},
{
"description": "Search for files matching a pattern",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"path": {
"description": "The directory to search in. Defaults to the current working directory.",
"type": "string"
},
"pattern": {
"description": "The glob pattern to match files against",
"type": "string"
}
},
"required": [
"pattern"
],
"type": "object"
},
"name": "searchGlob"
},
{
"description": "Search for text in files",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"include": {
"description": "File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")",
"type": "string"
},
"path": {
"description": "The directory to search in. Defaults to the current working directory.",
"type": "string"
},
"pattern": {
"description": "The regular expression pattern to search for in file contents",
"type": "string"
}
},
"required": [
"pattern"
],
"type": "object"
},
"name": "grep"
},
{
"description": "A tool for thinking through complex problems",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"thought": {
"description": "Your thoughts",
"type": "string"
}
},
"required": [
"thought"
],
"type": "object"
},
"name": "think"
},
{
"description": "Review code for bugs, security issues, and best practices",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"code": {
"description": "The code to review",
"type": "string"
}
},
"required": [
"code"
],
"type": "object"
},
"name": "codeReview"
},
{
"description": "Create or edit a file",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"content": {
"description": "The new content for the file",
"type": "string"
},
"file_path": {
"description": "The absolute path to the file to edit",
"type": "string"
}
},
"required": [
"file_path",
"content"
],
"type": "object"
},
"name": "editFile"
}
]