Module 3 · AI Engineering English
🔥 14 day streak

Lesson 15: Model Context Protocol (MCP)

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

Claude Code CLI / MCP Integration

MCP Server Initialization Timeout on Custom Agent Orchestrator

We are integrating a custom MCP server with our Claude Code CLI orchestrator to expose internal APIs. However, the client frequently drops the connection during the handshake phase, citing an initialization timeout. I need to trace the JSON-RPC lifecycle to see where the transport layer is failing.

我们正在将自定义的 MCP 服务器与 Claude Code CLI 编排器集成,以暴露内部 API。然而,客户端在握手阶段频繁断开连接,提示初始化超时。我需要追踪 JSON-RPC 的生命周期,找出传输层失败的具体原因。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Orchestrator /ɔːr.kəˌstreɪ.t̬ɚ/ 编排器

The component responsible for coordinating multiple agents, tools, or services.

"The orchestrator routes the query to the appropriate MCP server based on the requested tool schema."

Transport /ˈtræn.spɔːrt/ 传输 / 传输层

The underlying communication mechanism (e.g., stdio, SSE) for the protocol.

"Switching the transport layer from stdio to SSE resolved our intermittent connection drops."

JSON-RPC /ˌdʒeɪ.sən.ɑːr.piːˈsiː/ JSON远程过程调用

A stateless, light-weight remote procedure call (RPC) protocol standard used heavily in MCP.

"I dumped the JSON-RPC payloads to standard error to inspect the malformed tool execution request."

Expose /ɪkˈspoʊz/ 暴露 / 提供

To make internal functions, services, or endpoints available to external clients.

"We should only expose read-only database queries through this MCP server for security reasons."

Handshake /ˈhænd.ʃeɪk/ 握手协议

The initial negotiation phase between the client and server to establish a connection.

"The server failed to negotiate capabilities during the initial handshake."

Resource /ˈriː.sɔːrs/ 资源

Data, text, or files provided by an MCP server explicitly for the client to read.

"The client successfully subscribed to the log file resource via the MCP protocol."

Section 3 Native Engineer Expressions
JG

"The MCP client is hanging during the init phase."

MCP 客户端在初始化阶段卡住了。 · Use when debugging connection timeouts

JG

"Can we dump the JSON-RPC traffic to stderr?"

我们能把 JSON-RPC 流量输出到标准错误流吗? · Use when requesting verbose logging for debugging

JG

"It seems the server failed to negotiate capabilities."

服务器似乎未能成功协商能力/特性。 · Use when diagnosing handshake failures

JG

"We need to dynamically expose these internal APIs as MCP tools."

我们需要将这些内部 API 动态暴露为 MCP 工具。 · Use during architectural discussions about tool integration

JG

"The orchestrator is choking on the malformed tool response."

编排器因为格式错误的工具响应而崩溃/卡顿。 · Use when the LLM client fails to parse the server's output

Section 4 Technical Reading

The Model Context Protocol (MCP) standardizes how AI models access external data and tools. By decoupling the orchestrator from the underlying data sources, MCP enables a highly modular architecture. When an MCP client connects to a server, it initiates a JSON-RPC handshake over a chosen transport, such as standard input/output (stdio) or Server-Sent Events (SSE). During this phase, both parties negotiate capabilities.

If the server successfully initializes, it can expose specific resources, prompts, and tools to the client. However, developers must carefully manage the transport layer; if a subprocess writes non-protocol logs or debugging information to stdout instead of stderr, it will corrupt the JSON-RPC stream. This frequently causes the orchestrator to abruptly drop the connection, citing a malformed payload or initialization timeout.

Comprehension Check

1. What happens during the initial connection phase between an MCP client and server?

The client downloads the server's full database.
They negotiate capabilities via a JSON-RPC handshake.
The orchestrator immediately executes all exposed tools.
The server sends an SSE payload to standard output.

2. Which transport mechanisms are explicitly mentioned in the passage?

HTTP/2 and WebSockets
REST APIs and gRPC
Stdio and Server-Sent Events (SSE)
TCP and UDP

3. What will likely cause the orchestrator to abruptly drop the connection?

Writing non-protocol logs to standard output, corrupting the stream.
Exposing too many resources to the client during initialization.
Sending standard JSON-RPC payloads over an SSE transport layer.
Decoupling the data sources from the main orchestrator entirely.
Section 5 Writing Task

You just fixed #TKT-8924. The Claude Code CLI was dropping its connection to your custom MCP server because a third-party library was logging warnings to `stdout`, which polluted the JSON-RPC stream. Write a brief ticket update.

  • 1.State the root cause clearly
  • 2.Explain your fix (redirecting logs to stderr)
  • 3.Use the term "transport" or "JSON-RPC stream"
  • 4.Keep it under 80 words
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct verb tenses for an RCA (Root Cause Analysis); e.g., "was dropping", "redirected".
Vocabulary / 20 pts
Accurate use of "stdout", "stderr", "JSON-RPC", or "transport".
Clarity / 20 pts
Root cause (polluted stream) and fix (redirected logs) stated explicitly in 1-2 sentences.
Professionalism / 20 pts
Tone is direct, factual, and engineering-first. No marketing fluff.
Native-like Expression / 20 pts
Uses native phrasing naturally (e.g., "polluting the stream", "choking on", "hanging").
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Ephemeral

短暂的 / 临时的

Used for short-lived containers, tokens, or states.

Introspection

内省 / 自省

The ability of a system to examine its own schemas or state.

Discrepancy

差异 / 不一致

Used when two environments or expected outputs do not match.

2 Expressions from Previous Lessons

"It looks like the MCP server is silently swallowing the error."

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

Section 8 Challenge Zone ⚡ Above current level

In an MCP architecture, what are the security trade-offs between using a local `stdio` transport versus a remote `SSE/HTTP` transport when exposing internal backend APIs to an AI Agent? Describe at least one distinct risk for each approach.

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