Skip to content
What Is MCP? A Step-by-Step Tool Call Walkthrough

What Is MCP? A Step-by-Step Tool Call Walkthrough

This article explains the Model Context Protocol (MCP) by tracing a complete tool call flow—from tool discovery via tools/list, model intent generation, MCP routing, server execution, to result return—detailing JSON-RPC message formats, stdio and HTTP transports, and the roles of Model, Host, Client, and Server.

Cambridge Mofang Notes
Cambridge Mofang Notes
Cambridge Mofang Notes

The Model Context Protocol (MCP) is an open protocol that lets AI applications discover, read, and invoke external capabilities in a standardized way. It solves the repeated adaptation problem when the same business capability must be integrated into multiple AI applications.

01 What MCP Unifies

Without a common protocol, each AI application defines its own tool description format, invocation method (HTTP, local script, etc.), and interaction details (tool listing, parameter validation, error handling). MCP standardizes four aspects: how capabilities are discovered, how tools are described, how invocation requests are sent, and how results are returned. A capability provider implements an MCP Server; an AI application uses a built-in MCP Client to access it.

MCP is often compared with business APIs. A business API answers "how to call this specific business interface." MCP answers "how available capabilities are discovered, how parameters are described to the model, and how requests and results are standardized." The two layers complement each other.

02 Order Query Example

Assume an order system exposes GET /api/orders/123 returning {"order_id":"123","status":"已发货"}. In traditional software, the developer handles the request URL, parameters, authentication, and response directly. For an AI Agent to answer "Has order 123 shipped?", the model must first be told a tool named get_order exists, accepting an order_id parameter. The model then expresses a call intent; the surrounding application executes the call and feeds the result back.

Introducing MCP changes only how the application accesses the external tool—replacing private integration with a standard protocol. The order API still handles core business logic; the MCP Server exposes the "query order" capability per the MCP spec. Note that wrapping an HTTP API is just one implementation; an MCP tool can also query a database, read local files, or run local computations directly.

03 Separating Model, Host, Client, and Server

In MCP architecture, four distinct roles exist:

LLM (Large Language Model) : understands user query, selects tool, generates parameters, composes final answer.

Host (Host Application) : manages conversation context, model invocation, permission control, tool routing, and overall execution flow.

MCP Client : a connection instance inside the Host that communicates with an MCP Server via protocol messages.

MCP Server : exposes tool definitions, validates invocation requests, executes the order query, and returns standardized results.

Two independent communication paths exist: (1) Model ↔ Host using the model vendor's tool format (Function Calling), and (2) Host ↔ MCP Server using JSON-RPC 2.0. The Host bridges these paths, converting tool formats and maintaining a routing table that maps each tool to its MCP Server. When multiple servers provide identically named tools (e.g., search), the Host can prefix tool names (e.g., orders__search, shipping__search) to avoid conflicts.

04 Complete Tool Call Walkthrough (MCP 2026-07-28)

Step 1: Application Fetches Tool Definitions

The Host sends a tools/list request via MCP Client:

{ "jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": { "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {} } } }

The server returns a tool definition, e.g., get_order with a JSON Schema input requiring order_id (string). The Host converts this to the model vendor's tool format and may cache or filter tools.

Step 2: Model Generates Call Intent

The Host passes the user question and converted tool definitions to the model. The model returns a call intent (illustrative):

{ "call_id": "call_order_01", "name": "get_order", "arguments": { "order_id": "123" } }

At this point, the order query has not executed; the model only expressed intent.

Step 3: Application Routes and Sends MCP Call Request

The Host identifies the target MCP Server via its routing table (built during tools/list), validates parameters and permissions, then sends tools/call via the corresponding MCP Client.

Step 4: Server Executes Tool and Returns Result

The Order MCP Server parses the request, invokes the internal get_order handler (which calls the order system API), and returns a standard MCP response.

Step 5: Application Feeds Result Back to Model

The Host converts the MCP response to the model's tool result format, linking it via call_order_01. The model reads "已发货" and answers the user. If more info is needed, the model can invoke another tool (e.g., logistics details).

Throughout this chain, the Host performs three key adaptations: model tool format ↔ MCP protocol, tool routing, and permission enforcement.

05 MCP Message Format (JSON-RPC 2.0)

MCP uses JSON-RPC 2.0. A request contains four core fields: jsonrpc (fixed "2.0"), id (request identifier), method (e.g., tools/list, tools/call), and params (method-specific parameters). The tools/call request for the order query looks like:

{ "jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": { "name": "get_order", "arguments": { "order_id": "123" }, "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {} } } }

The server processes the message through two dispatches: protocol layer → method handler → tool function. A successful response includes result with content (text, image blocks for model consumption) and structuredContent (structured JSON for host processing), plus isError: false. Errors are separated: protocol-level errors (invalid method, malformed JSON) appear in the top-level error field; tool execution errors (upstream API failure) stay in result with isError: true so the model can perceive business failure.

06 Transport: stdio and Streamable HTTP

1. stdio: Local Subprocess Communication

The Host launches the MCP Server as a child process and communicates via stdin/stdout pipes. Business parameters are not passed as command-line arguments; they flow continuously over the pipes after startup. A Node.js server reads lines from stdin, parses JSON, processes, and writes JSON responses with a newline delimiter to stdout. The newline acts as message boundary because OS pipes deliver a continuous byte stream. Logs must go to stderr (e.g., console.error) to avoid corrupting the protocol stream.

Common npx configurations (e.g.,

{"command":"npx","args":["-y","@your-scope/[email protected]"]}

) simply launch the package; stdio handles the protocol. npx is only a launcher—it can also start an HTTP server; the transport is independent.

2. Streamable HTTP: Remote Service Access

For independent deployment and multi-client access, the MCP Server runs as a web service exposing an endpoint (e.g., https://example.com/mcp). The client sends JSON-RPC in an HTTP POST body. Required headers include Content-Type: application/json, Accept: application/json, text/event-stream, MCP-Protocol-Version: 2026-07-28, Mcp-Method: tools/call, Mcp-Name: get_order. The server validates header-body consistency, executes the function, and returns either a single application/json response or a text/event-stream (SSE) stream for progress notifications and final result. A plain HTTP endpoint that accepts arbitrary JSON is not an MCP server; it must adhere to the full spec (message structure, capability discovery, schema description, result/error semantics).

07 Why MCP Configuration Looks So Simple

Developers only write a few lines of JSON (launch command or service URL) because Host and Server SDKs handle connection establishment, protocol version negotiation, tools/list fetching, tool filtering, model context injection, routing, permission checks, tools/call assembly, and result backfill. On the server side, frameworks like FastMCP or official SDKs generate JSON Schema from type annotations, register handlers, and manage request-response correlation and transport. Without a framework, developers must implement parameter validation, timeouts, subprocess lifecycle, and version compatibility themselves.

08 MCP Beyond Tools: Resources and Prompts

Besides Tools (executable operations for query, compute, or mutation), MCP defines two other primitives:

Resources : read-only context data (e.g., product docs, DB schema, log files) that can be loaded into the model's context.

Prompts : reusable instruction templates and workflows (e.g., order troubleshooting template, code review guidelines).

The spec also covers Authorization and Progress notifications, but adoption can start with Tools alone. The name "Model Context Protocol" reflects that external systems provide not only executable tools but also data and prompt templates that enter the model's context window; the Host orchestrates when and how they are assembled.

09 Summary and Common Debates

Responsibilities in a tool call:

LLM : intent understanding, tool selection, parameter generation.

Host : execution flow, format conversion, routing, permission control.

MCP Client/Server : standardized capability discovery, invocation, and result exchange via JSON-RPC.

stdio/HTTP : physical transport of protocol messages.

Debate 1: "Direct API calls are faster than MCP." MCP adds protocol overhead and an extra network hop; latency is observable in most scenarios. However, the gap is not constant and must be measured under identical conditions. For complex tasks requiring structured data handling, MCP may actually be faster. Model inference time should not be attributed to MCP. The choice depends on reuse: a tool serving a single application is simpler via direct API; a tool reused across multiple heterogeneous applications benefits from MCP's standardization, amortizing integration cost over time.

Debate 2: "MCP just wraps an API with another layer." Wrapping an HTTP API is only one common implementation; an MCP Server can directly connect to a database or local files—the protocol does not constrain the backend. MCP's core is runtime capability discovery: the client fetches tool list and parameter schemas (JSON Schema) and invokes via a uniform spec, avoiding hardcoded interface definitions in client code. For two or three fixed interfaces, direct code is sufficient; when a capability must be shared across teams and diverse AI clients, MCP's standardization enables a single server to be reused by many compatible clients.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MCPFunction CallingModel Context ProtocolJSON-RPCstdioStreamable HTTPAI tooling
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.