AI Skills AI技能 9h ago Updated 6h ago 更新于 6小时前 51

The MCP 2026–07–28 Spec Just Dropped — Here’s How to Build a Production-Ready MCP Server with Express.js MCP 2026-07-28 规范刚刚发布——如何使用 Express.js 构建生产就绪的 MCP 服务器

The MCP 2026-07-28 specification introduces a fundamental architectural shift by making the protocol stateless, eliminating the previous requirement for session handshakes and sticky routing. Developers can now deploy MCP servers behind standard round-robin load balancers, treating them like conventional REST APIs rather than complex stateful services. State management is offloaded to the application layer via an "explicit handle pattern," where models pass identifiers between tool calls instead MCP协议发布2026-07-28重大版本更新,核心变革是从有状态会话转向无状态HTTP架构,彻底移除initialize握手和Mcp-Session-Id头。 新规范引入显式句柄模式处理跨调用状态,利用Mcp-Method/Mcp-Name头部实现负载均衡器路由,并内置类似HTTP Cache-Control的缓存机制。 提供基于Express.js的生产级MCP服务器构建指南,强调将MCP逻辑与HTTP传输层解耦,采用模块化目录结构以符合微服务最佳实践。 官方SDK配套Express中间件自动处理Host验证和DNS重绑定保护,结合Zod进行参数校验,简化了安全且类型安全的开发流程。 协议

75
Hot 热度
70
Quality 质量
72
Impact 影响力

Analysis 深度分析

TL;DR

  • The MCP 2026-07-28 specification introduces a fundamental architectural shift by making the protocol stateless, eliminating the previous requirement for session handshakes and sticky routing.
  • Developers can now deploy MCP servers behind standard round-robin load balancers, treating them like conventional REST APIs rather than complex stateful services.
  • State management is offloaded to the application layer via an "explicit handle pattern," where models pass identifiers between tool calls instead of relying on server-side session storage.
  • New features include built-in caching mechanisms with TTL scopes, distributed tracing via W3C Trace Context, and first-class support for extensions like MCP Apps and Tasks.
  • Implementation guidance emphasizes using Express.js with strict separation of concerns, leveraging Zod for validation and official SDK packages for secure, scalable deployment.

Why It Matters

This update removes significant operational complexity for AI engineers, allowing MCP servers to scale horizontally with minimal infrastructure overhead. By aligning MCP with standard HTTP microservice patterns, it lowers the barrier to entry for backend developers and improves reliability in distributed environments.

Technical Details

  • Stateless Protocol Layer: The initialize/initialized handshake and Mcp-Session-Id header are deprecated. All context, including protocol version and client info, is transmitted within the _meta field of every request.
  • Explicit Handle Pattern: Instead of server-side session stores, application state is managed by minting unique handles (e.g., basket_id) in tool responses, which the LLM must explicitly pass back in subsequent requests.
  • Routing and Validation: Requests utilize Mcp-Method and Mcp-Name headers for efficient load balancing. Servers validate consistency between headers and request bodies, rejecting mismatches.
  • Caching and Tracing: Resource lists support ttlMs and cacheScope attributes similar to HTTP Cache-Control. Distributed tracing is enabled via W3C Trace Context propagation in the metadata.
  • Express.js Integration: The recommended stack uses @modelcontextprotocol/express for middleware handling (including DNS rebinding protection) and zod for runtime parameter validation, ensuring type safety and robust error handling.

Industry Insight

  • Infrastructure Simplification: Organizations can decommission complex session-sharing databases (like Redis clusters dedicated to MCP state) and rely on standard cloud-native scaling strategies, reducing cost and maintenance burden.
  • Security Posture Improvement: Moving away from sticky sessions mitigates risks associated with session hijacking and simplifies security audits, as each request is self-contained and verifiable.
  • Adoption Acceleration: By making MCP development indistinguishable from standard REST API creation, the learning curve for backend teams is drastically reduced, likely accelerating enterprise adoption of standardized AI tool integration.

TL;DR

  • MCP协议发布2026-07-28重大版本更新,核心变革是从有状态会话转向无状态HTTP架构,彻底移除initialize握手和Mcp-Session-Id头。
  • 新规范引入显式句柄模式处理跨调用状态,利用Mcp-Method/Mcp-Name头部实现负载均衡器路由,并内置类似HTTP Cache-Control的缓存机制。
  • 提供基于Express.js的生产级MCP服务器构建指南,强调将MCP逻辑与HTTP传输层解耦,采用模块化目录结构以符合微服务最佳实践。
  • 官方SDK配套Express中间件自动处理Host验证和DNS重绑定保护,结合Zod进行参数校验,简化了安全且类型安全的开发流程。
  • 协议层新增W3C Trace Context分布式追踪支持及MCP Apps/Tasks等一等公民扩展,提升了可观测性和异步任务处理能力。

为什么值得看

对于AI应用开发者而言,理解这一架构转变至关重要,因为它消除了传统MCP实现中复杂的会话管理和粘性路由痛点,使MCP服务器能像标准REST API一样轻松水平扩展。掌握新的无状态设计模式和显式句柄策略,是构建高可用、生产就绪型AI工具集成服务的关键前提。

技术解析

  • 无状态协议重构:废弃了原有的initialize/initialized握手流程,所有协议版本、客户端信息和能力描述均通过每个请求中的_meta字段传递。客户端可通过新的server/discover方法按需获取服务器能力,实现了真正的无状态交互。
  • 状态管理与路由优化:移除了Mcp-Session-Id,引入“显式句柄模式”(Explicit Handle Pattern),即由工具生成如basket_id这样的令牌并在后续调用中由模型传回以维持上下文。同时,请求携带Mcp-MethodMcp-Name头部,允许负载均衡器在不解析Body的情况下进行高效路由。
  • 工程化项目架构:推荐采用分层结构,将Express HTTP层(index.ts)、MCP服务器逻辑(server.ts)、工具定义(tools/)、资源定义(resources/)及中间件(middleware/)分离。这种关注点分离的设计便于维护和测试,符合生产环境标准。
  • 依赖与安全配置:使用@modelcontextprotocol/sdk@modelcontextprotocol/express作为核心依赖,后者提供轻量级中间件以防御DNS重绑定攻击。配合zod进行运行时参数验证,确保工具输入的类型安全和错误提示友好性。

行业启示

  • 基础设施标准化加速:MCP向无状态HTTP协议的演进标志着AI工具接口正式融入主流Web微服务生态,降低了集成门槛,预计将推动更多传统后端服务快速适配AI Agent需求。
  • 开发范式迁移:开发者需从“会话管理思维”转向“函数式/无状态思维”,在设计和实现AI工具时,应优先考虑幂等性和显式状态传递,而非依赖隐式的服务器端会话存储。
  • 可观测性与扩展性优先:内置的分布式追踪支持和官方扩展机制表明,行业正重视AI调用的全链路监控和复杂异步场景,企业在构建AI平台时应提前规划相应的监控体系和异步任务处理架构。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Open Source 开源 LLM 大模型 Deployment 部署