Skip to main content

MCP with Claude Desktop, Claude Code, and the Claude API

29/40
Chapter 8 Connecting MCP to Every AI Platform

MCP with Claude Desktop, Claude Code, and the Claude API

22 min read Lesson 29 / 40 Preview

MCP with Claude Desktop, Claude Code, and the Claude API

Claude is the most MCP-native AI platform. Anthropic created MCP, and Claude products have the deepest integration. This lesson covers connecting your servers to all three Claude products.

Claude Desktop Configuration

Claude Desktop supports MCP natively through a JSON configuration file.

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "database": {
      "command": "node",
      "args": ["/path/to/db-server/build/index.js"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/mydb"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@yourname/mcp-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/you/projects"]
    }
  }
}

After saving, restart Claude Desktop. You will see a hammer icon (🔨) showing available tools. Click it to see all registered tools from all connected servers.

Claude Code Configuration

Claude Code (the CLI agent) supports MCP through project-level or user-level configuration:

# Add an MCP server to the current project
claude mcp add database-server -s project -- node /path/to/build/index.js

# Add with environment variables
claude mcp add github -s project -e GITHUB_TOKEN=ghp_token -- npx -y @yourname/mcp-github

# List configured servers
claude mcp list

# Remove a server
claude mcp remove database-server

Or edit .mcp.json in your project root directly:

{
  "mcpServers": {
    "database": {
      "command": "node",
      "args": ["/path/to/db-server/build/index.js"],
      "env": {
        "DATABASE_URL": "postgresql://localhost/mydb"
      }
    }
  }
}

Claude Code automatically picks up MCP servers and uses their tools during coding sessions.

Claude API with MCP

For programmatic access, use the Claude API with MCP tool definitions:

import anthropic

client = anthropic.Anthropic()

# Define tools that match your MCP server's tools
tools = [
    {
        "name": "query_database",
        "description": "Execute a read-only SQL query against the database",
        "input_schema": {
            "type": "object",
            "properties": {
                "sql": {
                    "type": "string",
                    "description": "SQL SELECT query to execute"
                }
            },
            "required": ["sql"]
        }
    }
]

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=4096,
    tools=tools,
    messages=[
        {"role": "user", "content": "How many orders were placed last month?"}
    ],
)

# When Claude wants to use a tool, forward it to your MCP server
for block in response.content:
    if block.type == "tool_use":
        # Execute against your MCP server or directly
        result = execute_mcp_tool(block.name, block.input)
        # Send result back to Claude for final response

Best Practices for Claude Integration

  1. Use descriptive tool names — Claude excels at choosing the right tool when names are clear
  2. Include examples in descriptions — Claude performs better with example inputs
  3. Limit tool count — 10-15 tools per server is optimal; more causes selection confusion
  4. Test with extended thinking — Claude Opus 4.6 with extended thinking makes better tool decisions

Key Takeaway

Claude products offer the deepest MCP integration because Anthropic built the protocol. Claude Desktop for interactive use, Claude Code for development workflows, and the Claude API for programmatic access — all work seamlessly with your MCP servers.