Module 3 · AI Engineering English
🔥 7 day streak

Lesson 08: MCP Server Integration

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

CLAUDE CODE CLI / MCP INTEGRATION

MCP Server fails to initialize tools during handshake

I am trying to integrate a custom MCP server with the Claude Code CLI to enable local PostgreSQL querying. However, the CLI hangs during the initialization phase, and the tool definitions are not being registered in the context window. We need to debug the transport layer to see if the JSON-RPC payload is malformed.

在尝试将自定义的 MCP 服务器与 Claude Code CLI 集成以实现本地 PostgreSQL 查询时,CLI 在初始化阶段挂起,工具定义未能注册到大模型的上下文窗口中。我们需要排查传输层通信,确认 JSON-RPC 格式是否正确。

Section 2 Core Vocabulary Click gray bar to reveal Chinese
Invocation /ˌɪnvəˈkeɪʃən/ 调用

The act of triggering or executing a function, tool, or API endpoint.

"The LLM's tool invocation failed because the mandatory parameters were missing from the JSON payload."

Transport /ˈtrænspɔːrt/ 传输/通信层

The underlying mechanism used to pass messages between the client and server (e.g., stdio, SSE).

"Claude Code CLI uses stdio as the default transport for local MCP servers, preventing the need for exposed network ports."

Subprocess /ˈsʌbˌprɒsɛs/ 子进程

A secondary process spawned and managed by a parent program to execute a specific task.

"The MCP client launches the server as a local subprocess, so any crash in the server won't tear down the whole agent."

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

The sequence of states an object, connection, or process goes through from creation to termination.

"We need to handle the complete MCP server lifecycle, including sending graceful shutdown signals to prevent resource leaks."

Initialization /ɪˌnɪʃəlaɪˈzeɪʃən/ 初始化

The required setup phase where systems connect, authenticate, or exchange capabilities before operation.

"The handshake stalled during the initialization sequence because the server returned an invalid JSON schema."

Section 3 Native Engineer Expressions
JG

"The CLI is hanging during the tool discovery phase."

CLI 在工具发现阶段挂起了。 · Use when describing a stuck process during initialization

JG

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

检查一下客户端和服务器的协议版本是否一致。 · Use when debugging handshake failures

JG

"I suspect the transport layer is dropping packets over stdio."

我怀疑传输层在通过 stdio 通信时丢包了。 · Use when investigating intermittent I/O issues

JG

"Let's tail the logs and see what the MCP server is actually receiving."

我们追踪一下日志,看看 MCP 服务器到底接收到了什么。 · Use during live debugging sessions

JG

"The tool execution failed because of a schema mismatch."

由于模式不匹配,工具执行失败了。 · Use when LLM payload doesn't fit the expected parameters

Section 4 Technical Reading

The Model Context Protocol (MCP) establishes a standardized architecture for connecting AI models to external data sources and tools. When integrating an MCP server with a client like the Claude Code CLI, the transport mechanism is critical. Typically, local servers operate via stdio, acting as a subprocess where JSON-RPC messages are exchanged over standard input and output streams.

During initialization, the client and server perform a handshake to negotiate protocol versions and advertise capabilities. If the server fails to expose its tool schema correctly during this phase, the client cannot inject those capabilities into the LLM's context window. This often results in the CLI hanging or returning an invocation error. To troubleshoot, engineers must isolate the transport layer, verify the JSON-RPC payload, and ensure no background processes are interfering with the stdio streams and lifecycle events.

Comprehension Check

1. What transport mechanism is typically used for local MCP servers in this context?

Server-Sent Events (SSE)
Standard input and output streams (stdio)
WebSockets
REST APIs over HTTPS

2. Why might the CLI hang during the initialization phase?

The LLM exceeded its context window token limit.
The subprocess was successfully killed.
The server failed to expose its tool schema correctly during the handshake.
The client rejected the JSON-RPC payload format permanently.

3. According to the passage, what must engineers verify to troubleshoot an invocation error?

The JSON-RPC payload and the transport layer.
The pricing tier of the Claude API.
The maximum token length of the LLM.
The internet connection speed.
Section 5 Writing Task

Write a brief update in Jira ticket #TKT-8492 explaining your progress.

  • 1.State that you successfully reproduced the CLI hang issue.
  • 2.Mention that the root cause appears to be a schema mismatch during initialization.
  • 3.Propose debugging the transport layer logs to inspect the JSON-RPC payloads.
  • 4.Keep it concise (under 80 words).
0 words
Section 6 AI Review Rubric
Grammar / 20 pts
Correct tense usage for past actions (reproduced) and current/future proposals (debugging, plan to inspect).
Vocabulary / 20 pts
Uses "initialization", "schema mismatch", and "transport layer" accurately.
Clarity / 20 pts
Root cause and proposed next steps are stated immediately without filler words. Under 80 words.
Professionalism / 20 pts
Tone is objective, engineering-focused, and appropriate for an internal Jira ticket.
Native-like Expression / 20 pts
Uses standard industry phrasing like "reproduced the issue", "root cause is", or "inspect payloads".
Total 100 pts
Section 7 Spaced Repetition Review Tap card to flip

3 Words from Previous Lessons

Discoverability

可发现性

How easily a client can find advertised tools.

Expose

暴露 / 公开

Making an API or tool schema available to clients.

Schema

模式 / 架构

The structural definition of expected parameters.

2 Expressions from Previous Lessons

"The MCP server is failing to advertise its tools."

"It looks like a schema mismatch between the advertised tool and the LLM's invocation."

Section 8 Challenge Zone ⚡ Above current level

When implementing a Multi-Agent System using MCP, why is it risky to rely entirely on a single stdio-based local MCP server for all agents? Discuss potential bottlenecks and suggest an alternative transport or orchestration architecture.

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