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 <nombre> -- <comando> [args...] # Ejemplo: servidor de PostgreSQL claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres \ "postgresql://localhost/midb" # Ejemplo: servidor de filesystem (solo lectura) claude mcp add files -- npx -y @modelcontextprotocol/server-filesystem \ /ruta/al/directorio
Popular MCP servers
Managing MCP servers
# Listar servidores configurados claude mcp list # Ver detalles de un servidor claude mcp get postgres # Eliminar un servidor claude mcp remove postgres # Dentro de Claude Code, ver servidores activos: /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.
# Añadir servidor a nivel de usuario (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: "mi-servidor", version: "1.0.0" }, {
capabilities: { tools: {} }
});
server.setRequestHandler("tools/list", async () => ({
tools: [{
name: "saludar",
description: "Saluda al usuario",
inputSchema: {
type: "object",
properties: { nombre: { type: "string" } },
required: ["nombre"]
}
}]
}));
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "saludar") {
return { content: [{ type: "text", text: `Hola, ${request.params.arguments.nombre}!` }] };
}
});
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:
# Servidor local (stdio)
{
"command": "node",
"args": ["./mi-servidor-mcp.js"]
}
# Servidor remoto (HTTP/SSE)
{
"url": "https://mi-servidor.com/mcp",
"headers": { "Authorization": "Bearer TOKEN" }
}