跪拜 Guibai
← All articles
Interview

Chaining Remote and Local MCP Servers into a Single Agent Workflow

By 嘟嘟0717 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

MCP’s transport abstraction means an Agent can mix local tools, remote APIs, and npm-published servers without glue code. A developer who understands the `url` vs `command + args` split can assemble multi-tool workflows in a single configuration file, turning the LLM into an orchestrator rather than a chatbot.

Summary

MCP’s protocol stays identical whether the transport is stdio or HTTP; only the connection method changes. A `MultiServerMCPClient` can manage a remote Amap maps server via a URL alongside locally spawned filesystem and Chrome DevTools servers, all configured in one object. `getTools()` fetches every tool at once, and a standard ReAct loop lets the LLM decide which to call.

The Agent chains `maps_geo`, `maps_around_search`, and `maps_search_detail` to find nearby hotels, then uses the Chrome DevTools server to open each image in a browser tab and rewrite the page titles. The filesystem server writes any results to disk, constrained to a single allowed directory for security.

Common failure modes include API rate limiting on free map keys, LLM-generated parameter formats that violate API schemas, and hallucinated Linux paths that trip the filesystem server’s directory allowlist. A `SystemMessage` that declares the working directory and parameter constraints prevents most of these.

Takeaways
An MCP Server can be connected via a local child process (`command + args`) or a remote HTTP endpoint (`url`); the protocol messages are identical.
`npx -y package-name` auto-downloads and runs an npm-published MCP Server without a separate install step.
`MultiServerMCPClient` accepts a single config object mixing all three connection types and returns every tool through `getTools()`.
The filesystem MCP Server enforces a security boundary: the last `args` parameter is the only directory it will touch; anything outside gets `Access denied`.
LLMs hallucinate filesystem paths (often Linux-style) unless the working directory is explicitly stated in a `SystemMessage`.
Tool return formats vary across servers, so a four-case handler normalizes bare strings, MCP content arrays, string content fields, and fallback JSON.
`tool_call_id` must be preserved in every `ToolMessage` so the LLM can match results to concurrent calls.
Free Amap API keys hit QPS limits when the Agent fires multiple `maps_search_detail` calls; batching or a paid key is required.
Chrome DevTools MCP exposes dozens of browser actions — `navigate_page`, `click`, `evaluate_script`, `take_screenshot` — as callable tools.
Conclusions

Transport independence is MCP’s quiet superpower: the same ReAct loop drives a local script, a cloud API, and a browser controller without any adapter layer.

Security in the filesystem server is path-based and enforced server-side, which means the Agent cannot escalate its own privileges even if the LLM is tricked.

The four-case return-value normalizer is a microcosm of MCP’s current maturity — the protocol standard exists, but real-world server implementations still diverge enough to require defensive parsing.

Rate limiting becomes a first-class Agent design concern when a single user prompt can trigger eight parallel API calls; prompt-level batching instructions are a cheap fix but fragile.

Concepts & terms
MCP Transport
The communication layer that carries MCP protocol messages. Stdio transport uses a spawned child process and standard I/O pipes; HTTP transport sends JSON-RPC over network requests. The protocol messages themselves do not change.
MultiServerMCPClient
A client class that manages multiple MCP Server connections simultaneously, each defined by a `url` (remote) or `command` + `args` (local). Calling `getTools()` aggregates all tools from every configured server.
ReAct Loop
A reasoning-and-acting pattern where an LLM iteratively decides whether to call a tool, executes it, feeds the result back into the conversation, and repeats until it produces a final answer or hits a maximum iteration limit.
npx
A Node.js command that downloads and runs an npm package in one step. The `-y` flag skips the install confirmation prompt. In MCP, it lets developers use published servers without manually cloning or installing them.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗