Repository navigation
DeepSeek adapter: let tool results carry tool_reference so large MCP catalogs can stay deferred (the official endpoint already supports it)
#10812
kirkchinese
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
dsh-mcp-clientregisters every discovered MCP tool, and the registry sends every visible schema with every request. Large servers make this expensive. REA 6.7.0, which lists DeepSeek Harness as a supported client, exposes 207 tools with about 668 KB of input schemas. With REA registered throughdsh-mcp-clienton 0.2.0-rc.2, the first request of a headless session reported 249,653 input tokens, and every later step repeated that prefix (cache hits keep the cost down, not the context use).PTC mode does not help here: its SDK text replaces the schemas at a comparable size, as the
dsh-toolsREADME notes. Mid-conversation registration (tool_addition) is the mechanism meant for growing tool sets, but it currently breaks sessions on the official endpoint (#10539, #10547, #10553, #10563).What the official endpoint already accepts
Measured on 2026-10-23 against
https://api.deepseek.com/anthropic/v1/messageswithdeepseek-flashanddeepseek-v4-pro:toolswithtool_search_tool_bm25_20251119or_regex_defer_loading: truedefer_loading: trueinput_tokens166, identical to the regular tool alone; the same 150 tools without the flag: 261,938tool_searchtool whosetool_result.contentis[{"type": "tool_reference", "tool_name": "<deferred tool>"}]tool_usefor the referenced deferred tool with correct argumentsSo the endpoint supports the client-side tool search pattern: deferred tools cost nothing until referenced, the tools array never changes, no
tool_additionblock is involved, and the prompt cache prefix stays stable. A minimal script that reproduces the table is attached below.What is missing in the Harness
ToolSchema.deferLoadingalready serializes todefer_loading, but a deferred tool only activates through atool-additiondeveloper message.WireInputindsh-llm-deepseekallows text and images only, and there is no harness content block that maps totool_reference(checked on 0.2.0-rc.2 and master 687f282).dsh-mcp-clienthas no option to register discovered tools as deferred.Proposal
{ type: 'tool-reference', toolName }, logged like any other result content so replay stays exact, and serialized by the DeepSeek Messages adapter to{ type: 'tool_reference', tool_name }insidetool_result.content. Routes that cannot carry it could project it to text, as image blocks are projected for text-only routes.toolUpdate) so the registry or a plugin knows whether references are supported.deferLoading: trueondsh-mcp-clientrows, plus a small search tool (built in or in a plugin) that returns references.This keeps the tool array fixed for the whole session, which also sidesteps the permanent-400 failure mode of mid-conversation tool changes.
Workaround we use today
A plugin that never changes the tools array: a compact family index in the system prompt plus fixed
capability_search/capability_describe/capability_calltools that proxy MCP calls and validate arguments against the original schema. With REA behind it, the first request of the same headless task reported about 9.2k input tokens instead of 249,653, and the task completed. It works today but costs an extra step per tool and loses native tool calls, which is why native references would be better. Source and measurements: https://github.com/kirkchinese/dsh-capability-catalog (npm@kirkchinese/dsh-capability-catalog).Reproduction script
All reactions