What Is the Model Context Protocol?
The Model Context Protocol (MCP) is an open standard created by Anthropic that defines how AI models communicate with external tools, data sources, and services. Think of it as the USB-C of the AI world: a universal interface that lets any AI model plug into any service through a standardized protocol. Before MCP, every AI tool built its own proprietary integrations. MCP changes that by providing a single, well-defined protocol that both AI clients and tool servers can implement.
MCP follows a client-server architecture. The AI application (Claude Desktop, Cursor, Claude Code) acts as the MCP client. External services expose their capabilities through MCP servers — lightweight processes that translate the MCP protocol into specific API calls, database queries, or system operations. When the AI needs to read a file from Google Drive, query a PostgreSQL database, or post a message to Slack, it communicates through the MCP protocol, and the corresponding MCP server handles the actual interaction.
MCP servers run locally on your machine by default. Your data flows directly from the MCP server to the service — it does not pass through any third-party servers. This is a critical security property that makes MCP suitable for enterprise environments.
Understanding the MCP Architecture
An MCP server exposes three types of primitives to AI clients. Tools are executable functions — they let the AI take actions like 'create a GitHub issue' or 'run a SQL query.' Resources are data sources — they let the AI read information like 'the contents of this Google Doc' or 'the schema of this database.' Prompts are reusable templates that guide the AI's behavior in specific contexts. Most automation workflows rely heavily on tools and resources.
- Tools: Executable functions the AI can call. Each tool has a name, description, and JSON Schema defining its parameters. Example: a 'search_emails' tool that accepts a query string and returns matching emails.
- Resources: Read-only data sources identified by URIs. The AI can browse available resources and read their contents. Example: 'postgres://mydb/users' exposing the users table schema and sample data.
- Prompts: Pre-defined instruction templates that help the AI understand how to use a specific server effectively. Example: a prompt template for 'analyze quarterly sales data' that structures the AI's approach.
Setting Up Your First MCP Server
Let us walk through setting up a real MCP server from scratch. We will build a server that connects to a PostgreSQL database, allowing your AI assistant to query data, inspect schemas, and generate reports — all through natural language. This is one of the most powerful and practical MCP use cases.
# Install the MCP SDK
npm init -y
npm install @modelcontextprotocol/sdk pg
npm install -D typescript @types/node @types/pg
# Create the project structure
mkdir src
touch src/index.ts
Now let us write the MCP server. The SDK provides a Server class that handles all the protocol details. You just need to define your tools and resources.
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { Pool } from "pg";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const server = new Server(
{ name: "postgres-mcp", version: "1.0.0" },
{ capabilities: { tools: {}, resources: {} } }
);
// Define a tool to run read-only SQL queries
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "query",
description: "Run a read-only SQL query against the database",
inputSchema: {
type: "object",
properties: {
sql: { type: "string", description: "The SQL query to execute" },
},
required: ["sql"],
},
},
],
}));
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "query") {
const sql = request.params.arguments?.sql as string;
// Safety: only allow SELECT statements
if (!sql.trim().toUpperCase().startsWith("SELECT")) {
return { content: [{ type: "text", text: "Error: Only SELECT queries are allowed." }] };
}
const result = await pool.query(sql);
return { content: [{ type: "text", text: JSON.stringify(result.rows, null, 2) }] };
}
throw new Error("Unknown tool");
});
// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);
Connecting MCP Servers to Your AI Client
Once your MCP server is built, you need to register it with your AI client. The configuration varies by client, but the principle is the same: you tell the client where to find the server and how to start it.
// Local MCP server (stdio transport) — .claude/settings.json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["tsx", "/path/to/postgres-mcp/src/index.ts"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
// Remote MCP server (Streamable HTTP transport, OAuth 2.1) — production recommended
{
"mcpServers": {
"github": {
"transport": "http",
"url": "https://api.githubcopilot.com/mcp/"
},
"stripe": {
"transport": "http",
"url": "https://mcp.stripe.com",
"headers": { "Authorization": "Bearer sk-..." }
}
}
}
After adding the configuration, restart your AI client. You should now be able to ask natural language questions about your database: 'Show me the top 10 customers by revenue this quarter' or 'What tables exist in the database and how are they related?' The AI will use the MCP tools to query the database and present the results.
Real-World MCP Automation Examples
The database example above is just the beginning. MCP servers can connect to virtually any service. Here are five production-ready automation patterns we see teams deploying today.
- GitHub + Linear Integration: An MCP server that reads GitHub PRs, extracts the changes, creates Linear tickets for follow-up work, and posts summaries back to the PR. Teams report saving 3-5 hours per week on project management overhead.
- Slack + Analytics Pipeline: An MCP server that monitors Slack channels for data requests, queries your analytics warehouse, generates charts, and posts them back to the channel. No more waiting for the data team to run ad-hoc reports.
- CRM Data Assistant: Connect to Salesforce or HubSpot via MCP, letting sales teams ask natural language questions about pipeline data, generate forecasts, and draft follow-up emails — all through their AI assistant.
- Infrastructure Monitoring: An MCP server connected to Datadog or Grafana that lets on-call engineers diagnose issues by asking questions like 'What changed in the payment service in the last 2 hours?' instead of manually navigating dashboards.
- Content Publishing Pipeline: An MCP server that connects to your CMS (WordPress, Sanity, Contentful), letting writers draft content in AI, review it, and publish directly — including image optimization and SEO metadata generation.
Tip: Start with read-only MCP servers. Get comfortable with AI querying your data before you give it write access. You can always add mutation tools later once you have established trust in the workflow.
Security Best Practices for MCP Servers
Security is the most important consideration when building MCP servers, especially those that connect to production systems. The fundamental principle is least privilege: every MCP server should have the minimum permissions required for its specific use case. A server that generates analytics reports should have read-only database access. A server that creates GitHub issues should not have permission to merge PRs or modify repository settings.
- Use read-only credentials wherever possible. Create dedicated database users with SELECT-only permissions for analytics MCP servers.
- Implement input validation in every tool handler. Never pass user input directly to shell commands or SQL queries without sanitization.
- Set rate limits on MCP tool calls to prevent runaway automation. A bug in your prompting should not result in 10,000 API calls.
- Log every tool invocation with the full parameters. You need an audit trail for debugging and compliance.
- Use environment variables for all secrets. Never hardcode API keys, database passwords, or tokens in your MCP server code.
- Run MCP servers in containers or sandboxed environments in production to limit blast radius if something goes wrong.
- For remote MCP servers, implement OAuth 2.1 with PKCE before exposing any endpoint. A February 2026 security scan of the MCP registry found over 8,000 servers with no authentication whatsoever — do not be one of them. Dynamic client registration is now standard; client secrets alone are not sufficient.
Warning: Be extremely careful with MCP servers that have write access to production systems. A misinterpreted natural language instruction could result in data modification or deletion. Always implement confirmation steps for destructive operations.
Building Chained Workflows
The real power of MCP emerges when you chain multiple servers together. A single AI conversation can span multiple services: read data from your database, generate a report, save it to Google Drive, and send a Slack notification — all in one interaction. The AI orchestrates the workflow by calling tools from different MCP servers in sequence.
To build effective chained workflows, configure multiple MCP servers simultaneously in your client. Give each server a clear, descriptive name so the AI understands which server to use for each step. Write clear tool descriptions that explain not just what each tool does, but when it should be used. The AI uses these descriptions to plan its multi-step workflows.
// Multi-server configuration for a chained workflow
{
"mcpServers": {
"analytics-db": {
"command": "npx",
"args": ["tsx", "./mcp/analytics-db.ts"],
"env": { "DATABASE_URL": "postgresql://readonly@analytics:5432/warehouse" }
},
"google-drive": {
"command": "npx",
"args": ["tsx", "./mcp/google-drive.ts"],
"env": { "GOOGLE_CREDENTIALS_PATH": "./credentials.json" }
},
"slack": {
"command": "npx",
"args": ["tsx", "./mcp/slack.ts"],
"env": { "SLACK_BOT_TOKEN": "xoxb-your-token" }
}
}
}
Debugging MCP Servers
Debugging MCP servers can be tricky because they communicate over stdio, making traditional console.log debugging difficult. The MCP SDK provides an Inspector tool that lets you test your servers interactively. Run your server with the inspector to see exactly what messages are being exchanged between client and server.
# Use the MCP Inspector to debug your server
npx @modelcontextprotocol/inspector npx tsx ./src/index.ts
# This opens a web interface where you can:
# - List available tools and resources
# - Call tools with custom parameters
# - See the raw JSON-RPC messages
# - Verify your server's responses
Common debugging issues include: tools not appearing in the client (usually a naming or registration issue), tool calls returning errors (check your input validation and error handling), and timeout errors (MCP has default timeouts that you may need to increase for long-running operations like database queries on large tables).
What Is Next for MCP
MCP has matured rapidly into a cross-vendor standard. As of March 2026, the protocol surpassed 97 million monthly SDK downloads and 81,000 GitHub stars — metrics that confirm it has moved from Anthropic experiment to industry infrastructure. The official registry now lists over 10,000 servers — up from a few hundred at the protocol's launch in late 2024 — covering file systems, email, enterprise SaaS, databases, and every major cloud provider. Crucially, MCP is no longer an Anthropic-only protocol: OpenAI, Google (Gemini CLI), and most major AI clients now support MCP servers using the same configuration format, which means a server you build today works across Claude, ChatGPT plugins, Cursor, and Windsurf with zero changes.
The biggest 2026 shift is the transition to remote MCP servers via the Streamable HTTP transport. Where the examples earlier in this guide show local stdio servers, production deployments are now converging on remote servers secured with OAuth 2.1 + PKCE. Streamable HTTP works behind load balancers and proxies, supports multiple concurrent users, and eliminates the need to install anything on client machines. The CLI command is as simple as `claude mcp add --transport http github https://api.githubcopilot.com/mcp/`. If you are building a new MCP server that will be used by more than one person, start with Streamable HTTP from day one.
Two capabilities that shipped in early 2026 are worth calling out specifically. MCP Apps extended the protocol into interactive user interfaces: tools can now return rich HTML responses that render in sandboxed iframes directly inside the chat experience. This means an MCP server can return a live chart, a form, or an interactive dashboard — not just text. A data analytics server that previously returned a JSON table can now render a bar chart the user can click through. Tasks introduce a 'call-now, fetch-later' async pattern for long-running operations. A tool invocation can return a task handle immediately while the real work continues in the background — useful for operations like 'generate and email a quarterly report' or 'run a full regression test suite.'
MCP Server Cards add a discoverability layer: servers can now expose structured metadata at a `.well-known/mcp.json` URL, describing their tools, required auth scopes, and supported transports. Browsers, registries, and client auto-discovery can read this without establishing a full connection first. If you are building a server you intend to share or publish, adding a Server Card is now a best practice. The MCP registry ingests them automatically for indexing.
¿Te ha gustado esta guía?
Recibe más como esta cada semana en tu bandeja de entrada. Sin spam, cancela cuando quieras.