Module 3 · AI Engineering English
🔥 18 day streak

Lesson 19: MCP (Model Context Protocol) Integration

2026-06-20 · ~20 min · B1 → C1 · Section 1 / 8
Section 1 Today's Scenario
#TKT-8942 P2 · High In Progress

Daily English Lab Agent / MCP Server

MCP Server connection drops intermittently during tool discovery via SSE

We are integrating a custom MCP server into the Daily English Lab Agent using the SSE transport layer. However, Claude Code CLI is reporting intermittent connection drops during the tool discovery phase. We need to debug the negotiation process and ensure the capabilities schema is properly exposed before the timeout hits.

我们正在将自定义MCP服务器集成到Daily English Lab Agent中,使用的是SSE(Server-Sent Events)传输层。但是Claude Code CLI在工具发现阶段报告了间歇性的连接中断。我们需要调试协商过程,并确保在超时之前正确暴露了能力层模式(capabilities schema)。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Transport Layer /trænˈspɔːrt ˈleɪ.ər/ 传输层

The underlying communication mechanism (Stdio or SSE) used by the Model Context Protocol.

"We need to switch the transport layer from Stdio to SSE for remote access."

Ping /pɪŋ/ 连通性测试 / 保活检测

A basic JSON-RPC message sent to check if the connection is alive or to prevent timeouts.

"Implement a keep-alive ping interval to prevent the SSE connection from dropping."

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

The sequence of states an MCP connection goes through, from initialize to shutdown.

"The MCP server lifecycle requires a strict initialize-then-initialized handshake sequence."

Prompt Template /prɒmpt ˈtɛm.plət/ 提示词模板

A pre-defined structure exposed by an MCP server for LLM context generation.

"The server exposes several prompt templates for code review and lesson generation tasks."

Resource URI /ˈriː.sɔːrs juː.ɑːr.aɪ/ 资源统一资源标识符

A unique identifier formatted as a URI used to access specific contextual data via MCP.

"The agent fetches the system logs using a custom resource URI scheme."

Pagination /ˌpædʒ.ɪˈneɪ.ʃən/ 分页

The process of dividing a large dataset (like a long list of resources) into discrete pages.

"The resource discovery endpoint is timing out, so we need to implement pagination."

Section 3 Native Engineer Expressions
JG

"The SSE connection is timing out during the handshake phase."

SSE连接在握手阶段超时。 · Use when debugging network drops in early connection steps.

JG

"Can we implement a keep-alive ping to prevent the transport from dropping?"

我们能实现一个保活ping机制来防止传输断开吗? · Use when proposing a solution for idle disconnects.

JG

"Let's verify if the server is correctly advertising its tool capabilities."

我们来验证一下服务器是否正确声明了它的工具能力。 · Use during integration testing of an MCP server.

JG

"The CLI is throwing a JSON-RPC parse error on the payload."

CLI在解析载荷时抛出了JSON-RPC解析错误。 · Use when describing serialization or formatting bugs.

JG

"We need to decouple the tool execution from the main agent loop."

我们需要将工具执行与主智能体循环解耦。 · Use in architecture reviews to improve system design.

Section 4 Technical Reading

The Model Context Protocol (MCP) provides a standardized way for AI models to interact with local and remote data sources. An MCP architecture typically consists of a client, like the Claude Code CLI, and an MCP server. Communication occurs over a transport layer, usually Stdio for local subprocesses or SSE (Server-Sent Events) for remote integrations.

The connection lifecycle begins with an initialization handshake, where the client and server negotiate protocol versions and advertise capabilities. Once the handshake completes, the server can expose resource URIs, prompt templates, and executable tools. When designing the Daily English Lab Agent, we utilize SSE transport to allow the agent to fetch contextual data asynchronously. Proper handling of the JSON-RPC payload and implementing a robust keep-alive ping are crucial. Failure to maintain active signaling often results in the orchestrator dropping the connection unexpectedly during complex, long-running tool calls.

Comprehension Check

1. Which two transport layers are typically used in MCP architecture?

TCP and UDP
Stdio and SSE
HTTP/2 and WebSockets
gRPC and REST

2. When does the server advertise its capabilities to the client?

During the initialization handshake
After the first tool call is executed
Only when requested via a specific Resource URI
Before the transport layer is established

3. According to the passage, why is implementing a keep-alive ping important?

It reduces the memory footprint of the LLM.
It encrypts the JSON-RPC payload for security.
It prevents the orchestrator from dropping the connection unexpectedly.
It automatically parses prompt templates into executable code.
Section 5 Writing Task

Write a short technical update to your team via Slack regarding the #TKT-8942 issue.

  • 1.State that the intermittent connection drop during tool discovery is caused by an SSE timeout.
  • 2.Mention that you plan to implement a keep-alive ping as a workaround.
  • 3.Ask a team member to review the JSON-RPC payload logs.
  • 4.Keep it under 80 words.
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct verb tenses for actions taken vs. future plans (e.g., "is caused by", "I plan to").
Vocabulary / 20 pts
Accurately uses "timeout", "keep-alive ping", and "JSON-RPC payload".
Clarity / 20 pts
The root cause and proposed fix are clearly stated in the first two sentences.
Professionalism / 20 pts
Slack-appropriate tone—direct, collaborative, and engineering-focused.
Native-like Expression / 20 pts
Uses standard tech phrasings like "I'll implement..." or "Could someone review...".
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Subprocess

子进程

The client launches the MCP server as a local subprocess.

Negotiation

协商

Protocol version negotiation failed between client and server.

Ephemeral

短暂的 / 临时的

The agent uses ephemeral containers to execute arbitrary code safely.

2 Expressions from Previous Lessons

"The server is choking on the initialization request."

"Are we validating the tool input schema on the server side?"

Section 8 Challenge Zone ⚡ Above current level

In an MCP architecture using SSE, why might a standard HTTP timeout configuration cause intermittent failures during complex, long-running tool calls? Describe one architectural pattern to solve this without just increasing the timeout globally.

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