Module 3 · AI Engineering English
🔥 12 day streak

Lesson 13: Model Context Protocol (MCP) Integration

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

CLAUDE CODE CLI / MCP SERVER

Custom MCP server integration failing with silent transport errors

We are integrating a custom Model Context Protocol (MCP) server to allow Claude Code CLI to securely access our internal Nacos configuration registry. However, the connection drops intermittently during the JSON-RPC initialization phase over stdio. We need to debug the transport layer and ensure the tool schema is exposed correctly without polluting the output stream.

我们正在集成一个自定义的 MCP (模型上下文协议) 服务器,以便让 Claude Code CLI 安全地访问我们内部的 Nacos 配置注册中心。但是,在通过 stdio 进行 JSON-RPC 初始化阶段时,连接偶尔会中断。我们需要调试传输层,并确保工具的 Schema 被正确暴露,同时不污染输出流。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Registry /ˈredʒɪstri/ 注册中心 / 注册表

A centralized system for managing configurations and service discovery.

"The MCP server fetches the latest service endpoints from the Nacos registry."

Stdout / Stderr /ˌstæn.dɚd ˈaʊt/ 标准输出 / 标准错误

Standard output and error streams used for inter-process communication.

"Ensure the MCP server only logs debug messages to stderr, leaving stdout strictly for JSON-RPC payloads."

Capabilities /ˌkeɪpəˈbɪlətiz/ 能力 / 功能特性

The set of features or tools a server declares it can support during the handshake.

"The server must declare its tool execution capabilities during the initialization request."

Proxy /ˈprɒksi/ 代理 / 转发

To forward requests from a client to a server securely across boundaries.

"We can proxy the MCP traffic through Cloudflare to inspect the malformed packets."

Overhead /ˈoʊvərhed/ 系统开销 / 额外负担

The processing or latency cost required to perform a specific task.

"Using SSE (Server-Sent Events) for the MCP transport introduces more overhead than standard stdio."

Lifecycle /ˈlaɪfˌsaɪkəl/ 生命周期

The series of states a process or connection goes through from initialization to termination.

"We need to manage the lifecycle of the MCP subprocess carefully to prevent zombie processes."

Section 3 Native Engineer Expressions
JG

"It's polluting the stdout stream."

污染了标准输出流 · Use when logs or unexpected data break JSON-RPC parsing

JG

"The server failed to negotiate capabilities."

服务器未能完成能力协商 · Use when the client and server cannot agree on supported MCP features

JG

"We need to isolate the transport layer."

我们需要隔离传输层 · Use when debugging if the issue is in business logic vs connection protocol

JG

"Let's pipe the debug logs to a separate file."

把调试日志重定向到单独的文件中 · Use when managing standard streams to avoid interference

JG

"The tool call is timing out at the perimeter."

工具调用在边界处超时 · Use when a request fails at the network boundary like Cloudflare/API gateway

Section 4 Technical Reading

The Model Context Protocol (MCP) standardizes how AI agents interact with external data sources and tools. When integrating an MCP server via a local subprocess, the client and server communicate exclusively over standard input (stdin) and standard output (stdout) using JSON-RPC 2.0 messages.

A common anti-pattern in MCP development is emitting application logs to stdout. This pollutes the stream and causes the client to parse malformed JSON payloads, abruptly terminating the connection. To ensure robust interoperability, all telemetry, debugging, and warning logs must be strictly routed to standard error (stderr) or piped to an external file.

During the initial handshake, both parties negotiate capabilities; if the server fails to expose its tool schemas within the timeout threshold, the client will assume the subprocess is hanging and kill it.

Comprehension Check

1. Why might an MCP client abruptly terminate the connection according to the text?

The server failed to authenticate the client securely.
The server sent debug logs to standard output, breaking the JSON-RPC parsing.
The client lacks the required Nacos configuration registry.
The SSE transport overhead was too high for the payload.

2. Where should developers send telemetry and debugging logs in an MCP subprocess architecture?

To the standard output stream (stdout).
Directly to the Nacos configuration center.
To the LangGraph orchestration layer.
To standard error (stderr) or an external file.

3. What happens if the server does not expose its tool schemas in time during the handshake?

The client assumes the subprocess is hanging and kills it.
The client retries the initialization indefinitely.
The server routes the request through a proxy automatically.
The capabilities are safely inherited from previous sessions.
Section 5 Writing Task

The custom MCP server for your Halo PSA integration keeps crashing in Claude Code CLI. You discovered a third-party library is writing warning logs to stdout, which breaks JSON-RPC parsing. Write a brief Slack update to your team.

  • 1.Clearly state the root cause of the crash.
  • 2.Mention the terms "stdout" and "stderr".
  • 3.Propose a quick fix (e.g., redirecting logs).
  • 4.Keep it under 80 words.
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct tense usage for technical diagnosis; accurate subject-verb agreement.
Vocabulary / 20 pts
Proper use of required technical terms like "stdout", "stderr", and "JSON-RPC".
Clarity / 20 pts
Root cause and proposed solution are immediately obvious.
Professionalism / 20 pts
Tone is engineering-focused, factual, and solution-oriented.
Native-like Expression / 20 pts
Uses an authentic phrase like "polluting the stream" or "breaks the parser".
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Ephemeral

短暂的 / 临时的

Used for short-lived containers or tokens.

Introspection

内省 / 反省

Examining a system's own state or schema.

Arbitrary

任意的 / 随机的

Executing unauthorized or random code.

2 Expressions from Previous Lessons

"The process is hanging on startup."

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

Section 8 Challenge Zone ⚡ Above current level

When orchestrating multiple MCP servers for an AI agent, what are the architectural trade-offs between using a standard input/output (stdio) transport versus a Server-Sent Events (SSE) HTTP transport? Mention latency, security, and deployment complexity in your answer.

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