From REST to MCP: Building a Self-Hosted AI Agent Stack That Achieves Rapid Context Forking
说明与用途
从 REST 转向 MCP 通过将遗留服务包装为 MCP 工具,弥补了语义缺口,使 LLM 能够调用高级功能并在毫秒级别分叉上下文,同时保持主对话不受污染。
问题
Legacy REST/GraphQL APIs expose only endpoints, lacking semantic context for LLMs, causing brittle prompt‑engineering and poor multi‑step task execution.
结果
The stack enables instant context forking in 5.6 s on a 16 GB GPU, allowing sub‑tasks to run in isolated threads while the main agent remains responsive.
工作流
- 1. Extract API schemas using OpenAPI or GraphQL introspection.
- 2. Define MCP tools with input schemas (e.g., zod) and handlers that call existing REST endpoints.
- 3. Deploy an MCP Server Adapter to expose these tools.
- 4. Run an Agent Orchestrator that monitors tool calls and manages context forking.
- 5. When a sub‑task is needed, the orchestrator serializes the current context, spawns a child agent, injects the context into the local LLM KV‑cache, and resumes execution after the child returns its result.
证据
Traditional API gateways expose endpoints, but they do not expose semantics.
The 5.6-second forking metric cited in our benchmarks refers to the time it takes to clone the active context state, initialize a new sub-agent thread, and resume execution after a major context shift.
The adapter is the bridge between your existing REST/GraphQL codebase and the MCP protocol. It does not rewrite your business logic; it wraps it.
- 记录日期: 2026-10-06T18:55:54.560Z