MCP Protocol
MCP (Model Context Protocol) is an open protocol designed to enable seamless integration between Large Language Model (LLM) applications and external data sources, tools, and services, similar to the HTTP protocol on the web or the SMTP protocol in email.
The MCP protocol enhances the functionality, flexibility, and scalability of LLM applications by standardizing the way models interact with external resources.


By standardizing communication rules in the AI application ecosystem, MCP provides developers with a unified, efficient, and interoperable development environment.
Core Concepts of MCP
The core of MCP is model context, i.e., all the external information and tools that an LLM needs during runtime.
By defining standardized interfaces and protocols, MCP enables LLMs to dynamically access and integrate the following:
- External Data Sources: Such as databases, APIs, document libraries, etc., providing real-time or historical data to LLMs.
- Tools and Services: Such as computing tools, search engines, third-party services, etc., extending the capabilities of LLMs.
- Context management: Dynamically maintains the LLM's conversation context to ensure coherence and consistency.
Architecture of MCP
The architecture of MCP consists of four key components:
Host: The host is the AI application that expects to obtain data from the server, such as an Integrated Development Environment (IDE), a chatbot, etc. The host is responsible for initializing and managing clients, handling user authorization, managing context aggregation, etc.
2.MCP, just like USB-C, lets different devices connect together through the same interface.

How MCP Works
MCP enables interaction between LLMs and external resources by defining standardized data formats and communication protocols.
MCP uses JSON-RPC 2.0 as its message format and communicates through standard request, response, and notification messages.
MCP supports multiple transport mechanisms, including local standard input/output (Stdio) and HTTP-based Server-Sent Events (SSE).
The MCP lifecycle includes three phases: initialization, operation, and shutdown, ensuring that connection establishment, communication, and termination all comply with the protocol specification.
The following is its workflow:
1. Context Request
The LLM application sends a context request to external resources, including the required data or service type.

- The LLM application sends requests to external resources based on task requirements.
- External resources return the required data or service results.
2. Context Integration
The LLM application integrates the context data returned by external resources into the model for generating responses or performing tasks.

- The LLM application combines external data with the model's internal knowledge to generate more accurate or richer responses.
3. Context management
MCP supports dynamic management of the LLM's conversation context, ensuring the coherence of multi-turn conversations.

- The context manager maintains the history and state of the conversation.
- The LLM application generates coherent responses based on the context.
Key Part of the Protocol - Messages
The core of MCP is the use of JSON-RPC 2.0 as the message format, providing a standardized way for communication between the client and server.
The base protocol defines three basic message types: Requests, Responses, and Notifications.
The following is a detailed description of these three message types:
1. Requests
Request messages are used to initiate an operation from the client to the server, or from the server to the client.
The structure of a request message is as follows:
{
"jsonrpc": "2.0",
"id": "string | number",
"method": "string",
"params": {
"[key: string]": "unknown"
}
}
jsonrpc: Protocol version, fixed as"2.0"。
id: A unique identifier of the request, which can be a string or a number.
method: The name of the method to call, which is a string.
params: The parameters of the method, an optional key-value object where keys are strings and values can be of any type.
2. Responses
A response message is a reply to a request, sent from the server to the client, or from the client to the server.
The structure of a response message is as follows:
{
"jsonrpc": "2.0",
"id": "string | number",
"result": {
"[key: string]": "unknown"
},
"error": {
"code": "number",
"message": "string",
"data": "unknown"
}
}
jsonrpc: Protocol version, fixed as"2.0"。
id: Corresponding to theidin the request, used to identify which request the response corresponds to.
result: If the request succeeds,resultfield contains the result of the operation, which is a key-value object.
error: If the request fails,errorfield contains error information, where:
-
code: The error code, which is a number. -
message: The error description, which is a string. -
data: Optional additional error information, which can be of any type.
code: The error code, which is a number.
message: The error description, which is a string.
data: Optional additional error information, which can be of any type.
3. Notifications
A notification message is a one-way message that does not require a reply from the receiver.
The structure of a notification message is as follows:
{
"jsonrpc": "2.0",
"method": "string",
"params": {
"[key: string]": "unknown"
}
}
jsonrpc: Protocol version, fixed as"2.0"。
method: The name of the method to call, which is a string.
params: The parameters of the method, an optional key-value object where keys are strings and values can be of any type.
Description
Requests and Responses: Requests and responses are one-to-one; after the client sends a request, the server returns a response.idfield is used to associate requests with responses.
errorfield, providing the error code and description to help developers quickly locate the problem.
Key Features of MCP
- Standardized Interface: Defines unified interfaces and protocols to ensure compatibility between LLMs and external resources.
- Dynamic Integration: Supports LLMs dynamically accessing and integrating external data sources and tools.
- Context awareness: Supports dynamic management of conversation context, improving the coherence of multi-turn conversations.
- Openness and Scalability: Supports third-party developers extending features and resources for LLM applications.
Application Scenarios of MCP
MCP is widely used in the following scenarios:
- Enhanced Question Answering Systems: Provides real-time, accurate answers by integrating external data sources.
- Intelligent Assistants: Performs complex tasks (such as booking, calculation, search, etc.) by integrating tools and services.
- Knowledge management: Provides knowledge support in professional domains by integrating document libraries and databases.
- Multi-turn conversation: Achieves coherent multi-turn conversations through context management.
Advantages and Disadvantages of MCP
Fixed size, stores elements of the same type.
- Function Extension: Significantly extends the functionality of LLM applications by integrating external resources.
- Flexibility: Supports dynamic access to and integration of various data sources and tools.
- Openness: The standardized protocol supports third-party development and integration.
High efficiency in random access of elements.
- Complexity: Requires designing and maintaining interaction logic with external resources.
- Performance overhead: Accessing external resources may introduce additional latency.
Alternatives to MCP
In some scenarios, the following alternatives can be used:
- Custom API: Develop custom API interfaces for LLM applications.
- Plugin mechanism: Use plugin mechanisms to extend the functionality of LLM applications.
- Knowledge graph: Integrate external knowledge through knowledge graphs.