Claude Code MCP Server MCP server

Use Claude Code as an MCP server.
Back to servers
Provider
Anthropic
Release date
Mar 25, 2025
Language
TypeScript

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.

Installation

Installing Claude Code CLI

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.

System Requirements

  • Operating Systems: macOS 10.15+, Ubuntu 20.04+/Debian 10+, or Windows via WSL
  • Hardware: 4GB RAM minimum
  • Software:
    • Node.js 18+
    • git 2.23+ (optional)
    • GitHub or GitLab CLI for PR workflows (optional)
    • ripgrep (rg) for enhanced file search (optional)
  • Network: Internet connection required for authentication and AI processing

Authentication

After installation, you'll need to authenticate:

  1. Navigate to your project: cd your-project-directory
  2. Start Claude Code: Run claude to launch
  3. Complete the one-time OAuth process with your Console account
  4. You'll need active billing at console.anthropic.com

Troubleshooting WSL Installation

Claude 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:

    • Run npm config set os linux before installation
    • Install with npm 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.

Setting Up the MCP Server

Quick Start

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.

Configuration Options

Connecting from Other Applications

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": {}
}

Available Tools

The Claude Code MCP server provides access to all of Claude's built-in tools including:

  • File reading and writing
  • Directory listing
  • Code editing and creation
  • Running commands
  • Search functionality

Using with Other Frameworks

The Claude Code MCP Server can be used with various frameworks:

Cursor IDE Integration

  1. Ensure Claude Code CLI is installed on your system
  2. Open Cursor settings (⇧+⌘+J)
  3. Navigate to the "MCP" tab and click "Add MCP Server"
  4. Add the following JSON configuration:
{
  "mcpServers": {
    "claude-code": {
      "command": "claude",
      "args": [
        "mcp",
        "serve"
      ]
    }
  }
}
  1. Click "Save" to add the Claude Code MCP server to Cursor
  2. You can now use Claude Code capabilities directly within Cursor

For older versions of Cursor, you may need to restart the application after adding the MCP server configuration.

Integration in Applications

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"
});

Security and Management

When using Claude Code as an MCP server:

  • The server provides access to Claude's tools like View, Edit, LS, etc.
  • Your MCP client is responsible for implementing user confirmation for individual tool calls
  • All tool calls will execute in the context of the user running the claude mcp serve command
  • Consider security implications when exposing file system access through the MCP server

Advanced Usage

Custom Tool Implementation

The Claude Code MCP server exposes all of Claude's built-in tools, making it particularly useful for:

  1. Code analysis and understanding
  2. Automated code editing and refactoring
  3. File system interactions from other applications
  4. Running and analyzing command output

MCP Server Scope Configuration

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

Limitations

When using Claude Code as an MCP server, be aware of these limitations:

  • The server can only access files and run commands in the context of the user running the server
  • The server doesn't implement authentication or authorization beyond what's provided by the file system
  • Tool calls that would normally require user confirmation in Claude Code will be executed without confirmation by default, so your client application should implement its own confirmation mechanism

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later