Module 3 · AI Engineering English
🔥 10 day streak

Lesson 11: Model Context Protocol (MCP) Integration

2026-06-16 · ~20 min · B1 → C1 · Section 1 / 8
Section 1 Today's Scenario
#MCP-2041 P2 · High Investigating

Daily English Lab Agent

MCP Server Integration Failure over Stdio Transport

We are integrating a new custom MCP server into our Daily English Lab Agent to dynamically pull user progress data. However, the Claude Code CLI orchestrator is failing to discover the tools advertised by the server over the stdio transport. We need to isolate whether this is a JSON formatting issue polluting the standard output, or an initialization timeout in the subprocess.

我们正在将一个新的自定义 MCP 服务集成到每日英语实验室 Agent 中以动态获取用户进度数据。然而,Claude Code CLI 编排器未能通过 stdio 传输层发现该服务声明的工具。我们需要排查这究竟是污染了标准输出的 JSON 格式问题,还是子进程中的初始化超时。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Bi-directional /ˌbaɪ dɪˈrekʃənl/ 双向的

Functioning in two directions; used to describe communication where both client and server can send and receive data.

"The MCP establishes a bi-directional JSON-RPC connection over the specified transport layer."

Interoperability /ˌɪntərˌɒpərəˈbɪləti/ 互操作性

The ability of different systems, devices, or applications to connect and communicate with one another.

"We chose MCP to ensure interoperability between our LangGraph agents and the local database."

Adhere /ədˈhɪər/ 遵守 / 遵循

To stick firmly to a rule, standard, or specification.

"The server's response payload must adhere strictly to the JSON-RPC 2.0 specification."

Introspection /ˌɪntrəˈspekʃən/ 内省机制 / 自省

A process where a system dynamically discovers the structure, capabilities, or schema of an endpoint.

"During the handshake, the client uses introspection to list all the tools exposed by the server."

Propagate /ˈprɒpəɡeɪt/ 传播 / 向上抛出

To transmit or spread an event or error up through the layers of an application architecture.

"If the server crashes, we need to ensure the error propagates properly back to the LLM agent."

Ephemeral /ɪˈfemərəl/ 短暂的 / 临时的

Lasting for a very short time; typically referring to processes that are created and destroyed frequently.

"Stdio transports are best suited for ephemeral server instances tied directly to the client's lifecycle."

Section 3 Native Engineer Expressions
JG

"The MCP server is failing to emit the proper JSON-RPC payload during initialization."

MCP服务在初始化时未能发出正确的JSON-RPC载荷。 · Use when diagnosing parsing/schema failures.

JG

"Let's bump the timeout threshold for the stdio transport."

我们把stdio传输层的超时阈值调高一点吧。 · Use when heavy initializations are killing the subprocess prematurely.

JG

"Is the client strictly adhering to the tool schema defined by the server?"

客户端是否严格遵循了服务端定义的工具schema? · Use during API contract mismatch investigations.

JG

"We need to pipe the stderr to a file so we can capture the crash logs."

我们需要把标准错误输出导向到文件,以便捕获崩溃日志。 · Use when diagnosing silent crashes in subprocesses.

JG

"It looks like a race condition during the handshake sequence."

看起来像是在握手阶段发生了竞态条件。 · Use when connection success is intermittent or timing-dependent.

Section 4 Technical Reading

The Model Context Protocol (MCP) standardizes how AI models interact with external data sources and tools, ensuring robust interoperability. When a client instantiates an MCP server via a `stdio` transport, it spawns a subprocess and establishes a bi-directional communication channel using JSON-RPC 2.0.

During the initialization phase, the client performs introspection to discover the tools and capabilities exposed by the server. It is crucial that the server adheres strictly to the protocol specification. Because `stdio` streams are shared, developers must ensure that any background logging or print statements do not pollute `stdout`. Extraneous text in the standard output will break the JSON-RPC message framing, leading to silent malformed payload errors at the orchestration layer. Best practice dictates routing all diagnostic logs to `stderr` to prevent such disruptions.

Comprehension Check

1. What happens if the server outputs background logs to standard output (stdout) during a stdio transport session?

A) The orchestrator automatically pipes it to a log file.
B) It breaks JSON-RPC message framing and causes parsing errors.
C) The client ignores it and continues the handshake seamlessly.
D) The subprocess restarts automatically to clear the buffer.

2. Which protocol does MCP use for its bi-directional communication?

A) gRPC
B) RESTful API
C) JSON-RPC 2.0
D) GraphQL

3. What is the main purpose of the client performing introspection during initialization?

A) To dynamically discover the tools and capabilities exposed by the server.
B) To monitor the memory and CPU usage of the spawned subprocess.
C) To propagate authentication errors to the end-user.
D) To encrypt the payload data before sending it over the network.
Section 5 Writing Task

You just resolved Ticket #MCP-2041. Write a brief Slack message to your team explaining the root cause and the fix for the MCP server failure.

  • 1.Mention that background logs were polluting standard output (stdout).
  • 2.State that the workaround/fix was routing logs to stderr.
  • 3.Confirm that tool discoverability is now functioning properly.
  • 4.Keep it under 80 words.
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct use of past tense for identifying root causes, proper subject-verb agreement.
Vocabulary / 20 pts
Accurately uses terms like "stdout", "stderr", "pollute", and "discoverability".
Clarity / 20 pts
The root cause and solution are stated directly without ambiguity.
Professionalism / 20 pts
Tone is helpful, factual, engineering-oriented, and suitable for internal Slack communication.
Native-like Expression / 20 pts
Phrased concisely (e.g., "piped logs to stderr", "tools are now discoverable").
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Discoverability

可发现性

Ensuring APIs or tools can be found dynamically.

Subprocess

子进程

A process spawned and managed by a parent script.

Handshake

握手 / 建立连接

The initial protocol negotiation between client and server.

2 Expressions from Previous Lessons

"The process is failing silently."

"Let's check if the client and server agree on the protocol version."

Section 8 Challenge Zone ⚡ Above current level

When using the `stdio` transport for an MCP server, all communication happens over standard input and output streams tied directly to a local subprocess. Why might this architecture become problematic if you need to scale the system to handle concurrent requests from multiple distinct, remote AI agents? How would switching to an HTTP-based or SSE (Server-Sent Events) transport architecture resolve these limitations?

Answer in English. Use technical vocabulary from this lesson. No word limit.