Repository navigation
[Feature] Add configurable pre-upstream tool-schema budgeting for large MCP catalogs #5464
Replies: 2 comments
Follow-up: reproduced with exact numbers, and a working implementationSince filing this I hit the failure in a real session rather than in a synthetic test, captured the payload, and built a working implementation as a plugin. Posting the details in case they help anyone evaluating this idea. The failure is not a context-overflow edge case — it is turn 1Codex Desktop serialises every connected app into on the first message of a brand new conversation, before any history exists. A 9-token request to the same model and credential returned 200, so the credential itself was healthy — it is purely a size gate. Tool counts by source in that capture:
And within the connected apps, the largest contributors by tool count: github 89, linear 74, adobe 73, google_drive 45, figma 33, atlassian 31, supabase 28, sites 23, gmail 21, notion 19 — followed by a long tail of small ones (travel, crypto, misc) that no coding session ever calls. The distribution is the useful part: a budget does not need to be aggressive to help. Trimming the long tail of unused connector catalogs is enough on its own to get back under the window. Why compaction does not solve itI checked PR #5516 (synthesize Codex compaction for Claude, Antigravity and Gemini upstreams) first, since it looked like the natural fix. It compacts conversation history, and the failure happens where there is no history to compact. The tool schemas ship regardless. Compaction and tool budgeting address different halves of the payload. Implemented as a
|
|
Reproduced the same failure mode here — 6 servers × 12 tools was ~33.4k tokens of tool definitions sitting in context before a single prompt was sent, and yes, quality degrades long before you run out of window. For anyone evaluating pre-upstream budgeting: one thing that helped me beyond hard token caps was relevance ranking. A flat cap still keeps whatever happens to be first; ranking per task and exposing only top-K (with a meta-tool to pull more on demand) preserved most of the win without agents losing access to tools they actually needed mid-task. I ended up extracting my approach into a standalone proxy (ctxslim — https://github.com/v01dst/ctxslim) since it seemed generally useful; it sits between client and servers, is 100% local with no API keys, and would slot in at exactly the layer this discussion is about. Numbers + benchmark methodology are in the repo if useful for comparison with whatever budgeting approach lands here. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
When an OpenAI Responses client sends a large MCP catalog, the Responses-to-Claude translation path forwards every distinct supported tool after format conversion. There is currently no pre-upstream budget for the translated
toolsarray.With clients that expose many MCP connectors, tool schemas alone can consume hundreds of thousands of tokens before conversation history and tool outputs are counted. This can leave little or no usable context and can make the final request exceed an upstream model or transport limit.
This is a feature request for an optional, deterministic tool-schema budgeting step before the final upstream request is sent.
Version tested
v7.2.14717a65ee5470fbaf0e22fc219381e6a4ae9e07624Evidence
Anonymized real-request measurements
A local pre-proxy observed the following before forwarding to CLIProxyAPI:
JSON length / 4estimateAfter the local pre-proxy reduced the tool schemas and history, the final request estimate was 41k-88k tokens and many upstream requests returned HTTP 200.
Important limitation: this capture did not record an unguarded upstream HTTP 400 or 413. It recorded one HTTP 429 rate-limit response and several socket hang-ups, which are separate from the tool-budget problem. Therefore this report does not claim that a specific 400/413 was reproduced.
Synthetic translator test
I also tested the exact commit above with a synthetic OpenAI Responses request containing 60 large function-tool schemas. The exported converter
ConvertOpenAIResponsesRequestToClaudeproduced:The test passed only when all 60 tools remained in the translated payload. This matches the current converter loop, which converts every winning descriptor and appends all converted entries to
tools:CLIProxyAPI/internal/translator/claude/openai/responses/claude_openai-responses_request.go
Lines 492 to 518 in 17a65ee
Current behavior
The translator removes unsupported tool types and resolves duplicate names, but it does not apply a byte or token budget to the surviving schemas. The finished request is then sent upstream.
Expected behavior
CLIProxyAPI should offer an opt-in request/tool budgeting policy for translated requests. A possible configuration could include:
tool-schema-budget-tokensand/ormax-upstream-request-bytes;reject,allowlist, orcompact;tool_choice;Keyword-based semantic selection could be an optional strategy, but it should not be the only rule: a model may need a tool whose name does not appear in the latest user message. Silent removal without diagnostics would also be difficult to debug.
Suggested acceptance tests
{ "type": "object" }schema.Privacy note
The original full backup and raw request payload are not attached because they contain OAuth material and private conversation data. The figures and synthetic test above are anonymized and contain no account identifiers or secrets.
All reactions