What Is MCP?
Model Context Protocol (MCP) is a standard protocol that enables AI models to interact with external tools and data sources. Through MCP servers, Claude Code can add capabilities like database queries, API calls, and file system operations.
How MCP Works
MCP is a communication protocol between a client (Claude Code) and servers (tool providers).
- Servers publish a list of available tools with descriptions
- Claude Code recognizes these tools and calls them as needed
- Servers execute the tool and return results
- Claude Code interprets results and determines next actions
Configuring MCP Servers
Add MCP servers to your Claude Code configuration file.
{
"mcpServers": {
"my-database": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}
}
}Configuration file locations:
- Per-project:
.claude/settings.json - Per-user:
~/.claude/settings.json
Key Official MCP Servers
Examples of official servers provided by Anthropic and the community.
File System
Safely read, write, and manage files and directories.
PostgreSQL / SQLite
Connect to databases, execute queries, and retrieve schema information.
GitHub
Manage issues, operate on PRs, and retrieve repository information.
Slack
Send and receive messages and manage channels.
Web Browser
Fetch and scrape web pages.
Building Custom MCP Servers
You can build custom MCP servers in TypeScript.
import { Server } from "@modelcontextprotocol/sdk/server";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio";
const server = new Server({
name: "my-custom-server",
version: "1.0.0",
});
// Define tools
server.setRequestHandler("tools/list", async () => ({
tools: [{
name: "get_weather",
description: "Get weather for a specified city",
inputSchema: {
type: "object",
properties: {
city: { type: "string", description: "City name" }
},
required: ["city"]
}
}]
}));
// Execute tools
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "get_weather") {
const city = request.params.arguments.city;
// Call weather API
return { content: [{ type: "text", text: `Weather in ${city}: Sunny 22°C` }] };
}
});
const transport = new StdioServerTransport();
await server.connect(transport);Security Considerations
MCP servers are powerful but require security awareness.
- Use trusted servers only: Review third-party MCP server code before deployment
- Principle of least privilege: Use read-only database accounts when possible
- Credential management: Store API keys in environment variables, never hardcode in config files
Looking back
MCP transforms Claude Code from a coding assistant into a versatile agent that can connect with any system. Start with official servers and build custom ones as your needs grow.