What is MCP?
MCP (Model Context Protocol) is how AI assistants like Claude and ChatGPT call external tools. Your server exposes "tools" — functions with names, descriptions, and input schemas — and the AI model decides when to call them during a conversation.
How it works
All communication uses JSON-RPC 2.0 over HTTP POST to a single endpoint (e.g., /mcp):
initialize to establish the sessiontools/list to discover available toolstools/call with a tool name and argumentsImplementation example
app.post('/mcp', (req, res) => {
const { method, params, id } = req.body;
if (method === 'initialize') {
return res.json({ jsonrpc: '2.0', id, result: {
protocolVersion: '2024-11-05',
capabilities: { tools: {} },
serverInfo: { name: 'my-service', version: '1.0' }
}});
}
if (method === 'tools/list') {
return res.json({ jsonrpc: '2.0', id, result: {
tools: [{
name: 'search',
description: 'Search for items',
inputSchema: {
type: 'object',
properties: { query: { type: 'string' } },
required: ['query']
}
}]
}});
}
if (method === 'tools/call') {
const { name, arguments: args } = params;
return res.json({ jsonrpc: '2.0', id, result: {
content: [{ type: 'text', text: 'Search results...' }]
}});
}
res.json({ jsonrpc: '2.0', id, error: { code: -32601, message: 'Method not found' }});
});
Key concepts
- Tools: Functions your server exposes (e.g., "search", "create_invoice")
- inputSchema: JSON Schema describing what arguments each tool accepts
- Streamable HTTP: The standard transport — all messages via POST to one endpoint
- SSE: Server-Sent Events — optional, used for server-to-client streaming via GET
Spec maturity
Formal specification. MCP is maintained by Anthropic with a versioned spec. Current protocol version: 2024-11-05. Supported natively by Claude, ChatGPT, and many AI tools.
Learn more
- modelcontextprotocol.io — Official specification
- MCP TypeScript SDK — Reference implementation