What is MCP?
MCP (Model Context Protocol) is an open standard created by Anthropic that defines how AI models communicate with external tools. It's like a "USB for AI": a universal connector that any tool can implement.
With MCP, Claude Code can access resources beyond your local file system: PostgreSQL databases, REST APIs, the web browser, Slack, GitHub, Jira, and any service that has an MCP server.
How it works
An MCP server is a process (local or remote) that exposes:
- Tools: functions Claude can call (e.g., run SQL, search Slack).
- Resources: data Claude can read (e.g., DB schema, documentation).
- Prompts: specialized instructions for specific tasks.
Adding an MCP server
MCP servers are configured in .claude/settings.json :
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres",
"postgresql://localhost/midb"],
"env": {}
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxx"
}
}
}
}Or add servers directly from the CLI:
claude mcp add <name> -- <command> [args...] # Example: PostgreSQL server claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres \ "postgresql://localhost/midb" # Example: filesystem server (read-only) claude mcp add files -- npx -y @modelcontextprotocol/server-filesystem \ /path/to/directory
Popular MCP servers
Managing MCP servers
# List configured servers claude mcp list # View details for a server claude mcp get postgres # Remove a server claude mcp remove postgres # Inside Claude Code, view active servers: /mcp
MCP server scopes
MCP servers have three possible scopes:
- Local (default): available only in the current project. Saved in .claude/settings.json .
- User: available across all your projects. Saved in ~/.claude/settings.json . Add --scope user to the command.
- Project: shared with the team via version control.
# Add server at user level (global) claude mcp add --scope user github -- npx -y @modelcontextprotocol/server-github
Creating your own MCP server
Any script that implements the MCP protocol can be a server. Anthropic provides SDKs for Python and TypeScript:
# TypeScript npm install @modelcontextprotocol/sdk # Python pip install mcp
Minimal TypeScript example
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server({ name: "my-server", version: "1.0.0" }, {
capabilities: { tools: {} }
});
server.setRequestHandler("tools/list", async () => ({
tools: [{
name: "greet",
description: "Greets the user",
inputSchema: {
type: "object",
properties: { name: { type: "string" } },
required: ["name"]
}
}]
}));
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "greet") {
return { content: [{ type: "text", text: `Hello, ${request.params.arguments.name}!` }] };
}
});
const transport = new StdioServerTransport();
await server.connect(transport);MCP in the cloud vs local
MCP servers can run locally (as a process on your machine) or in the cloud (connected via HTTP/SSE). Claude Code supports both:
# Local server (stdio)
{
"command": "node",
"args": ["./my-mcp-server.js"]
}
# Remote server (HTTP/SSE)
{
"url": "https://my-server.com/mcp",
"headers": { "Authorization": "Bearer TOKEN" }
}