Model Context Protocol (MCP)
MPC is a protocol for connecting AI applications to external systems.
For example an AI application like Claude or Gemini can connect to data sources (e.g. local databases), to workflows (e.g. specialized prompts) and to tools (e.g. search engines, calculators).
MCP advantages aim to:
- reduce development time and complexity when building or integrating with an AI application
- improve capability of AI applications or agent to interact with tools on behalf of the end user
Core Concepts of MCP
Architecture
MCP follows a client-server architecture:
- an MCP host (e.g. Claude Code, Gemini CLI) establishes a connection to one ore more MCP servers.
- A MCP server is a program that provides context to MCP clients.
MCP Servers can use protocol like:
- STDIO transport for local development single-client use
- Streamable HTTP transport otherwise
Layers
- Data Layer: defines JSON-RPC based protocol for client-server communication, including lifecycle management, and core primitives, such as tools, resources, prompts and notifications.
- Transport Layer: defines the communication mechanisms and channel that enable data exchange between clients and servers, including transport-specific connection establishment, message framing, and authorization.
Data Layer
Implements a JSON-RPC based exchange protocol that defines the message structure and semantics.
This includes:
- Lifecycle management: handles connection initialization, capability negotiation, and connection termination between clients and servers
- Server features: provide core functionality including tools for AI actions, resources for context data, and prompts for interaction templates from and to the client
- Client features: Enables servers to ask the client to sample from the host LLM, elicit input from the user, and log messages to the client
- Utility features: Supports additional capabilities like notifications for real-time updates and progress tracking for long-running operations
Transport Layer
MCP supports two transport mechanisms:
- Stdio transport: Uses standard input/output streams for direct process communication between local processes on the same machine, providing optimal performance with no network overhead.
- Streamable HTTP transport: Uses HTTP POST for client-to-server messages with optional Server-Sent Events for streaming capabilities. This transport enables remote server communication and supports standard HTTP authentication methods including bearer tokens, API keys, and custom headers. MCP recommends using OAuth to obtain authentication tokens.
The transport layer abstracts communication details from the protocol layer, enabling the same JSON-RPC 2.0 message format across all transport mechanisms.
Data Layer Protocol
A core part of MCP is defining the schema and semantics between MCP clients and MCP servers. It is the part of MCP that defines the ways developers can share context from MCP servers to MCP clients.
MCP uses JSON-RPC 2.0 as its underlying RPC protocol. Client and servers send requests to each other and respond accordingly. Notifications can be used when no response is required.
Lifecycle management
MCP is a stateful protocol that requires lifecycle management. However a subset of MCP can be made stateless using the Streamable HTTP transport.
The purpose of lifecycle management is to negotiate the capabilities that both client and server support. Detailed information can be found in the specification, and the example showcases the initialization sequence.
Primitives
They define what clients and servers can offer each other.
MCP defines three core primitives that servers can expose:
- Tools: executable functions that AI applications can invoke to perform actions (e.g., file operations, API calls, database queries)
- Resources: data sources that provide contextual information to AI applications (e.g., file contents, database records, API responses)
- Prompts: reusable templates that help structure interactions with language models (e.g., system prompts, few-shot examples) → few-shot prompting