Module 3 · AI Engineering English
🔥 13 day streak

Lesson 14: Model Context Protocol (MCP) Integration

2026-06-18 · ~20 min · B1 → C1 · Section 1 / 8
Section 1 Today's Scenario
TKT-9104 P1 · Critical Investigating

Claude Code CLI / MCP Orchestrator

Intermittent transport failures during MCP server initialization

We are integrating a custom MCP server with the Claude Code CLI to expose internal MSP platform APIs. However, the MCP client is intermittently failing to complete the capability negotiation handshake over the stdio transport layer. The logs indicate that the subprocess is exiting prematurely without emitting the required JSON-RPC initialization payload.

我们正在将自定义的 MCP (Model Context Protocol) 服务器与 Claude Code CLI 集成,以暴露内部 MSP 平台的 API。但是,MCP 客户端在通过 stdio 传输层进行能力协商握手时,偶尔会失败。日志显示子进程过早退出,且未能发出所需的 JSON-RPC 初始化载荷。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Negotiate /nɪˈɡoʊʃieɪt/ 协商 / 交互通讯

The process of exchanging protocols or capabilities between client and server.

"The client and server must negotiate capabilities before exchanging tool execution requests."

Prematurely /ˌpriːməˈtʃʊərli/ 过早地 / 未完成就中断地

Happening before the normal or expected completion time.

"The MCP server process terminated prematurely due to an unhandled exception in the stdio stream."

Delegate /ˈdelɪɡeɪt/ 委托 / 委派

Passing the responsibility for a task to another component or system.

"The agent orchestrator delegates the actual API invocation to the respective MCP server."

Scaffold /ˈskæfəʊld/ 搭建骨架 / 生成基础代码

Generating the basic structural code or infrastructure for a new project.

"We used the official LangChain template to scaffold the new MCP server architecture."

Discrepancy /dɪˈskrepənsi/ 差异 / 不一致

An unexpected difference or lack of compatibility between two facts or schemas.

"There is a discrepancy between the tool schema exposed by the server and what the LLM expects."

Resilient /rɪˈzɪliənt/ 具备弹性的 / 容错的

Able to withstand or recover quickly from difficult conditions or errors.

"We need a more resilient transport implementation to handle intermittent connection drops."

Concurrently /kənˈkʌrəntli/ 并发地 / 同时地

Executing multiple operations at the same time.

"The LangGraph agent can invoke multiple MCP tools concurrently to reduce latency."

Section 3 Native Engineer Expressions
JG

"The server is choking on the initialization request."

服务器在处理初始化请求时卡住/崩溃了 · Use when a system fails during startup due to a bad payload

JG

"Let's tail the logs to see where the handshake drops."

我们追踪一下日志,看看握手在哪里中断的 · Use in Slack when debugging real-time transport issues

JG

"It looks like a race condition between the client connecting and the server binding to the port."

看起来客户端连接和服务器绑定端口之间存在竞态条件 · Use when intermittent initialization bugs occur

JG

"Can we stub out the API calls to isolate the transport layer?"

我们能不能打个桩替换掉 API 调用,以便隔离传输层? · Use when troubleshooting whether an error is in business logic or protocol

JG

"The agent is hallucinating arguments that aren't in the tool schema."

Agent 虚构了不在工具 schema 中的参数 · Use when the LLM generates invalid JSON parameters for an MCP tool

Section 4 Technical Reading

The Model Context Protocol (MCP) standardizes how AI agents interface with external data sources and tools. During the initialization phase, the MCP client and server exchange a JSON-RPC payload to negotiate capabilities. If the server is implemented using the stdio transport, it is critical to ensure that standard output is strictly reserved for the protocol messages.

Any arbitrary application logs emitted to standard output will pollute the stream, causing the client to fail the parse step and prematurely terminate the connection. To build resilient integrations, engineers should route all diagnostic telemetry to standard error (stderr) and verify that the server correctly exposes its tool schemas before delegating execution to the LLM orchestrator.

Comprehension Check

1. What is the primary cause of connection termination mentioned in the text?

The server failing to bind to a network port.
Arbitrary logs polluting the standard output stream.
The LLM generating invalid tool schemas.
The agent orchestrator rejecting the JSON-RPC payload.

2. How should developers handle diagnostic telemetry in a stdio MCP server?

Emit it as a JSON-RPC payload to the client.
Disable it entirely in production environments.
Route it to the standard error (stderr) stream.
Delegate it to the LLM orchestrator for parsing.

3. What happens during the initial handshake between the MCP client and server?

They exchange a payload to negotiate supported capabilities.
The client instantiates a new vector database.
The server automatically executes all exposed tools.
They bind to a REST API endpoint.
Section 5 Writing Task

Write a short update to your team via Slack explaining the root cause of the intermittent MCP server failures in the Claude Code CLI integration.

  • 1.State that the server is writing log messages to stdout instead of stderr.
  • 2.Explain that this pollutes the JSON-RPC payload and breaks the initial handshake.
  • 3.Propose configuring the logger to exclusively use stderr as the workaround.
  • 4.Keep it under 80 words.
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct verb tenses when describing the bug and the proposed fix (e.g., present continuous for ongoing actions).
Vocabulary / 20 pts
Accurately uses terms like "pollute", "payload", "handshake", and "workaround".
Clarity / 20 pts
Root cause (stdout vs stderr) is immediately obvious in the first sentence.
Professionalism / 20 pts
Constructive tone, presenting a clear engineering solution rather than just complaining about the error.
Native-like Expression / 20 pts
Uses concise phrasing typical of an engineering-first environment (e.g., "The issue boils down to...", "To fix this...").
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Interoperability

互操作性

Systems working together seamlessly.

Ephemeral

短暂的 / 临时的

Short-lived resources or instances.

Stale

过期的 / 陈旧的

Data or cache that is no longer valid.

2 Expressions from Previous Lessons

"It's polluting the stdout stream."

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

Section 8 Challenge Zone ⚡ Above current level

When designing an MCP server that exposes sensitive MSP platform tools (e.g., restarting customer servers via Halo PSA), how would you design the authorization model? Should the MCP server blindly trust the client, or should it implement its own validation layer? Explain your architecture briefly.

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