MCP Protocol Specification - Deep Dive
MCP Protocol Specification - Deep Dive
Overview
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. It uses JSON-RPC 2.0 as the base messaging format.
Inspired by: Language Server Protocol (LSP) - which standardizes language support across development tools
Goal: Standardize how to integrate additional context and tools into AI application ecosystem
Protocol Version
Current Version: 2025-11-25
Versioning Format: YYYY-MM-DD (last date of backwards-incompatible changes)
Revisions:
Architecture
Communication Model
┌─────────────────────────────────────────────────────────┐
│ MCP Protocol │
│ (JSON-RPC 2.0) │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌────────────┐ │
│ │ Host │ ←───────→ │ Server │ │
│ │ (LLM App) │ │ (Context/ │ │
│ │ │ │ Tools) │ │
│ └──────────────┘ └────────────┘ │
│ │
│ Host initiates connection │
│ Server provides context/tools/prompts │
│ Bidirectional JSON-RPC messages │
│ │
└─────────────────────────────────────────────────────────┘Roles
Components
┌─────────────────────────────────────────────────────────┐
│ MCP Protocol Layers │
├─────────────────────────────────────────────────────────┤
│ │
│ 1. Base Protocol │
│ └─ JSON-RPC 2.0 message format │
│ │
│ 2. Lifecycle Management │
│ └─ Initialization, capability negotiation, │
│ session control │
│ │
│ 3. Authorization (HTTP-based) │
│ └─ Auth framework for HTTP transports │
│ │
│ 4. Server Features (MAY implement) │
│ ├─ Resources: Context and data │
│ ├─ Prompts: Template messages │
│ └─ Tools: Functions to execute │
│ │
│ 5. Client Features (MAY implement) │
│ ├─ Sampling: Server-initiated LLM interactions │
│ ├─ Roots: Filesystem/URI boundaries │
│ └─ Elicitation: User prompts from server │
│ │
│ 6. Utilities │
│ ├─ Configuration │
│ ├─ Progress tracking │
│ ├─ Cancellation │
│ ├─ Error reporting │
│ └─ Logging │
│ │
└─────────────────────────────────────────────────────────┘Message Types
1. Requests
Direction: Client → Server OR Server → Client
Structure:
{
"jsonrpc": "2.0",
"id": "string | number",
"method": "string",
"params": {
"[key: string]": "unknown"
}
}Requirements:
id MUST be string or integer (NOT null)id MUST be unique within the sessionid MUST NOT have been previously used2. Responses
Direction: Server → Client OR Client → Server
Result Response (success):
{
"jsonrpc": "2.0",
"id": "string | number",
"result": {
"[key: string]": "unknown"
}
}Requirements:
id MUST match the requestresult field MUST be includedError Response (failure):
{
"jsonrpc": "2.0",
"id": "string | number | null",
"error": {
"code": "number",
"message": "string",
"data": "unknown"
}
}Requirements:
id MUST match request (null if request was malformed)error field MUST be includedcode MUST be integermessage MUST describe the error3. Notifications
Direction: Client → Server OR Server → Client (one-way)
Structure:
{
"jsonrpc": "2.0",
"method": "string",
"params": {
"[key: string]": "unknown"
}
}Requirements:
id MUST NOT be includedServer Features
Resources
Purpose: Provide context and data for user or AI model
URI Scheme: protocol://path format
Examples:
screenshots:///latest - Latest screenshotforms:///my-form - Form definitionfile:///home/user/data.json - Local filehttps://api.example.com/data - HTTP resourceMethods:
resources/list - List all available resourcesresources/read - Read a specific resourceContent Types:
text/plain - Plain textapplication/json - JSON dataimage/png - PNG imagesapplication/pdf - PDF documentsPrompts
Purpose: Templated messages and workflows for users
Template Format:
{{variable}} syntaxExample:
{
"name": "analyze_dashboard",
"description": "Navigate to dashboard, capture screenshot, extract metrics",
"arguments": [
{"name": "dashboard_url", "required": true}
],
"template": [
"Navigate to {{dashboard_url}}",
"Take screenshot",
"Extract metrics via OCR",
"Return formatted report"
]
}Methods:
prompts/list - List all available promptsprompts/get - Get a specific promptprompts/execute - Execute a prompt (NOT in base spec, but common)Tools
Purpose: Functions for AI model to execute
Tool Schema:
{
"name": "tool_name",
"description": "What this tool does",
"inputSchema": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "Parameter description"
}
},
"required": ["param1"]
}
}Methods:
tools/list - List all available toolstools/call - Execute a toolMy Implementation:
Client Features
Sampling
Purpose: Server-initiated agentic behaviors and recursive LLM interactions
Allows server to:
Example Use Case:
Roots
Purpose: Define URI or filesystem boundaries for operations
Examples:
file:///home/user/ - Only access this [REDACTED]yhttps://api.example.com/ - Only access this APIPrevents:
Elicitation
Purpose: Server-initiated requests for additional information from users
Use Cases:
JSON Schema Usage
Supported Dialects
Default Dialect: JSON Schema 2020-12 (when no $schema field)
Explicit Dialect: Any valid JSON Schema dialect via $schema field
Supported (at least):
Example Schema
Default dialect (2020-12):
{
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "minimum": 0}
},
"required": ["name"]
}Explicit dialect (draft-07):
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "minimum": 0}
},
"required": ["name"]
}Validation Requirements
$schemaMetadata
`_meta` Property
Purpose: Reserved field for additional metadata in interactions
Format: {prefix/name}
Prefix Rules:
Reserved Prefixes:
io.modelcontextprotocol/ - MCP reserveddev.mcp/ - MCP reservedorg.modelcontextprotocol.api/ - MCP reservedcom.mcp.tools/ - MCP reservedNOT Reserved (examples):
com.example.mcp/ - Not reserved (second label is "example")custom.vendor/ - Not reserved`icons` Property
Purpose: Standardized visual identifiers for resources, tools, prompts
Icon Object:
{
"src": "URI (required)",
"mimeType": "optional MIME type",
"sizes": ["48x48", "96x96"],
"theme": "light | dark"
}Allowed `src` types:
Supported MIME Types (MUST support):
image/png - Universal compatibilityimage/jpeg / image/jpg - Universal compatibilityShould Also Support:
image/svg+xml - Scalable (but security risks)image/webp - Modern, efficientIcon Security:
Security & Trust
Key Principles
1. User Consent and Control
2. Data Privacy
3. Tool Safety
4. LLM Sampling Controls
Implementation Guidelines
Implementors SHOULD:
Version Negotiation
Process
Failure Handling
My Implementation Alignment
✅ What I Implemented Correctly
id, method, paramsid and resultcode, messagetools/list methodtools/call methodresources/list methodresources/read methodprompts/list methodprompts/get method{{variable}}⚠️ Areas for Improvement
sampling client featureroots implementationelicitation supporticons metadataprompts/execute method (only defined templates)_meta property supportTransport Layers
STDIO (Standard I/O)
Use Case: Local communication via stdin/stdout
Auth: Retrieve from environment
Authorization: NOT required (no HTTP)
HTTP
Use Case: Remote communication over HTTP/HTTPS
Auth: MCP Authorization Framework
Authorization: REQUIRED for non-public servers
Negotiation
Multiple Versions: Clients and servers MAY support multiple protocol versions simultaneously
Agreement: MUST agree on single version for session
Official SDKs
Key Insights
1. Protocol Flexibility
MCP is modular - components are optional:
This allows implementations to support exactly what they need.
2. Bidirectional Communication
Unlike pure client-server protocols, MCP is bidirectional:
This enables agentic behaviors where servers can drive workflows.
3. Open but Structured
Protocol is open source (Linux Foundation) with:
This balances openness with structure.
4. Extensible
_meta property allows custom metadata without breaking protocol:
Reserved prefixes prevent conflicts:
io.modelcontextprotocol/ for protocol useNext Steps for My Implementation
1. Add Missing Methods
prompts/execute - Run prompt templates2. Add Client Features
sampling - Server-initiated LLM callsroots - Define access boundarieselicitation - Ask user for info3. Improve Security
4. Add Metadata
icons for tools/resources/prompts_meta property supportStatus: Deep dive complete
Protocol Version: 2025-11-25
Key Insight: MCP is flexible, bidirectional, extensible protocol for AI integrations
Next: Add missing features to my implementation
Date: 2026-02-04