跪拜 Guibai
← All articles
Design Patterns · Design

One Agent, Four Servers: Wiring Maps, Browsers, and Files into a Single AI Loop

By 烬羽 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Multi-server MCP setups collapse what used to be separate integrations — maps, browsers, file I/O — into a single agent loop with no custom middleware. The `MultiServerMCPClient` pattern means adding a new capability is a config entry, not a new code path.

Summary

MCP acts as a universal tool bus for AI models, and this walkthrough demonstrates the multi-server architecture that makes it practical. A `MultiServerMCPClient` aggregates tools from four distinct servers — a remote HTTP-based Amap service for location data, a local stdio-based Chrome DevTools server for browser control, a custom arithmetic server, and a filesystem server — into one flat tool list. The agent loop then lets DeepSeek reason across them: it searches for hotels, fetches details, and writes results to disk without per-tool glue code.

The configuration shows two transport patterns side by side. Remote servers connect over HTTP with a single URL, while local servers launch as child processes over stdio, including npm packages invoked through `npx`. The agent itself is a straightforward while-loop that feeds tool results back into the conversation as `ToolMessage` objects, with a max-iterations guard against runaway calls.

A custom MCP server boils down to three pieces: a name, a Zod parameter schema that the model reads to understand inputs, and an async handler that returns a standard `{ content: [...] }` shape. The Chrome DevTools server exposes 29 browser-control tools — navigation, clicks, screenshots, console inspection — all callable through natural language.

Takeaways
`MultiServerMCPClient` from LangChain’s MCP adapter merges tools from HTTP and stdio servers into one list the model can call.
Remote MCP servers connect via a URL; local servers launch as child processes using `command` and `args` in the config.
An agent loop sends user queries to the model, executes any requested tool calls, feeds results back as `ToolMessage` objects, and repeats until the model returns text.
Custom MCP servers require only a name, a Zod schema describing parameters, and a handler that returns `{ content: [{ type: 'text', text: '...' }] }`.
Chrome DevTools MCP provides 29 tools — navigation, clicks, screenshots, console inspection — all controllable through natural language.
Environment variables for API keys are managed with `dotenv`; keys are never hardcoded.
Conclusions

The architecture treats tools as interchangeable resources: the model never knows or cares whether a tool came from a remote HTTP service or a local subprocess.

Stdio transport means MCP servers can be written in any language that reads stdin and writes stdout, not just JavaScript or Python.

The agent loop is deliberately simple — no planning module, no reflection step — yet chains multi-step tasks across unrelated services reliably because each tool result is just another message in the conversation.

Concepts & terms
MCP (Model Context Protocol)
An open standard from Anthropic that defines how AI models discover and invoke external tools. It separates tool providers (servers) from tool consumers (clients) so any compliant server can plug into any compliant host without custom integration code.
MultiServerMCPClient
A LangChain adapter that reads a config of multiple MCP servers — both remote HTTP and local stdio — fetches all their tool definitions, and merges them into a single list that can be bound to a model via `bindTools()`.
Agent Loop
A while-loop pattern where the model receives a user query, optionally requests tool calls, the host executes those calls, and the results are appended to the conversation as ToolMessages. The loop repeats until the model produces a final text response or hits an iteration limit.
stdio Transport
A local MCP connection method where the client launches the server as a child process and they communicate over standard input/output with JSON messages. This lets MCP servers be written as command-line programs in any language.
Zod
A TypeScript-first schema declaration and validation library. In MCP, Zod schemas define the names, types, and descriptions of tool parameters so the AI model can understand what inputs a tool expects.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗