🔌MCP — Model Context Protocol
Connect Claude to external tools, databases, and services via MCP
MCP — Model Context Protocol
What Is MCP?
The Model Context Protocol (MCP) is an open standard created by Anthropic that lets AI models like Claude communicate with external tools, data sources, and services through a unified protocol. Think of it as a USB-C port for AI — one standard connector that works with everything.
Before MCP, every integration required custom code, bespoke APIs, and brittle glue logic. MCP replaces all of that with a single, well-defined protocol that any tool can implement.
The Problem MCP Solves
Without MCP, connecting Claude to external systems looks like this:
Claude --> Custom code --> Tool A
Claude --> Different custom code --> Tool B
Claude --> Yet another adapter --> Tool C
With MCP, it becomes:
Claude --> MCP Protocol --> Any MCP Server
MCP Architecture
MCP follows a client-server architecture with three core components:
1. MCP Host
The application that runs the AI model (e.g., Claude Desktop, Claude Code, your custom app).
2. MCP Client
A protocol client embedded inside the host. It manages connections to one or more MCP servers.
3. MCP Server
A lightweight program that exposes specific capabilities — tools, resources, or prompts — through the MCP standard.
┌─────────────────────────────────────────────────┐
│ MCP Host │
│ (Claude Desktop / Claude Code / Custom App) │
│ │
│ ┌───────────┐ ┌───────────┐ │
│ │ MCP Client│ │ MCP Client│ │
│ └─────┬─────┘ └─────┬─────┘ │
│ │ │ │
└─────────┼───────────────┼───────────────────────┘
│ │
┌─────▼─────┐ ┌─────▼─────┐
│MCP Server │ │MCP Server │
│(Filesystem│ │ (GitHub) │
│ access) │ │ │
└───────────┘ └───────────┘
Communication Flow
- The host starts and initializes one or more MCP clients.
- Each client connects to an MCP server via stdio or HTTP/SSE.
- The client discovers available tools, resources, and prompts from the server.
- When Claude decides to use a tool, the client sends a request to the appropriate server.
- The server executes the action and returns the result.
- Claude receives the result and continues its reasoning.
MCP with Claude Code
Claude Code has built-in MCP support. You can configure MCP servers directly in your project or global settings.
Adding an MCP Server to Claude Code
# Add a server to your project
claude mcp add my-server -s project -- npx -y @modelcontextprotocol/server-filesystem /path/to/dir
# Add a server globally
claude mcp add my-server -s user -- npx -y @modelcontextprotocol/server-filesystem /path/to/dir
# List all configured servers
claude mcp list
# Remove a server
claude mcp remove my-serverConfiguration File
MCP servers are stored in .claude/settings.json (project) or ~/.claude/settings.json (global):
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"],
"env": {}
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
}
}
}
}Using MCP Tools in Claude Code
Once configured, Claude Code automatically discovers available tools. You can ask Claude to use them naturally:
> Read the contents of /home/user/projects/README.md using the filesystem tool
> List my open GitHub pull requests
> Search my Slack messages from today
MCP with the Claude API
When building custom applications with the Claude API, you can connect MCP servers as tool providers.
Basic Setup with the SDK
// 1. Start the MCP server
const transport = new StdioClientTransport({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
});
// 2. Connect the MCP client
const mcpClient = new Client({ name: "my-app", version: "1.0.0" });
await mcpClient.connect(transport);
// 3. Discover available tools
const { tools } = await mcpClient.listTools();
// 4. Convert MCP tools to Claude API format
const claudeTools = tools.map((tool) => ({
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema,
}));
// 5. Use tools in conversation
const anthropic = new Anthropic();
const response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
tools: claudeTools,
messages: [{ role: "user", content: "List files in /tmp" }],
});Popular MCP Servers
Here is a reference table of widely-used MCP servers you can add today:
| Server | Package | Description |
|---|---|---|
| Filesystem | @modelcontextprotocol/server-filesystem | Read, write, search, and manage local files |
| GitHub | @modelcontextprotocol/server-github | Repos, issues, PRs, code search |
| Slack | @modelcontextprotocol/server-slack | Read channels, search messages, post updates |
| PostgreSQL | @modelcontextprotocol/server-postgres | Query databases, inspect schemas |
| SQLite | @modelcontextprotocol/server-sqlite | Local database operations |
| Google Drive | @modelcontextprotocol/server-gdrive | Search and read Google Drive files |
| Brave Search | @modelcontextprotocol/server-brave-search | Web search via Brave API |
| Memory | @modelcontextprotocol/server-memory | Persistent key-value memory for Claude |
| Puppeteer | @modelcontextprotocol/server-puppeteer | Browser automation and web scraping |
| Git | @modelcontextprotocol/server-git | Git operations on local repositories |
Community Servers
The MCP ecosystem is growing rapidly. Community-built servers include:
- Notion — Read and write Notion pages and databases
- Linear — Manage issues, projects, and cycles
- Sentry — Query error reports and performance data
- Jira — Interact with Jira issues and boards
- MongoDB — Query and manage MongoDB collections
- Redis — Key-value store operations
- Docker — Manage containers and images
Setting Up Your First MCP Server
Let us walk through setting up the Filesystem server step by step.
Step 1: Install and Add the Server
# With Claude Code
claude mcp add filesystem -s project -- npx -y @modelcontextprotocol/server-filesystem /home/user/projects
# Verify it is running
claude mcp listStep 2: Test the Connection
Start Claude Code and try a simple command:
> List all files in my projects directory
Claude will use the filesystem MCP server to read the directory and return the results.
Step 3: Try More Operations
> Read the package.json file
> Search for all TypeScript files containing "export default"
> Create a new file called notes.txt with today's date
Creating a Custom MCP Server
You can build your own MCP server to expose any functionality to Claude. Here is a minimal example in TypeScript:
const server = new McpServer({
name: "weather-server",
version: "1.0.0",
});
// Define a tool
server.tool(
"get-weather",
"Get current weather for a city",
{
city: z.string().describe("City name"),
},
async ({ city }) => {
// In production, call a real weather API
const weather = await fetchWeather(city);
return {
content: [
{
type: "text",
text: JSON.stringify(weather, null, 2),
},
],
};
}
);
// Define a resource
server.resource(
"config",
"config://app",
async (uri) => ({
contents: [
{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify({ version: "1.0", region: "us-east" }),
},
],
})
);
// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);Registering Your Custom Server
# Point Claude Code to your custom server
claude mcp add weather -s project -- node /path/to/weather-server.jsSecurity Considerations
MCP servers can be powerful — they access files, databases, and external services. Follow these security best practices:
1. Principle of Least Privilege
Only grant MCP servers access to the directories and resources they need. Never expose your entire filesystem.
# Good: Specific directory
claude mcp add fs -- npx -y @modelcontextprotocol/server-filesystem /home/user/projects/my-app
# Bad: Entire filesystem
claude mcp add fs -- npx -y @modelcontextprotocol/server-filesystem /2. Environment Variables
Store sensitive credentials in environment variables, never in configuration files committed to version control.
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN"
}
}
}
}3. Review Tool Calls
Claude Code shows you every tool call before execution. Always review what the MCP server is about to do, especially for write operations.
4. Use Project-Scoped Servers
Prefer project-level configuration over global configuration. This limits the blast radius if something goes wrong.
5. Audit Server Code
When using community MCP servers, review the source code before granting access to sensitive data. Check the npm package contents and GitHub repository.
Practical Examples
Example 1: Database-Backed Q&A
# Add PostgreSQL server
claude mcp add db -s project -- npx -y @modelcontextprotocol/server-postgres "postgresql://user:pass@localhost/mydb"Then ask Claude:
> How many users signed up this month? Query the users table.
> What are the top 5 products by revenue? Join orders and products tables.
Example 2: Multi-Server Workflow
Configure multiple servers for a comprehensive development workflow:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./src"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN" }
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "$DATABASE_URL"]
}
}
}Then use all of them together:
> Check my open PRs on GitHub, read the related source files,
> and verify the database schema matches the migration in the PR.
Example 3: Automated Documentation
> Read all TypeScript files in src/, analyze the exports,
> and generate an API reference document.
Key Takeaways
- MCP is an open protocol that standardizes how AI models connect to external tools
- It uses a client-server architecture: Host > Client > Server
- Claude Code supports MCP natively via
claude mcp add - You can use pre-built servers for filesystems, GitHub, databases, and more
- Custom servers are straightforward to build with the official SDK
- Always follow security best practices: least privilege, credential management, review
- MCP turns Claude from a text-only model into an agent that can interact with the real world