跳转到主要内容

跨模型、工具、服务、公司、提供商、API、套餐、文章和新闻进行搜索。

MCP 协议高级 1 小时

MCP 进阶:从玩具服务器到生产部署

入门教程不会讲的主题:安全与校验、会话与状态、规模化工具设计,以及生产环境的长期维护。

MCP 进阶:从玩具服务器到生产部署

Beyond the MCP hello-world

Most MCP tutorials end at a demo server; the gap between that and a production server is exactly where the real problems live. This tutorial covers that gap.

Security and validation

Your server is a trust boundary. Validate every tool input (schema is not enough — check logical ranges), confine filesystem access to an explicit root, and ask for explicit approval on sensitive operations. Remember: the model reads tool descriptions — a third-party server with a manipulated description can steer model behaviour. Install unknown servers with the same care you audit an npm package.

Sessions, state and scale

A stateless server scales trivially; if you need state, externalise it (database/cache) rather than keeping it in process memory. For long operations, report progress so the client can show something live. Give every tool a timeout — one slow tool stalls the whole agent loop.

Tool design at scale

As the tool count grows, selection quality drops: dozens of similarly-described tools raise the wrong-tool rate. Group related tools, keep descriptions distinct and short, and build one high-level composite tool for common combinations instead of hoping the model chains calls correctly. Tool output has a contract too: summarise or paginate large results.

Deployment and maintenance

Structured logs for every call (tool, input, duration, result), server versioning, and a small test suite run after every change. An MCP server is a product like any other service; the only difference is that its customer is a language model deciding from your descriptions.