The Claude Code MCP Server enables integration with Anthropic's Claude Code capabilities through function calling for various agent frameworks, including Model Context Protocol (MCP). It provides a convenient way to leverage Claude's coding abilities programmatically, allowing AI assistants to understand, analyze, and manipulate code through a simple, secure connection.
Before you can use Claude Code as an MCP server, you need to install the Claude Code CLI:
npm install -g @anthropic-ai/claude-code
Important: Do NOT use
sudo npm install -g
as this can lead to permission issues and security risks.
After installation, you'll need to authenticate:
cd your-project-directory
claude
to launchClaude Code does not run directly in Windows and requires WSL. If you encounter issues in WSL:
OS/platform detection issues: If you receive an error during installation, WSL may be using Windows npm. Try:
npm config set os linux
before installationnpm install -g @anthropic-ai/claude-code --force --no-os-check
(Do NOT use sudo)Node not found errors: If you see exec: node: not found
when running claude
, your WSL environment may be using a Windows installation of Node.js. You can confirm this with which npm
and which node
, which should point to Linux paths starting with /usr/
rather than /mnt/c/
. To fix this, try installing Node via your Linux distribution's package manager or via nvm.
The fastest way to run the Claude Code MCP server is directly from the Claude Code CLI:
claude mcp serve
This command starts Claude Code as an MCP server that other applications can connect to, providing them with Claude's tools and capabilities.
You can connect to the Claude Code MCP server from any MCP client, such as Claude Desktop. If you're using Claude Desktop, you can add the Claude Code MCP server using this configuration:
{
"command": "claude",
"args": ["mcp", "serve"],
"env": {}
}
The Claude Code MCP server provides access to all of Claude's built-in tools including:
The Claude Code MCP Server can be used with various frameworks:
{
"mcpServers": {
"claude-code": {
"command": "claude",
"args": [
"mcp",
"serve"
]
}
}
}
For older versions of Cursor, you may need to restart the application after adding the MCP server configuration.
You can integrate the Claude Code MCP server into your own applications that support the Model Context Protocol:
import { MCPClient } from "@modelcontextprotocol/client";
// Connect to the Claude Code MCP server
const client = new MCPClient({
command: "claude",
args: ["mcp", "serve"],
env: {}
});
// Now you can use all Claude Code tools via the client
const result = await client.callFunction("readFile", {
path: "/path/to/file.js"
});
When using Claude Code as an MCP server:
The Claude Code MCP server exposes all of Claude's built-in tools, making it particularly useful for:
Like other MCP servers in Claude Code, you can configure the Claude Code MCP server with different scopes:
# Add as a project-scoped server
claude mcp add claude-code-server -s project -- claude mcp serve
# Add as a user-scoped server
claude mcp add claude-code-server -s user -- claude mcp serve
When using Claude Code as an MCP server, be aware of these limitations:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.