lungeMCP

Architecture

A Rust core (execution + protocols + summarization) exposed to a thin TypeScript MCP layer via napi-rs. The FFI contract is JSON-string in / JSON-string out.

High-level split

  • crates/core - the Rust engine, compiled to a.node addon via napi-rs. Handles HTTP, GraphQL, WebSocket, SSE, assertions, templating, environments, the token optimizer, and the response store.
  • packages/mcp-server - the TypeScript MCP server (stdio transport). Tools live in src/tools/;src/native.ts is the typed wrapper over the addon.
  • scripts/e2e.mjs - end-to-end stdio verification (31 checks) that spins up a local test server and drives every tool.

FFI boundary

  • The Rust core must never write to stdout - stdout is the MCP JSON-RPC channel. Use stderr for diagnostics.
  • Cross the FFI boundary with JSON strings; keep camelCase on the wire (serde rename_all = "camelCase") so it matches the TypeScript types.
  • Every new core function is surfaced in packages/mcp-server/src/native.ts with an explicit TypeScript signature.

Streaming strategy

Bounded sessions (ws_session, sse_session) collect frames or events until a stop condition (max messages / max duration / matcher), then return a summarized batch. Persistent handles (ws_open /ws_send / ws_recv / ws_close) keep a live connection buffered on the Rust side for interactive flows.

Token optimizer

Every response is filtered, truncated, and summarized before it reaches the agent. Full payloads are spilled to an in-memory store and referenced by aresponseHandle. The agent escalates withinspect_response + a JSONPath when it needs more - paying only for the bytes it actually reads.