Back to series
· 13 min read

What Is MCP? A Detailed Explanation of the Model Context Protocol


1. What Is MCP?

MCP, short for Model Context Protocol, is an open protocol introduced by Anthropic, designed to solve the problem of the lack of a unified connection standard between AI applications and external systems.

Before a unified protocol existed, AI applications usually had to develop integration logic separately for each different data source and tool:

  • Connecting to a database required writing a separate database query interface.
  • Connecting to GitHub required implementing GitHub API calls separately.
  • Connecting to local files required handling file reading and permissions separately.
  • Connecting to internal enterprise systems required developing dedicated adapters.
  • When switching AI applications, much of the integration code had to be rewritten.

This approach leads to a great deal of duplicated work, and integration is hard to reuse across systems.

The core idea of MCP is:

Define a unified communication protocol that lets AI applications connect to various external capabilities through standardized interfaces.

MCP can be thought of as a universal connection layer between AI applications and the outside world.

For example, an AI assistant can connect to the following through MCP:

External System Capabilities Provided by MCP
File System Read, search, and manage files
GitHub Query repositories, read code, create issues
Database Query data, read table schemas
Browser Retrieve web page content, perform browser operations
Enterprise Knowledge Base Search documents, retrieve business knowledge
Project Management System Query tasks, create tickets
Cloud Platform Query resources, perform cloud service operations

MCP itself is not responsible for implementing these business functions; rather, it specifies how AI applications and these functions communicate in a standardized way.

2. Why Do We Need MCP?

2.1 Problems with Traditional Integration

Suppose an AI application needs to connect to 5 external systems, each requiring a dedicated interface to be developed.

flowchart TD
    A["AI Application"] --> B["GitHub Dedicated Interface"]
    A --> C["Database Dedicated Interface"]
    A --> D["File System Dedicated Interface"]
    A --> E["Browser Dedicated Interface"]
    A --> F["Enterprise Knowledge Base Dedicated Interface"]

    B --> G["GitHub"]
    C --> H["Database"]
    D --> I["File System"]
    E --> J["Browser"]
    F --> K["Enterprise Knowledge Base"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style I fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style J fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

This approach has several problems:

1. Duplicated interface development

Every AI application has to write adapter code for each different external system.

2. Integration logic is hard to reuse

The same GitHub interface may need to be implemented repeatedly across different AI applications.

3. High system coupling

AI applications need to understand the APIs, authentication methods, parameter formats, and response structures of different external services.

4. Growing expansion costs

As the number of tools and AI applications grows, integration relationships become complicated.

With M AI applications and N external systems, the traditional approach may, in the worst case, require maintaining M × N sets of integration relationships.

2.2 The MCP Solution

MCP introduces a unified protocol between AI applications and external systems.

flowchart TD
    A["AI App A"] --> D["MCP Client"]
    B["AI App B"] --> E["MCP Client"]
    C["AI App C"] --> F["MCP Client"]

    D --> G["MCP Protocol Layer"]
    E --> G
    F --> G

    G --> H["MCP Server: GitHub"]
    G --> I["MCP Server: Database"]
    G --> J["MCP Server: File System"]
    G --> K["MCP Server: Knowledge Base"]

    H --> L["GitHub API"]
    I --> M["Database"]
    J --> N["Local Files"]
    K --> O["Knowledge Base"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style C fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#EAF3EC,stroke:#83A995,color:#315D49
    style J fill:#EAF3EC,stroke:#83A995,color:#315D49
    style K fill:#EAF3EC,stroke:#83A995,color:#315D49
    style L fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style M fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style N fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style O fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

MCP transforms integration relationships from a large number of bespoke interfaces into a standardized protocol interface.

Its core value includes:

  • Standardization: A unified message format, capability description, and invocation method.
  • Decoupling: AI applications do not need to directly understand the underlying API of each external system.
  • Reuse: The same MCP Server can be used by multiple compatible clients.
  • Extensibility: When adding new external capabilities, the corresponding MCP Server can be developed independently.
  • Composability: A single AI application can connect to multiple MCP Servers at the same time.

Note that MCP does not mean that all integrations no longer require adaptation. Different services still need their own MCP Server implementations; what the protocol unifies is the communication method, not the business logic.

III. The Overall Architecture of MCP

MCP adopts a three-layer architecture of Host, Client, and Server.

The responsibilities of these three roles are not the same.

3.1 Host: The Host Application

The Host is the AI application that users actually use, and it is also the coordinator of the entire MCP system.

For example:

  • Claude Desktop
  • AI features in VS Code
  • Cursor
  • Other AI applications that support MCP

The Host is mainly responsible for:

  1. Managing user interaction.
  2. Managing large model calls.
  3. Creating and managing MCP Clients.
  4. Managing MCP Server connections.
  5. Controlling tool permissions and user authorization.
  6. Aggregating external data and building model context.
  7. Deciding whether to allow sensitive operations to be executed.

A Host can typically manage multiple MCP Clients at the same time, with each Client corresponding to one MCP Server.

3.2 Client: The Protocol Client

The MCP Client is the component inside the Host responsible for protocol communication.

It is responsible for:

  • Establishing connections with MCP Servers.
  • Sending requests in the protocol format.
  • Receiving and parsing responses.
  • Discovering the tools, resources, and prompt templates provided by the Server.
  • Handling protocol capability negotiation and related notifications.
  • Passing the data returned by the MCP Server to the Host.

A single Host can contain multiple MCP Clients.

Usually, one MCP Client corresponds to one MCP Server, rather than one Client managing all Servers at the same time.

3.3 Server: The Protocol Server

An MCP Server is a service component that provides capabilities to the outside world.

It encapsulates a specific business system into a standard MCP interface.

For example, a GitHub MCP Server can provide:

  • Querying repositories.
  • Reading files.
  • Querying commit records.
  • Creating Issues.
  • Querying Pull Requests.

A database MCP Server can provide:

  • Query the database schema.
  • Execute read-only SQL.
  • Query business data.
  • Get table field information.

An MCP Server can run locally or be deployed on a remote server.

3.4 Relationship of the Three-Layer Architecture

flowchart TD
    A["User"] --> B["Host: AI host application"]

    subgraph HOST["Host process"]
        B --> C["Large model"]
        B --> D["MCP Client A"]
        B --> E["MCP Client B"]
        B --> F["MCP Client C"]
    end

    D <--> G["MCP Server A"]
    E <--> H["MCP Server B"]
    F <--> I["MCP Server C"]

    G --> J["GitHub API"]
    H --> K["Database"]
    I --> L["File system"]

    style A fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style B fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#EAF3EC,stroke:#83A995,color:#315D49
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#EAF3EC,stroke:#83A995,color:#315D49
    style J fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style L fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

It is important to understand:

  • Host is the application and coordination layer.
  • Client is the protocol communication layer.
  • Server is the capability-providing layer.

An MCP Server does not directly control the large model, nor should it have all of the Host's conversation context by default. The Host is responsible for controlling which context and requests can be passed to a specific Server.

4. The Three Core Capabilities of MCP

The three most important foundational capabilities of an MCP Server are:

  1. Tools: Tools.
  2. Resources: Resources.
  3. Prompts: Prompt templates.

Each solves a different kind of problem.

4.1 Tools: Tool Invocation

Tools are among the most important capabilities in MCP.

This allows an MCP Server to expose executable operations to AI applications.

For example:

Tool Name Function
search_repositories Search code repositories
get_file_contents Read files
create_issue Create Issue
query_database Query database
search_documents Search knowledge base

A Tool usually includes:

  • name: The tool name.
  • description: A description of the tool's functionality.
  • inputSchema: The JSON Schema for input parameters.
  • annotations: Optional hints about the tool's behavior.

For example, a tool that queries user information:

{
  "name": "get_user",
  "description": "根据用户 ID 查询用户信息",
  "inputSchema": {
    "type": "object",
    "properties": {
      "user_id": {
        "type": "string",
        "description": "用户 ID"
      }
    },
    "required": ["user_id"]
  }
}

An MCP Client can obtain tool definitions through the tool discovery interface, and then provide suitable tool information to the large model.

When the model decides to call a tool, the Host uses the tool call request generated by the model and, after permission checks, has the MCP Client send the call request to the MCP Server.

Typical call flow:

flowchart TD
    A["User asks a question"] --> B["Host submits the question to the LLM"]
    B --> C["Model determines whether a tool is needed"]
    C --> D["Select an MCP Tool"]
    D --> E["Generate the tool name and parameters"]
    E --> F["Host validates the tool call request"]
    F --> G{"Is execution permitted?"}
    G -->|"Permitted"| H["MCP Client sends tools/call"]
    G -->|"Denied"| I["Return permission-denied result"]
    H --> J["MCP Server executes the business logic"]
    J --> K["Return the tool execution result"]
    K --> L["Host hands the result to the model"]
    L --> M["Model generates the final answer"]

    style A fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#EAF3EC,stroke:#83A995,color:#315D49
    style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style J fill:#EAF3EC,stroke:#83A995,color:#315D49
    style K fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style L fill:#EAF3EC,stroke:#83A995,color:#315D49
    style M fill:#DCEFE5,stroke:#4F8B70,color:#24563F

There is an important distinction here:

MCP Tool execution is not carried out directly by the large model.

The large model is responsible for understanding the task, selecting tools, and generating parameters; the Host and MCP Client handle the protocol calls; the MCP Server carries out the actual business logic.

The fact that the large model issues a call request does not mean that the request has been authorized for execution.

4.2 Resources: Resource Access

Resources are used to provide context data to AI applications.

They address the question:

What external information can an AI application read?

For example:

  • Contents of local files.
  • Database table schemas.
  • Project documentation.
  • Data returned by APIs.
  • Log files.
  • Material in an enterprise knowledge base.

A Resource is usually identified by a URI.

For example:

file:///workspace/project/README.md
db://production/schema/users
knowledge://company/engineering/architecture

These URIs are only examples of resource identifiers; the specific format is determined by the implementation of the MCP Server.

Resources usually contain:

Field Description
uri Unique resource identifier
name Resource name
description Resource description
mimeType Resource content type
annotations Optional resource annotations

Common resource operations include:

  • resources/list: discover available resources.
  • resources/read: read a specified resource.
  • resources/subscribe: subscribe to resource updates (requires Server support).

Two concepts need to be distinguished:

A Resource is a data access capability; a Tool is an operation execution capability.

For example:

  • Reading a database table schema can be designed as a Resource.
  • Querying a database by condition can be designed as a Tool.
  • Creating a database record can be designed as a Tool.

This is not an absolute design constraint; the same business capability can be designed as different MCP primitives depending on the interaction model and the usage scenario.

In addition, the specific way Resources are read is determined by the Host. Some Hosts actively select resources and place them into the context, while others fetch content based on resource URIs or user interaction.

It should not be simplistically assumed that the large model can automatically read all resources of an MCP Server.

4.3 Prompts: Prompt Templates

Prompts are used to provide reusable prompt templates to AI applications.

The problem they solve is:

How can prompts for specific business scenarios be standardized, structured, and reused?

For example, a code review MCP Server can provide:

  • review_code: Code review template.
  • explain_code: Code explanation template.
  • generate_tests: Test case generation template.

A Prompt can include:

  • Template name.
  • Template description.
  • Parameter definitions.
  • Message content.
  • Role information.

For example:

{
  "name": "review_code",
  "description": "审查代码中的潜在问题",
  "arguments": [
    {
      "name": "language",
      "description": "编程语言",
      "required": true
    },
    {
      "name": "code",
      "description": "待审查的代码",
      "required": true
    }
  ]
}

Common operations:

  • prompts/list: Discover prompt templates.
  • prompts/get: Retrieve a specified prompt template and its parameterized content.

Differences between Prompt and Tool:

Comparison dimension Prompts Tools
Core function Provide prompt templates Execute external operations
Main content Messages and template parameters Function names and input parameters
Whether it directly performs business operations Usually no Can execute
Typical use Code review, analysis tasks Query data, create tasks

A Prompt is not necessarily a system prompt that an MCP Server automatically injects into the model context. It is usually discovered, selected, and retrieved by the Host, and then handed to the model according to the application's interaction method.

4.4 Comparison of the Three Core Capabilities

Capability Problem solved Typical operations
Tools How to perform operations tools/list, tools/call
Resources How to obtain data resources/list, resources/read
Prompts How to reuse prompt templates prompts/list, prompts/get

This can be understood in one sentence:

  • Tools: enable AI to do things.
  • Resources: enable AI to obtain information.
  • Prompts: enable AI to reuse task templates.

5. MCP Communication Mechanism

MCP does not simply define a few API interfaces; it also specifies message formats, request-response patterns, protocol versions, capability discovery, and transport methods.

5.1 JSON-RPC 2.0

MCP's base message protocol uses JSON-RPC 2.0.

JSON-RPC is a lightweight remote procedure call protocol that describes requests, responses, and notifications using JSON objects.

A typical JSON-RPC request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list",
  "params": {}
}

Field descriptions:

Field Purpose
jsonrpc Protocol version, usually 2.0
id Request identifier, used to match responses
method Name of the requested method
params Request parameters

The corresponding response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": []
  }
}

JSON-RPC also supports error responses:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}

Common error fields:

  • code: Error code.
  • message: Error description.
  • data: Optional additional error information.

Besides requests and responses, JSON-RPC also supports Notification.

A Notification does not contain an id, so the receiver does not need to return a corresponding response.

For example:

{
  "jsonrpc": "2.0",
  "method": "notifications/progress",
  "params": {
    "progress": 50,
    "total": 100
  }
}

It is suitable for scenarios such as progress notifications and resource change notifications that do not require a direct response.

Note: MCP defines its own methods, parameter structures, and semantics on top of JSON-RPC; not every arbitrary JSON-RPC service can directly become an MCP Server.

5.2 MCP Requests and Responses

A typical tool call involves the following process:

sequenceDiagram
    participant U as User
    participant H as Host
    participant L as LLM
    participant C as MCP Client
    participant S as MCP Server
    participant E as External System

    U->>H: Make business request
    H->>L: Provide question and available tool information
    L-->>H: Return tool call intent and parameters
    H->>H: Validate permissions and parameters
    H->>C: Initiate tool call
    C->>S: tools/call
    S->>E: Execute business operation
    E-->>S: Return business result
    S-->>C: Return MCP result
    C-->>H: Return tool execution result
    H->>L: Provide tool result
    L-->>H: Generate final answer
    H->>U: Display result

Three layers need to be distinguished here:

  1. Model layer: Decides whether a tool needs to be called and what parameters to use.
  2. Protocol layer: Communicates using the message format defined by MCP.
  3. Business layer: The MCP Server calls databases, APIs, or other systems to perform the actual operation.

These three layers collaborate with one another, but their responsibilities must not be confused.

5.3 Capability Discovery and Negotiation

MCP does not require clients to hard-code all Server capabilities in advance.

Through the discovery mechanism specified by the protocol, clients can learn which functions the server supports.

For example, tool discovery typically uses:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list",
  "params": {}
}

The server returns a list of tools along with their descriptions and input parameter Schemas.

In terms of capability negotiation, MCP confirms the capabilities supported by both sides according to the specific protocol version.

There is a version difference to note here:

  • Earlier MCP versions use initialization interactions such as initialize and notifications/initialized, and negotiate capabilities within the session.
  • The 2026-07-28 version of the specification has been adjusted to a stateless protocol core, using metadata carried in requests to describe the protocol version and client capabilities, and introducing server/discover for optional preliminary discovery.

Therefore, the old initialization flow cannot be directly treated as a flow that all new MCP implementations must adopt. Actual development must be based on the protocol version jointly supported by the client and server.

Six. MCP Transport Methods

MCP separates protocol messages from the underlying transport mechanism.

This means the same MCP messages can be communicated over different transports.

Currently, two transport methods are mainly considered:

6.1 STDIO

STDIO is the standard input/output transport method.

Usually used for local MCP Servers.

The Host starts the MCP Server process and communicates through:

  • stdin: Send messages to the Server.
  • stdout: Receive messages returned by the Server.
  • stderr: Output logs and diagnostic information.

Communication relationship:

flowchart LR
    A["Host process"] -->|"stdin write request"| B["MCP Server process"]
    B -->|"stdout returns response"| A
    B -->|"stderr output logs"| C["Logging system"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

STDIO features:

  • No need to start an HTTP service.
  • Communication between local processes.
  • Does not depend on a network connection.
  • Low latency.
  • Suitable for local tools and development environments.

Pay special attention:

Standard output in the STDIO channel must be used for protocol messages.

If the MCP Server outputs ordinary logs directly to stdout, it may break message parsing. Therefore, diagnostic logs should generally be output to stderr.

6.2 Streamable HTTP

Streamable HTTP is a transport method for remote MCP Servers.

The MCP Client communicates with the remote server over HTTP.

It is suitable for:

  • Cloud MCP services.
  • Enterprise internal MCP services.
  • Tool services shared by multiple users.
  • Scenarios requiring unified authentication and access control.

Typical communication relationship:

flowchart TD
    A["AI Host"] --> B["MCP Client"]
    B --> C["HTTP POST request"]
    C --> D["Streamable HTTP Endpoint"]
    D --> E["MCP Server"]
    E --> F["External API / database"]

    F --> E
    E --> D
    D -->|"JSON response or streaming events"| B

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#EAF3EC,stroke:#83A995,color:#315D49
    style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

Main features of Streamable HTTP:

  1. Uses HTTP for requests and responses.
  2. Supports ordinary JSON responses.
  3. Can use Server-Sent Events (SSE) to implement streaming messages.
  4. Suitable for remote deployment and service-oriented management.
  5. Can be combined with HTTP authentication and authorization mechanisms.

It is important to distinguish:

Streamable HTTP is the transport method in the current specification; the earlier HTTP+SSE transport scheme is a design from historical versions, and the two cannot simply be regarded as completely identical implementations.

6.3 Comparison of the Two Transport Methods

Comparison dimension STDIO Streamable HTTP
Communication scope Local processes Local or remote services
Communication mechanism Standard input/output HTTP
Deployment method Start a child process Deploy an HTTP service
Network dependency Not required Required for remote deployment
Authentication method Usually uses local environment credentials Can be combined with HTTP authentication
Typical scenarios Local files, development tools Cloud APIs, enterprise services

Which method to choose mainly depends on the deployment environment, access scope, security requirements, and operations model.

VII. A Complete MCP Workflow

The following uses the example of a user asking an AI assistant to query GitHub repository information to outline the complete process.

Suppose the user asks:

“Query the recent commit history of a GitHub repository and summarize the recent code changes.”

The whole process can be broken down into several stages.

7.1 Stage One: Establish Connection and Discover Capabilities

The Host creates an MCP Client and connects to the GitHub MCP Server.

Both sides complete the necessary version and capability discovery according to the MCP protocol version used.

The Client obtains the list of tools supported by the Server.

For example:

search_repositories
get_repository
list_commits
get_file_contents

7.2 Stage Two: The Model Understands the Task

The Host provides the user's question and the applicable tool descriptions to the large model.

After analyzing the task, the model determines that list_commits needs to be called.

It then generates the tool parameters:

{
  "owner": "example",
  "repo": "project",
  "per_page": 10
}

7.3 Phase 3: Executing the Tool Call

The Host validates the call request generated by the model:

  • Does the tool exist?
  • Do the parameters conform to the Schema?
  • Does the current user have permission?
  • Is user confirmation required?
  • Has the call limit been exceeded?

Once the checks pass, the MCP Client calls the Server's tools/call method.

7.4 Phase 4: Fetching External Data

The MCP Server calls the GitHub API to retrieve the most recent commit records.

It then converts the results into the response structure defined by MCP and returns them to the Client.

7.5 Phase 5: The Model Generates the Result

The Host hands the tool results to the large model.

Based on the commit records, the model performs its analysis and finally outputs a summary of the changes to the user.

The complete flow: