Model Context Protocol: The Universal AI Integration Layer
MCP is becoming the standard for connecting AI assistants to tools, databases, and APIs. This guide explains the protocol from first principles and walks through building your first MCP server.
Model Context Protocol: The Universal AI Integration Layer
Model Context Protocol (MCP) is an open standard that defines how AI assistants connect to external tools, data sources, and APIs. Think of it as USB-C for AI — a single standard that works everywhere.
Why MCP Matters
Before MCP, every AI tool had its own bespoke plugin system. Claude had plugins, ChatGPT had plugins, Cursor had extensions. Each was incompatible with the others, and every developer had to integrate the same tools multiple times.
MCP solves this with a universal client-server protocol:
Core Concepts
Tools
Functions the AI can call. They have a name, description, and JSON Schema input definition.
Resources
Data the AI can read — files, database rows, API responses. Identified by URI.
Prompts
Pre-defined prompt templates that users can invoke.
Your First MCP Server
Install the SDK:
npm install @modelcontextprotocol/sdk
Create server.ts:
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
const server = new Server(
{ name: 'my-server', version: '1.0.0' },
{ capabilities: { tools: {} } }
);
// List available tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: 'get_weather',
description: 'Get current weather for a city',
inputSchema: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name' }
},
required: ['city']
}
}]
}));
// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === 'get_weather') {
const { city } = request.params.arguments as { city: string };
// Call your weather API here
const weather = await fetchWeather(city);
return { content: [{ type: 'text', text: JSON.stringify(weather) }] };
}
throw new Error('Tool not found');
});
// Start server
const transport = new StdioServerTransport();
await server.connect(transport);
Connect to Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"my-server": {
"command": "node",
"args": ["/path/to/dist/server.js"]
}
}
}
Restart Claude Desktop. Your tools are now available.
Real-World Use Cases
Security Considerations
MCP servers execute with real permissions. Always: