Back to series
· 13 min read

MCP’s Protocol Architecture and Communication Mechanisms: From JSON-RPC to Complete Client-Server Interaction


1. MCP Protocol Architecture Overview

MCP (Model Context Protocol) is not just a set of tool invocation interfaces; it is a complete inter-application communication protocol.

It defines how AI applications connect to external services, discover service capabilities, send requests, receive responses, and handle different types of interactions.

From an architectural perspective, MCP can be divided into four layers:

  1. Application Architecture Layer: the roles and responsibilities of Host, Client, and Server.
  2. Protocol Message Layer: the JSON-RPC 2.0 message format and MCP method specifications.
  3. Transport Layer: message transport mechanisms such as STDIO and Streamable HTTP.
  4. Business Capability Layer: discovery and invocation of capabilities such as Tools, Resources, and Prompts.

Overall structure:

flowchart TB
    A["AI Application Layer<br/>Host"] --> B["Protocol Client Layer<br/>MCP Client"]
    B --> C["Protocol Message Layer<br/>JSON-RPC 2.0 + MCP Methods"]
    C --> D["Transport Layer<br/>STDIO / Streamable HTTP"]
    D --> E["Server Protocol Layer<br/>MCP Server"]
    E --> F["Business Adaptation Layer"]
    F --> G["External Systems<br/>API / Database / Files"]

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

It should be noted that MCP's protocol message layer and transport layer are independent of each other:

  • JSON-RPC defines how messages are expressed.
  • MCP defines which methods, parameters, and interaction semantics exist.
  • The transport layer is responsible for delivering messages from one end to the other.
  • The business adaptation layer is responsible for actually executing external operations.

This layered design means MCP does not need to be tied to a particular network protocol, programming language, or large model.

2. MCP's Three-Layer Role Architecture

MCP adopts a three-layer role model consisting of Host, Client, and Server.

2.1 Host: Host Application

The Host is the entry point of the entire MCP system and the application-level coordinator.

For example, an AI coding assistant that supports MCP is a Host.

The Host is mainly responsible for:

  • Receiving user input.
  • Invoking the large model.
  • Managing MCP Clients.
  • Managing multiple MCP Servers.
  • Controlling tool invocation and permissions.
  • Assembling context.
  • Passing tool execution results back to the model.
  • Presenting final results to the user.

The Host is not just a protocol forwarder; it is also responsible for deciding when the model uses external capabilities and which operations can actually be executed.

2.2 Client: Protocol Client

An MCP Client is the protocol component inside the Host responsible for communicating with an MCP Server.

Main responsibilities:

  • Establishing and managing transport connections.
  • Sending MCP requests.
  • Receiving MCP responses.
  • Parsing JSON-RPC messages.
  • Discovering capabilities provided by the Server.
  • Handling protocol notifications and interaction results.
  • Executing the corresponding communication flow according to the protocol version.

Usually, one MCP Client is responsible for logical communication with one MCP Server.

A Host can manage multiple Clients and thus connect to multiple Servers.

2.3 Server: Protocol Server

An MCP Server is responsible for exposing standardized capabilities to the outside.

For example:

  • GitHub MCP Server.
  • PostgreSQL MCP Server.
  • Filesystem MCP Server.
  • Browser MCP Server.
  • Enterprise knowledge base MCP Server.

The Server encapsulates underlying business systems as MCP capabilities, so the Client does not need to directly understand each system's business API.

2.4 Relationships Among the Three Roles

flowchart TB
    A["User"] --> B["Host<br/>AI Host Application"]

    subgraph HOST["Inside Host"]
        B --> C["LLM"]
        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"]
    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

There are three points that are easy to confuse:

First, Host is not the same as Client.

Host is the complete AI application, while Client is the protocol communication component inside the Host.

Second, Client is not the same as Server.

Client initiates requests, while Server provides capabilities and handles requests.

Third, MCP does not require the model to be deployed inside the Host.

Host can call cloud models or use local models. MCP focuses on connecting to external capabilities, not on how the model itself is deployed.

III. MCP Protocol Message Layer: JSON-RPC 2.0

MCP uses JSON-RPC 2.0 as its underlying message format.

JSON-RPC is a lightweight remote procedure call protocol that uses JSON objects to represent requests, responses, notifications, and errors.

MCP defines specific protocol methods and parameter structures on top of JSON-RPC.

3.1 The Four Message Types of JSON-RPC

JSON-RPC mainly involves four types of messages:

Message Type Purpose Response Required?
Request Initiate a remote method call Yes
Response Return the request handling result N/A
Notification Send notification events No
Error Indicate an error in processing a request As part of a response

Here, Error is not a fifth message type independent of Response; rather, it is one result branch within a response.

3.2 Request: Request Message

Typical request:

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

Field descriptions:

Field Description
jsonrpc JSON-RPC version, fixed at 2.0
id Request identifier
method Name of the requested method
params Method parameters

Here, id is used to associate the response with the original request.

For example:

{
  "jsonrpc": "2.0",
  "id": 12,
  "method": "tools/call",
  "params": {
    "name": "search_documents",
    "arguments": {
      "query": "MCP architecture"
    }
  }
}

This request represents a call to the tool named search_documents, with query parameters passed in.

3.3 Response: Response Message

A normal response:

{
  "jsonrpc": "2.0",
  "id": 12,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Found 3 related documents"
      }
    ],
    "isError": false
  }
}

The id in a response must match the id of the corresponding request.

result is the result object produced after the method executes successfully; its internal structure is defined by the specific MCP method.

Two kinds of success need to be distinguished here:

  • The JSON-RPC request was handled successfully.
  • The tool actually executed successfully.

For example, a tool may execute successfully and return isError: true, indicating that a business error occurred during tool execution. At the JSON-RPC level, this may still be a normal response.

3.4 Error: Protocol Errors

If a request cannot be handled normally according to the protocol, a JSON-RPC error response can be returned:

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

Common error codes:

Error Code Meaning
-32700 Parse error
-32600 Invalid Request
-32601 Method not found
-32602 Invalid params
-32603 Internal error

MCP also defines its own error semantics. An actual implementation should follow the specification of the corresponding version, and should not rely solely on the generic error codes above.

3.5 Notification: Notification Messages

A notification is a message that does not require the receiver to return a JSON-RPC response.

For example:

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

Compared with a request, it has no id.

Notifications are suitable for:

  • Progress updates.
  • State changes.
  • Resource changes.
  • Notification events such as cancellation.

Note that a notification does not mean the message is unimportant; it simply means the protocol does not require a corresponding JSON-RPC response to be returned for it.

3.6 The Core Difference Between Requests and Notifications

flowchart TD
    A["Send a JSON-RPC message"] --> B{"Contains id?"}
    B -->|"Yes"| C["Request"]
    B -->|"No"| D["Notification"]
    C --> E["Receiver handles request"]
    E --> F["Return Response"]
    F --> G["Match request by id"]
    D --> H["Receiver handles notification"]
    H --> I["No JSON-RPC Response returned"]

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

IV. MCP Method System

JSON-RPC only addresses message formatting; MCP also needs to define the specific methods that can be invoked.

These methods constitute MCP's protocol interface.

4.1 Lifecycle and Discovery Methods

The lifecycle mechanism differs between protocol versions.

Earlier MCP versions use an initialization handshake:

Method Direction Purpose
initialize Client → Server Initialize the protocol connection
notifications/initialized Client → Server Notify that initialization is complete
ping Bidirectional Check communication status

In older protocol versions, initialize is used to exchange protocol version, client information, server information, and capability declarations.

The 2026-07-28 version of the specification removes the initialize / notifications/initialized handshake, and instead has each request carry the necessary protocol version and client metadata, and provides an optional server/discover capability discovery method.

Therefore, during development, you must distinguish between old and new protocol versions and must not mix the two lifecycle mechanisms in one implementation.

4.2 Tools Methods

Tools are used to discover and invoke tools.

Method Direction Purpose
tools/list Client → Server Get the tool list
tools/call Client → Server Execute the specified tool
notifications/tools/list_changed Server → Client Notify of changes to the tool list (applicable versions)

Basic structure of a tool call:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "get_user",
    "arguments": {
      "user_id": "1001"
    }
  }
}

The Server finds the corresponding handler by tool name, validates the parameters, and executes the specific business logic.

4.3 Resources Methods

Resources are used to discover and read server-side resources.

Method Purpose
resources/list Get resource list
resources/read Read the specified resource
resources/templates/list Get resource template list
resources/subscribe Subscribe to resource changes (requires corresponding capability support)
resources/unsubscribe Cancel resource subscription

For example:

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "resources/read",
  "params": {
    "uri": "file:///workspace/README.md"
  }
}

The server locates the resource based on the URI and returns the corresponding content.

Resource templates differ from ordinary resources: a template describes a parameterizable way of locating resources.

4.4 Prompts Methods

Prompts are used to discover and retrieve prompt templates.

Method Purpose
prompts/list Get the list of prompt templates
prompts/get Get a specified prompt template
notifications/prompts/list_changed Notify of changes to the prompt template list (in applicable versions)

For example:

{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "prompts/get",
  "params": {
    "name": "review_code",
    "arguments": {
      "language": "Python"
    }
  }
}

The server generates the message content based on the template name and arguments, and returns it to the client.

4.5 Other Protocol Methods

MCP also includes other interaction capabilities:

Capability Typical method or mechanism Purpose
Logging logging/setLevel Set the log level (in applicable versions)
Completion completion/complete Prompt argument completion
Sampling sampling/createMessage Request the host-side model to generate content (legacy interaction)
Elicitation elicitation/create Request additional information from the user (legacy interaction)
Roots roots/list Get root directory information provided by the client (legacy interaction)
Cancellation notifications/cancelled or transport cancellation Cancel a request that is being processed
Progress notifications/progress Report processing progress

These methods do not mean that every MCP server must support all capabilities.

Whether a given method can actually be used depends on the protocol version, the capability declarations, and the implementations of the client and server.

V. MCP Capability Negotiation Mechanism

Capability negotiation is used to determine which protocol features both communicating parties support.

It affects which methods the client can call, and which interaction capabilities the server can request from the client.

5.1 Legacy Capability Negotiation

In the legacy protocol, the client and server exchange capability declarations through the initialization handshake.

For example, the client declares:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-11-25",
    "capabilities": {
      "roots": {
        "listChanged": true
      },
      "sampling": {}
    },
    "clientInfo": {
      "name": "example-host",
      "version": "1.0.0"
    }
  }
}

The server returns:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-11-25",
    "capabilities": {
      "tools": {
        "listChanged": true
      },
      "resources": {
        "subscribe": true,
        "listChanged": true
      },
      "prompts": {
        "listChanged": true
      }
    },
    "serverInfo": {
      "name": "example-server",
      "version": "1.0.0"
    }
  }
}

Here, capabilities indicates the protocol capabilities that each side can offer or support — it is not a list of business tools.

For example:

  • tools means the server supports the tools capability.
  • resources means the server supports the resources capability.
  • prompts means the server supports the prompt templates capability.
  • sampling means the client supports the corresponding model sampling capability.
  • roots means the client can provide the root directories capability.

Note: a capability declaration is not the same as a tool list. The actual tools still have to be obtained via tools/list.

5.2 Capability Declarations in the New Version

The 2026-07-28 version of the protocol was reworked around a stateless protocol core.

Main changes:

  • Capabilities are no longer exchanged through an initialization handshake.
  • Each request carries metadata such as the protocol version and client identity.
  • Client capabilities are expressed through request metadata.
  • The server can provide capability discovery information via server/discover.
  • The server does not need to rely on a protocol-level session to store client capabilities.

In the new version, a request's _meta can carry protocol-defined metadata, such as client information and capability declarations.

Therefore, the capability exchange in the old initialize cannot simply be carried over to the new request flow.

5.3 Core Principles of Capability Negotiation

Whichever generation of the protocol is used, several principles must be followed:

  1. Do not assume the peer supports every MCP feature.
  2. Do not confuse capability declarations with business tool lists.
  3. Before calling an extension feature, confirm that both sides support the corresponding capability.
  4. Unsupported features should return an explicit error.
  5. When protocol versions are incompatible, stop using the incompatible methods.

6. The MCP Lifecycle Mechanism

The MCP lifecycle describes the protocol process from the start of interaction between client and server to the completion of a request.

Note in particular: the 2026-07-28 specification introduced a stateless protocol core, so the old handshake lifecycle and the new request lifecycle must be understood separately.

6.1 The Old Lifecycle: Initialization Handshake

The old version of the protocol typically involves:

  1. Establishing the transport connection.
  2. The client sends initialize.
  3. The server returns the protocol version and capabilities.
  4. The client sends notifications/initialized.
  5. Both sides enter the normal interaction phase.
  6. The client can call tools, read resources, and so on.
  7. The transport is closed when the connection ends.
flowchart TD
    A["Start MCP Client"] --> B["Establish transport connection"]
    B --> C["Send initialize"]
    C --> D["Server returns version and capabilities"]
    D --> E{"Protocol versions compatible?"}
    E -->|"No"| F["Terminate connection"]
    E -->|"Yes"| G["Send initialized notification"]
    G --> H["Enter normal communication phase"]
    H --> I["Call Tools / Resources / Prompts"]
    I --> J["Handle requests and responses"]
    J --> K["Close transport connection"]

    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:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style I fill:#EAF3EC,stroke:#83A995,color:#315D49
    style J fill:#EAF3EC,stroke:#83A995,color:#315D49
    style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

6.2 The New Lifecycle: Stateless Requests

The 2026-07-28 version of the specification eliminates the protocol-level initialization handshake and session identifier.

The client can first call server/discover as needed, or it can issue a specific request directly.

Each request carries the required protocol version and client metadata, and the server handles requests independently.

flowchart TD
    A["Host creates MCP Client"] --> B["Determine target protocol version"]
    B --> C{"Discover capabilities in advance?"}
    C -->|"Yes"| D["Call server/discover"]
    C -->|"No"| F["Build the specific MCP request"]
    D --> E["Obtain Server capability information"]
    E --> F
    F --> G["Include protocol version and request metadata"]
    G --> H["Send an independent request"]
    H --> I["Server validates the request"]
    I --> J{"Request valid and supported?"}
    J -->|"No"| K["Return a protocol error"]
    J -->|"Yes"| L["Execute the corresponding MCP method"]
    L --> M["Return the JSON-RPC result"]
    M --> N["Client handles the response"]

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

6.3 Comparison of the Old and New Lifecycles

Comparison dimension Old version (as of 2025-11-25) New version (2026-07-28)
Initialization initialize handshake No initialization handshake
Initialization completion notification notifications/initialized Not required
Capability discovery Initialization response Optional server/discover
Protocol version Negotiated during initialization Carried with every request
Session identifier HTTP can use Mcp-Session-Id Protocol-level session identifier removed
Request context Can rely on session state Each request self-describing
Load balancing Stateful deployments may require sticky routing Ordinary round-robin load balancing can be used

It should be emphasized: the new version's statelessness means that the protocol layer no longer relies on session state; it does not mean that the business application must be stateless.

For example, the Server can still persist business state through a database, a cache, or an explicit task ID.

VII. MCP Transport Layer Mechanisms

MCP separates protocol messages from the underlying transport method.

Protocol messages describe requests and responses, while the transport layer is responsible for delivering messages to the peer.

Currently, two standard transport methods are mainly used:

  • STDIO.
  • Streamable HTTP.

7.1 STDIO: Standard Input/Output

STDIO is mainly used for local MCP Servers.

The Host starts an MCP Server subprocess and communicates through standard input/output.

How it works:

  • The Host writes protocol messages to the Server's stdin.
  • The Server reads messages from stdin.
  • The Server writes protocol responses to stdout.
  • The Server writes diagnostic logs to stderr.
flowchart LR
    A["Host"] -->|"write messages to stdin"| B["MCP Server process"]
    B -->|"return messages via stdout"| A
    B -->|"output logs to stderr"| 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

Characteristics of STDIO:

  • No need to start an HTTP service.
  • Does not rely on a network connection.
  • Suitable for local process communication.
  • Relatively simple to deploy and develop.
  • Suitable for local files, terminals, and development tools.

Engineering considerations:

STDIO's stdout is the protocol communication channel, so ordinary logs must not be output to it at will.

For example:

// Not recommended: may pollute protocol output
console.log("MCP Server started");

// Recommended: write logs to stderr
console.error("MCP Server started");

If ordinary text is mixed into the protocol output, the Client may be unable to parse messages correctly.

7.2 Streamable HTTP: Remote Communication

Streamable HTTP is the standard MCP transport method for HTTP environments.

It allows the Client to request the MCP Server over HTTP and allows the server side to deliver messages through streaming responses.

Typical deployment:

flowchart TB
    A["AI Host"] --> B["MCP Client"]
    B --> C["HTTP Client"]
    C --> D["API Gateway / Reverse Proxy"]
    D --> E["MCP Server"]
    E --> F["Business API"]
    E --> G["Database"]

    F --> E
    G --> E
    E --> D
    D --> C

    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
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

It has the following characteristics:

  1. Uses HTTP to carry MCP requests.
  2. Supports JSON-format responses.
  3. Supports streaming messages over SSE.
  4. Suitable for remote service deployment.
  5. Can be combined with HTTP authentication and gateway policies.

7.3 Request Structure of Streamable HTTP

Taking a tool call as an example, an HTTP request may contain:

POST /mcp HTTP/1.1
Host: mcp.example.com
Content-Type: application/json
Accept: application/json, text/event-stream

Request body:

{
  "jsonrpc": "2.0",
  "id": 10,
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": {
      "query": "MCP"
    }
  }
}

In older versions of the protocol, after the client completes initialization, subsequent requests may need to carry the Mcp-Session-Id assigned by the server.

The 2026-07-28 version of the protocol no longer uses this protocol-level session identifier, and handles each request independently using the protocol version and metadata carried in each request.

7.4 Response Methods of Streamable HTTP

The server can return a normal JSON response according to the request and protocol requirements, or it can use an SSE streaming response.

Example of a normal JSON response:

HTTP/1.1 200 OK
Content-Type: application/json
{
  "jsonrpc": "2.0",
  "id": 10,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "查询完成"
      }
    ]
  }
}

A streaming response can use SSE events to carry MCP messages.

For example:

event: message
data: {"jsonrpc":"2.0","id":10,"result":{"content":[]}}

A distinction needs to be made here:

  • HTTP is the underlying transport protocol.
  • SSE is a streaming message delivery method.
  • JSON-RPC is the message format of MCP.

These three are not the same concept.

7.5 Comparison Between STDIO and Streamable HTTP

Dimension STDIO Streamable HTTP
Communication method Standard input/output HTTP
Deployment scope Local process Local or remote service
Network dependency Not required Required for remote access
Authentication Usually relies on local process permissions Can integrate with HTTP authentication
Streaming capability Delivered through a message stream Can use SSE
Operations method Process management Service deployment and monitoring
Typical scenarios Local tools Cloud and enterprise services

8. MCP Request and Response Mechanism

Requests and responses are the core of MCP communication.

To understand the complete mechanism, you need to focus on request IDs, method routing, parameter validation, execution results, and error handling.

8.1 Sending Requests

The client constructs a JSON-RPC request according to business requirements.

For example:

{
  "jsonrpc": "2.0",
  "id": 100,
  "method": "tools/call",
  "params": {
    "name": "query_database",
    "arguments": {
      "sql": "SELECT id, name FROM users LIMIT 10"
    }
  }
}

The client passes the message to the transport layer for sending.

8.2 Server Receiving and Routing

After the server receives the message, it needs to complete:

  1. Message parsing.
  2. JSON-RPC format validation.
  3. Method identification.
  4. Parameter validation.
  5. Permission check.
  6. Invoke the corresponding handler function.