MCP (Model Context Protocol) Practical Guide
AI Agents have a persistent problem: every Agent needs its own custom tool integration code. Switch to a different Agent? All tool integrations need to be rewritten from scratch. MCP (Model Context Protocol) solves exactly this.
What MCP Is
MCP is an open protocol proposed by Anthropic in late 2024, positioned as the USB of AI Agents.
Just like USB lets any device connect to any computer, MCP lets any AI Agent connect to any tool.
Without MCP:
Agent A → writes its own GitHub tools
Agent B → writes its own GitHub tools (duplicated effort)
With MCP:
Agent A → MCP Client → MCP GitHub Server
Agent B → MCP Client → MCP GitHub Server (reused)Core Concepts
MCP defines three core components (see the MCP Architecture Docs):
MCP Host
The AI agent or host application in use (such as Claude Desktop, Claude Code, Codex CLI, GitHub Copilot CLI, or Cursor).
MCP Client
The protocol client running inside the Host that maintains a 1:1 session with a target MCP Server.
MCP Server
A service exposing external capabilities (Tools, Resources, Prompts). Each external system (GitHub, Slack, PostgreSQL, internal ticketing) can be wrapped once as an MCP Server.
Transports and OAuth 2.1 Authorization
The transport and authorization rules below target MCP Spec 2025-11-25 (see the Transports specification; newer 2026 revisions move per-request protocol/capability metadata into JSON-RPC _meta, so always pin your client and SDK to one concrete spec revision):
- stdio: Ideal for local CLI tools and developer machines. The Host spawns the server as a subprocess and communicates over stdin/stdout with minimal latency and no open network port.
- Streamable HTTP: Designed for remote and team-shared MCP servers, superseding the legacy SSE-only HTTP transport. After version negotiation during initialization, clients send
POSTrequests with theMCP-Protocol-Versionheader to a single HTTP endpoint, and servers respond with either standard JSON or an upgraded SSE stream.
Remote MCP servers standardize authentication on OAuth 2.1, keeping transport auth separate from protected-resource authorization:
- Require PKCE and RFC 8707 Resource Indicators (audience binding); the MCP server must validate that the token’s
audmatches itself so tokens cannot be replayed across servers or conflated with downstream credentials. - Advertise authorization servers via RFC 9728 Protected Resource Metadata, with optional RFC 7591 Dynamic Client Registration.
- Always pass access tokens in the
Authorization: Bearer <token>header; never put tokens in URL query strings.
Quick Start
Configure a Local MCP Server in Claude Desktop / CLI
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
}
}
}On macOS, Claude Desktop reads ~/Library/Application Support/Claude/claude_desktop_config.json; CLI hosts also support claude mcp add or codex mcp add. Inject secrets through environment variables or a secret manager rather than hardcoding them in committed config files.
Writing Your Own MCP Server with the TypeScript SDK
Security boundary: never expose arbitrary free-form SQL to an agent. Instead, expose parameterized, column- and row-bounded lookup tools backed by a dedicated read-only database role, enforcing tenant and authorization checks in server code (tool description is documentation, not a security boundary):
// my-mcp-server.ts (@modelcontextprotocol/sdk v1.x)
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { Pool } from "pg";
import { z } from "zod";
// Fail fast if required read-only DB URL or trusted tenant binding is missing
// (local stdio binds tenant at launch; remote multi-tenant derives it from verified OAuth claims,
// never from caller-supplied tool arguments)
const dbUrl = process.env.DB_READONLY_URL;
const tenantId = process.env.TENANT_ID;
if (!dbUrl || !tenantId) {
throw new Error("Missing required DB_READONLY_URL or TENANT_ID");
}
const pool = new Pool({ connectionString: dbUrl });
const server = new McpServer({
name: "order-lookup-server",
version: "1.0.0",
});
server.registerTool(
"get_order_summary",
{
description: "Fetch a read-only order summary for the authorized tenant (max 1 row)",
inputSchema: {
orderId: z.string().uuid(),
},
},
async ({ orderId }) => {
const { rows } = await pool.query(
`SELECT id, status, total_cents, created_at
FROM orders
WHERE tenant_id = $1 AND id = $2
LIMIT 1`,
[tenantId, orderId],
);
return {
content: [{ type: "text", text: JSON.stringify(rows[0] ?? null) }],
};
},
);
const transport = new StdioServerTransport();
await server.connect(transport);Real Value
Tool Reuse
Before: every agent project had to re-implement GitHub, Jira, or database integrations.
Now: build an MCP Server once and reuse it across every MCP-compatible client, reducing integration overhead from $M \times N$ to $M + N$.
One internal database MCP Server:
- Cursor / VS Code → inspect schemas directly
- Claude Code → diagnose slow queries alongside migration files
- Codex CLI → verify data consistency inside sandboxed tasksTool Ecosystem
The MCP ecosystem now functions like an npm-style registry for agent tools. Reference implementations live in modelcontextprotocol/servers, and major cloud and SaaS vendors (GitHub, Cloudflare, Sentry, Linear, Stripe, etc.) ship first-party hosted remote MCP servers.
Enterprise Internal Tool Integration
Internal systems (CRMs, read-only databases, internal wikis, deployment portals) can be wrapped once behind MCP with unified OAuth 2.1 identity and read/write permission tiers, exposing them safely to every internal agent without re-integrating per model or client.
Comparison with Other Approaches
| Dimension | MCP | Vendor-Private Plugins | Framework-Bound Tools (e.g., LangChain) |
|---|---|---|---|
| Governance | Initiated by Anthropic, open community standard | Single model vendor | Single framework |
| Standardization | High (open JSON-RPC protocol) | Platform-specific | Language/framework-locked |
| Reuse | Cross-client and cross-model | Single platform only | Rewrite on framework change |
| Remote security | Streamable HTTP + OAuth 2.1 | Vendor-defined | DIY per application |
MCP’s core advantage is openness and neutrality: it decouples tool integration from any single model vendor or orchestration framework.
Current State and Limitations
Current State
By 2026, MCP has become the default tool-integration protocol across mainstream AI coding and general-purpose agents:
- Native support in Claude Desktop, Claude Code, OpenAI Codex, GitHub Copilot CLI, Cursor, and VS Code
- Remote Streamable HTTP + OAuth 2.1 enables zero-local-process, one-click SaaS connections
- Official and community SDKs cover TypeScript, Python, Go, Rust, and Java
Limitations
- Security boundaries: Local stdio servers inherit host process privileges, while overly broad remote OAuth scopes can cause unintended writes; enforce least privilege and read/write separation.
- Context bloat: Attaching too many MCP servers injects huge tool schemas into the system prompt, burning tokens and hurting tool selection accuracy; scope servers per project.
- End-to-end debugging: Tracing failures across Host → Client → Server → downstream API still requires disciplined structured logging.
Conclusion
MCP’s significance is moving the AI tool ecosystem from closed to open.
Just as REST APIs enabled web service interoperability, MCP decouples AI agents from tool implementations. When building or adopting AI agents, treat MCP as the default tool layer and enforce least privilege, scoped server loading, and OAuth 2.1 in production.