Using MCP Servers with Claude Code
MCP (Model Context Protocol) is an open standard that lets Claude Code connect to external tools and data sources. MCP servers give Claude Code new abilities like fetching web content, querying databases, or interacting with third-party APIs.
What is MCP?
MCP follows a client-server architecture:
- MCP Client — Claude Code itself, which connects to servers
- MCP Server — A lightweight program that exposes tools via the MCP protocol
When you add an MCP server, its tools become available to Claude Code just like built-in tools.
Adding an MCP Server
Use the claude mcp add command:
# Add a filesystem MCP server
claude mcp add filesystem -- npx -y @anthropic-ai/mcp-filesystem /path/to/dir
# Add a PostgreSQL MCP server
claude mcp add postgres -- npx -y @anthropic-ai/mcp-postgres "postgresql://localhost/mydb"
# Add a web fetch MCP server
claude mcp add fetch -- npx -y @anthropic-ai/mcp-fetchManaging MCP Servers
# List all configured MCP servers
claude mcp list
# Remove an MCP server
claude mcp remove postgres
# Get details about a server
claude mcp get filesystemMCP Server Scopes
MCP servers can be configured at different scopes:
# Project-level (stored in .claude/settings.json)
claude mcp add --scope project my-server -- command args
# User-level (stored in ~/.claude/settings.json)
claude mcp add --scope user my-server -- command argsPopular MCP Servers
| Server | Purpose | Example Use |
|---|---|---|
| mcp-filesystem | Access files outside project | Read config files from other directories |
| mcp-postgres | Query PostgreSQL | Check database schema and data |
| mcp-fetch | Fetch web URLs | Read API docs, check endpoints |
| mcp-github | GitHub integration | Manage issues, PRs, repos |
| mcp-slack | Slack integration | Send messages, read channels |
Using MCP Tools in Conversation
Once configured, MCP tools appear automatically. For example, with the postgres server:
> Show me all tables in the database
# Claude uses the MCP postgres tool to query information_schema
> What columns does the users table have?
# Claude queries the table structure directlyCreating Custom MCP Servers
You can create your own MCP servers for custom integrations. The MCP SDK is available in TypeScript and Python:
npm install @modelcontextprotocol/sdkA minimal MCP server exposes tools that Claude Code can call:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({ name: "my-server", version: "1.0.0" });
server.tool("hello", "Say hello", { name: { type: "string" } },
async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }]
})
);
const transport = new StdioServerTransport();
await server.connect(transport);Summary
MCP servers extend Claude Code’s capabilities by connecting it to external tools and data sources. From databases to APIs to custom integrations, MCP makes Claude Code infinitely extensible. Next, we’ll cover advanced tips and tricks to maximize your productivity.