Repository navigation
Description
Is your feature request related to a problem? Please describe.
rmcp sends every tool from every connected server through to the host, and there is no way to say how a tool should be exposed. This works fine with small servers, but it breaks down in three ways:
- Schemas are re-sent every turn. Anthropic measured ~77K tokens before the first user message with 50+ MCP tools (Advanced tool use). Servers with big tool surfaces already work around this alone: ghidra-mcp (209 tools) implements its own lazy loading (
search_tools/load_tool_group) because hosts don't do it. - Tool results always round-trip through the model, even when they're just input for the next tool call. Anthropic measured 150K → 2K tokens for exactly this pattern (Code execution with MCP).
- Server authors can't declare intent ("these tools only make sense scripted together", "search, don't preload"). Every host invents its own policy, so no convention exists across hosts, and nothing in the SDK carries it.
The ecosystem has already converged on the fix. pi ships a codemode tool (docs) and OpenCode 2.0 makes code mode the default for all MCP servers (release notes, packages/codemode); Codex reserves the same three states in its exposure enum (ToolExposure::Direct | Deferred | CodeModeOnly, codex-rs/tools/src/tool_executor.rs) and Anthropic standardizes deferred discovery (Tool Search Tool). The Rust SDK can't express any of it.
Describe the solution you'd like
Two primitives:
A client-side aggregation interface. rmcp's client role connects to N upstream servers, but composing them into one logical server (merged tools/list with namespaces, routed tools/call) is up to each implementer today. A trait covering "connect upstreams → aggregated registry → dispatch" gives third-party crates one shape to build on.
Per-server exposure metadata. A standard way to declare a server's tools as:
direct— intools/listevery turn (today's behavior)deferred— discoverable via a search primitive, schema fetched on demandcodemode— callable only from a script sandbox; never in the model's tool list, results pipe between tools
Sketch (semantics follow pi's codemode — MCP tools deferred by default inside the sandbox, BM25 searchTools for discovery; naming mirrors Codex's enum so the convention reads the same everywhere):
pub enum ToolExposure {
/// In tools/list every turn (current behavior).
Direct,
/// Discoverable via search; schema fetched on demand.
Deferred,
/// Callable only from a script sandbox.
CodeModeOnly,
}Describe alternatives you've considered
- Leave exposure to hosts. Every host implements its own policy, server authors keep writing host-specific workarounds, and Rust-built hosts/aggregators reinvent the same layer each time.
- Wait for the MCP spec. Slower than the ecosystem is moving. pi's ecosystem already ran this curve: a third-party extension (
mcp-adapter'smcpScript, January 2026) proved demand, then the host built it in (codemode, later in 2026). An SDK-level convention can be validated now and feed a spec proposal later. - Third-party crates with no SDK support. Aggregators can be built today — I'm building one — but without an agreed interface for upstream composition and exposure, every aggregator invents its own shape and none interoperate.
Additional context
I'm starting a third-party crate, rmcp-codemode, as a reference implementation: a client-side aggregator that exposes upstream servers' tools to any host as a codemode script tool — QuickJS sandbox (rquickjs), BM25 tool search, upstream MCP tools as namespaced JS functions. The semantics follow pi's shipped design (tools deferred inside the sandbox by default, discovery via search) rather than a new proposal; OpenCode's packages/codemode is the second reference for the aggregation side, and Cloudflare's Code Mode proves the same architecture works as a standalone layer (their MCP portal demoed 300+ tools → 3 from the host's view).
It stays out of this workspace on purpose: QuickJS can't meet the dependency policy, and exposure logic belongs to hosts anyway. The PoC's job is to find out which parts make sense as SDK primitives, so the crate is the input, not the ask.
Questions:
Does the SDK already provide anything for aggregating multiple upstream servers into one logical server? If not, is there anything in the current client API that would make a third-party aggregator fight the design?
Host-side discussions: zed#66626 (the same feature for the Zed agent, host-level argument) and zed#64004 (deferred tool discovery, the step codemode builds on). Server-author case for the result-cost problem: zed-mcp-server-markitdown — one tool, convert_to_markdown(uri), and a PDF dumps the whole document into context.
Activity
github-actions commentedon Nov 7, 2026
@jamadeo is on triage rotation this week and is the reviewer for this one.
Codex labeled this enhancement / P3 (T-service, T-model). Please confirm or correct those labels.
Automated triage. Labels are a first pass and the assigned maintainer has the final say.
SalyyS1 commentedon Nov 11, 2026
We built an open-source reference proxy (SalyyS1/mcp-slim) that implements both
direct(schema-compacted) anddeferred(--lazyBM25 meta-tool discovery) exposure modes at the stdio JSON-RPC layer. Sharing our benchmark numbers and three edge cases we hit in production that directly apply tormcp's client-side aggregation design:1. Token Reduction Benchmarks (
directvs.deferred)Across a 45-tool MCP catalog (
github-mcp-server+ filesystem + database tools,12,512raw tokens per turn):direct(with$defs/$refinlining, nullableanyOfflattening, and redundant parameter description stripping):12,512 -> 6,406tokens (-48.8%) while keeping all 45 tools directly visible to the model.deferred(mcp_search_tools+mcp_call_toolmeta-tools):12,512 -> 168tokens (-98.7%upfront). When the model callsmcp_search_tools(query, limit=5), BM25 ranking over(tool_name, description, property_names)returns only the top-K matching schemas on demand.2. Three Edge Cases for
rmcpClient-Side Aggregationcall_toolbridge:When a tool is invoked through a deferred bridge (
call_tool(name, arguments)), the outer schema declaresarguments: {"type": "object"}with no inner property constraints. Because the LLM provider's constrained decoding cannot see the inner tool'sinputSchemaat the outercall_toolboundary, models frequently emit stringified scalars ("limit": "25","recursive": "true"). Coercingargumentsagainst the cached innerinputSchemainside the aggregator before forwarding to the upstream server eliminates-32602validation failures.(server_name, tool_name)):When
rmcpaggregates multiple servers concurrently,tools/listresponses arrive in non-deterministic order. Canonical sorting of both the mergedtoolsarray and each schema'spropertiesmap prevents unnecessary LLM KV-cache invalidation at thetoolsprefix boundary.CallToolResultcompaction:Even before adopting full
codemode, strippingnull/""/[]/{}fields, REST hypermedia links (_links,*_url), and flattening textEmbeddedResourceblocks cutstools/callresult tokens by43%+across typical API-backed MCP servers.