The Quick TL;DR:
The Model Context Protocol (MCP) is an open standard that connects LLM applications (Claude Desktop, Cursor, AI agents) to external tools, databases, and local files via a uniform JSON-RPC 2.0 interface.Instead of writing brittle glue code for every combination of AI model and developer tool (an $M \times N$ nightmare), you write one MCP server that any compliant AI client can immediately discover and run.
The Problem: The $M \times N$ Integration Nightmare
Imagine your engineering team wants their AI assistants to access 4 internal systems:
- Staging PostgreSQL Database (to inspect schemas)
- Kubernetes Pod Log Streamer (to debug crashed containers)
- Jira Issue Tracker (to summarize tickets)
- Local Git Workspace (to inspect diffs)
If your team uses 3 different AI environments—Cursor for frontend developers, Claude Desktop for architects, and an internal CLI agent for DevOps—you previously had to build and maintain $4 \times 3 = 12$ custom integrations:
[Cursor IDE] ─── (OpenAI Function Wrapper) ───► [Postgres DB]
[Claude Desktop] ─── (Claude Desktop Config) ───► [Kubernetes Logs]
[Internal CLI] ─── (LangChain Tool Adapter) ───► [Jira API]
... 12 custom glue scripts!
Every time a new AI client entered the market, you had to rewrite your tool wrappers from scratch.
The Solution: MCP as the "USB-C Port" for AI
Anthropic designed the Model Context Protocol to transform this fragmented mess into an $M + N$ universal ecosystem:
┌───────────────────────────────┐
│ AI Host Applications (Clients)│
│ Claude Desktop • Cursor • CLI│
└───────────────┬───────────────┘
│
Standardized MCP
(JSON-RPC 2.0 Layer)
│
┌───────────────▼───────────────┐
│ Decoupled MCP Servers │
│ PostgreSQL • Git • Docker │
└───────────────────────────────┘
You build your tool once as an MCP server. Now, any MCP client in the world can discover it, query its capabilities, and execute it safely.
The 3 Core Primitives of MCP
Every MCP server exposes functionality through three distinct primitives:
| Primitive | What It Does | Analogy | Client Can Modify? |
|---|---|---|---|
| Resources | Read-only contextual data (files, schemas, logs) |
GET request / REST read |
No (Safe & idempotent) |
| Tools | Executable actions that create side effects (queries, git commits, API calls) |
POST request / RPC execution |
Yes (Requires user approval) |
| Prompts | Pre-engineered prompt templates with dynamic arguments | Slash commands / Saved templates | Context injection |
How It Works Under the Hood (The Handshake)
When an AI host (like Claude or Cursor) starts an MCP server, they communicate over standard input/output (stdio) or Server-Sent Events (SSE) using clean JSON-RPC 2.0 messages.
1. Capability Negotiation
The client asks: "What capabilities do you support?"
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"clientInfo": { "name": "cursor", "version": "1.0.0" }
}
}
The server responds with its supported features:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"tools": { "listChanged": true },
"resources": { "subscribe": true }
},
"serverInfo": { "name": "postgres-inspector", "version": "1.0.0" }
}
}
2. Discovering Available Tools
The AI client asks what tools the server provides:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}
The server returns strict JSON-schema parameter definitions:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "explain_query",
"description": "Runs EXPLAIN ANALYZE on a PostgreSQL SQL query",
"inputSchema": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "The SQL query to analyze" }
},
"required": ["query"]
}
}
]
}
}
Building a Minimal Production MCP Server in TypeScript
Here is a complete, working MCP server built with the official @modelcontextprotocol/sdk:
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
// 1. Initialize Server Metadata
const server = new Server(
{ name: 'devscampus-system-tools', version: '1.0.0' },
{ capabilities: { tools: {} } }
);
// 2. Register Available Tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'calculate_uptime',
description: 'Calculates system SLA uptime percentage from incident minutes',
inputSchema: {
type: 'object',
properties: {
downtimeMinutes: { type: 'number', description: 'Minutes of outage in a 30-day month' },
},
required: ['downtimeMinutes'],
},
},
],
}));
// 3. Handle Tool Execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === 'calculate_uptime') {
const minutes = Number(request.params.arguments?.downtimeMinutes ?? 0);
const totalMinutes = 30 * 24 * 60; // 43,200 min in a month
const uptimePct = (((totalMinutes - minutes) / totalMinutes) * 100).toFixed(4);
return {
content: [
{
type: 'text',
text: `SLA Uptime: ${uptimePct}% (${minutes} minutes of downtime out of ${totalMinutes} total minutes)`,
},
],
};
}
throw new Error(`Tool not found: ${request.params.name}`);
});
// 4. Start Server on stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);
Critical Production Security Rules
When deploying MCP servers in production, keep these 3 safeguards in mind:
-
Never log to
stdout: Thestdiotransport uses standard output strictly for JSON-RPC messages. Callingconsole.log("Debug info")will corrupt the JSON stream and crash the AI client. Always useconsole.error()for internal logs. -
Prevent Path Traversal: When serving resources from disk, always validate that requested file paths stay strictly within an approved root directory using
path.resolve(). -
Human-in-the-Loop for Write Tools: MCP clients will prompt developers before running destructive tools (like
DROP TABLEorgit push --force). Never bypass confirmation on mutating actions.
Wrapping Up & Next Steps
The Model Context Protocol solves the biggest friction point in building AI-assisted engineering workflows. Once you understand the host-client-server architecture, connecting your internal tools to Claude, Cursor, and custom agents becomes a breeze.
👉 Want to go deeper?
We published the complete architectural blueprint—including 5 production code examples, RAG integration patterns, and debugging runbooks for MCP error codes -32601 and buffer deadlocks—on DevsCampus.
Found this breakdown helpful? Share it with your team or leave a comment below with what MCP servers you're building!
Top comments (0)