跪拜 Guibai
← All articles
Interview

Wiring Four MCP Servers into One Agent: Maps, Chrome, Filesystem, and a Custom Tool

By 黄敬峰 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most MCP tutorials stop at a single local server. This walkthrough shows the real integration pattern: mixing remote and local servers, handling rate limits, path sandboxing, and the agent loop's exact message shape. The six bugs are the kind that cost hours in practice, and each fix is spelled out.

Summary

The setup mixes remote HTTP MCP (Amap's geolocation and hotel-search APIs) with three local stdio servers: Chrome DevTools for browser control, FileSystem for disk access, and a hand-rolled user-lookup tool. A DeepSeek model drives the agent loop, deciding which tool to invoke across five rounds until the task is complete.

Six concrete pitfalls are documented: a missing `type` field that breaks IDE config parsing, `@langchain/openai` requiring `apiKey` inside the `configuration` object, dotenv loading from the wrong working directory, Amap's free-tier QPS limit triggering failures, FileSystem's path sandbox blocking writes, and a stray semicolon that silently moved tool-call handling outside the agent loop.

The result is a working multi-tool agent that geocodes an address, fetches nearby hotel details and images, generates an HTML page, and opens it in Chrome — all driven by a single natural-language prompt.

Takeaways
Remote MCP servers connect via a `url` field; local ones spawn a child process with `command` and `args`.
`npx` auto-downloads and runs an npm package, while `node` executes a local `.mjs` file directly.
`@langchain/openai` v1.5.5 ignores a top-level `apiKey`; the key must go inside the `configuration` object.
dotenv loads `.env` from the current working directory, not the script's directory, unless a path is explicitly set.
Amap's free API rejects bursts of parallel calls; a 500ms delay between tool invocations avoids QPS errors.
FileSystem MCP enforces a sandbox: writes outside the configured root directory fail with an access-denied error.
A stray semicolon after a `for` loop body can silently exclude tool-call handling from the agent loop, executing it only once after the loop ends.
Conclusions

The agent loop's reliability hinges on correctly threading `tool_call_id` into every `ToolMessage`; omitting it breaks the model's ability to associate results with calls.

LangChain's `MultiServerMCPClient` treats remote and local servers identically after connection, but the failure modes differ sharply — network errors vs. process crashes vs. path sandbox violations.

The six pitfalls are not MCP-specific; they are standard Node.js and API-integration traps that become critical when an autonomous agent makes dozens of sequential calls without human intervention.

Concepts & terms
MCP (Model Context Protocol)
An open standard for communication between AI agents and external tools. Servers expose tools via stdio (local subprocess) or HTTP (remote service), and agents discover and invoke them through a uniform interface.
Agent Loop
A cycle where an LLM receives a prompt, optionally decides to call tools, receives tool results, and repeats until it produces a final answer. Each iteration carries the full message history.
stdio transport
A local MCP communication mode where the agent spawns the server as a child process and exchanges JSON messages over standard input/output.
HTTP (SSE) transport
A remote MCP communication mode where the agent connects to a server over HTTP, often using Server-Sent Events for streaming responses.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗