Saltar al contenido principal

Configuración de MCP y andamiajes de servidor

Intermedio

Plantillas listas para copiar y conectar Claude a herramientas mediante MCP. Recórtalas a lo que necesites.

.mcp.json — declarar servidores (compartido por el proyecto)

{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "${DATABASE_URL}"]
}
}
}

:::warning Mantén los secretos fuera del archivo Referencia variables de entorno (${GITHUB_TOKEN}) — no incrustes tokens en un archivo versionado. :::

Servidor stdio mínimo (TypeScript)

Un servidor diminuto que expone una sola herramienta. Adapta el handler a tus datos.

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({ name: "echo", version: "1.0.0" });

server.tool(
"echo",
{ text: z.string().describe("Text to echo back") },
async ({ text }) => ({ content: [{ type: "text", text: `You said: ${text}` }] }),
);

await server.connect(new StdioServerTransport());

Servidor stdio mínimo (Python)

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("echo")

@mcp.tool()
def echo(text: str) -> str:
"""Echo the text back."""
return f"You said: {text}"

if __name__ == "__main__":
mcp.run() # stdio transport

Antes de publicar un servidor

Siguiente