A request with `tool_choice: "none"` and no tools is forwarded with 16 tools including `Bash`, and `tool_choice` set to `auto`
Summary
Three behaviours combine so that a caller who grants no tools gets a request that grants shell execution.
- When the client sends no
tools, the provider branches substituteSTANDARD_TOOLS. The condition checks only whether tools were sent. It never looks attool_choice. - Roughly a dozen provider branches assign
tool_choice = "auto"unconditionally, sonone,required, a named tool and an allowed subset are all replaced. - On the
azure-anthropicpath, client tools that are not built-in aliases are rejected and replaced withDEFAULT_AZURE_TOOLS, andtool_choiceis deleted outright.
STANDARD_TOOLS contains 16 entries including Bash, Write, Edit, Read and Task. src/clients/standard-tools.js:78 is the Bash declaration, which takes a command string.
The result is that a caller expressing "do not use tools", with no tools declared, produces an upstream request offering shell execution with tool_choice: auto. Nothing in the response indicates this.
Captured
Client request:
{"model": "<provider-model>", "messages": [{"role": "user", "content": "G1 controlled request."}], "tool_choice": "none"}
Forwarded request, abbreviated. The full tool list is the 16 entries of STANDARD_TOOLS:
{"model": "<provider-model>",
"messages": [{"role": "system", "content": "[fmt-guard] ..."},
{"role": "user", "content": "G1 controlled request."}],
"tools": [{"name": "Write", ...}, {"name": "Read", ...}, {"name": "Edit", ...},
{"name": "Bash", "input_schema": {"type": "object", "properties": {"command": {"type": "string"}}, ...}},
...],
"tool_choice": "auto"}
A second capture, on the azure-anthropic path, shows the replacement case. The client declares its own tool:
{"model": "claude-opus-4-5", "messages": [{"role": "user", "content": "G1 controlled request."}],
"tools": [{"type": "function", "function": {"name": "tool_a", "strict": true, "parameters": {"type": "object", "properties": {}}}}]}
Forwarded:
{"model": "claude-opus-4-5",
"tools": [{"name": "WebSearch", ...}, {"name": "WebFetch", ...}, {"name": "Bash", ...}]}
tool_a is gone and three unrelated tools are in its place.
Root cause
Verified at 23cc328c1838.
Behaviour 1. src/clients/databricks.js:826
// Add tools - inject standard tools if client didn't send any (passthrough mode)
let toolsToSend = body.tools;
let toolsInjected = false;
if (!Array.isArray(toolsToSend) || toolsToSend.length === 0) {
toolsToSend = STANDARD_TOOLS;
toolsInjected = true;
logger.debug({ injectedToolCount: STANDARD_TOOLS.length, ... }, "=== INJECTING STANDARD TOOLS (OpenRouter) ===");
}
The same pattern repeats at lines 195, 539, 831, 908, 1013, 1461 and 1542. None of them consults body.tool_choice. The injection is recorded at debug level in the server log, so it is visible to an operator reading logs, but nothing is returned to the caller.
Behaviour 2. tool_choice is assigned a constant in each provider branch:
src/clients/databricks.js:1025 azureBody.tool_choice = "auto"; // Explicitly enable tool use
src/clients/databricks.js:1473 openAIBody.tool_choice = "auto"; // Let the model decide when to use tools
src/clients/databricks.js:1549 atlasBody.tool_choice = "auto";
src/clients/databricks.js:1698 llamacppBody.tool_choice = "auto";
src/clients/databricks.js:1794 lmstudioBody.tool_choice = "auto";
src/clients/databricks.js:2202 zaiBody.tool_choice = "auto";
src/clients/databricks.js:2407 moonshotBody.tool_choice = "auto";
src/clients/databricks.js:2561 baiduBody.tool_choice = "auto";
src/clients/databricks.js:2699 fireworksBody.tool_choice = "auto";
src/clients/databricks.js:2959 orcaBody.tool_choice = "auto";
Line 597 is the only branch that forwards what the caller sent:
if (body.tool_choice) ollamaBody.tool_choice = body.tool_choice;
Behaviour 3. src/orchestrator/index.js:1115
} else if (providerType === "azure-anthropic") {
const tools = sanitiseAzureTools(clean.tools);
clean.tools =
tools && tools.length > 0
? tools
: DEFAULT_AZURE_TOOLS.map((tool) => ({
name: tool.name,
input_schema: JSON.parse(JSON.stringify(tool.input_schema)),
}));
delete clean.tool_choice;
}
sanitiseAzureTools accepts only built-in tool-name aliases, so an arbitrary client tool is dropped, the list becomes empty, and DEFAULT_AZURE_TOOLS takes its place. Line 1124 then removes tool_choice entirely.
Reproduction
Built from this repository at an unmodified commit. The upstream is a recording endpoint that stores the exact request bytes it receives and returns a fixed valid response, so the forwarded bytes above are quoted verbatim rather than described.
curl -X POST http://localhost:<port>/v1/chat/completions \
-H 'content-type: application/json' -H "authorization: Bearer $KEY" \
-d '{"model":"<provider-model>","messages":[{"role":"user","content":"G1 controlled request."}],"tool_choice":"none"}'
Then read the outbound request, or enable debug logging and look for === INJECTING STANDARD TOOLS.
Expected
The narrow fix for the worst case is one condition. Do not inject when the caller said none:
if (body.tool_choice !== "none" && (!Array.isArray(toolsToSend) || toolsToSend.length === 0)) {
Beyond that:
- Injection should be opt in per route or per key rather than the default. A caller that declares no tools has expressed a capability boundary, and substituting a tool set widens it. Right now the only way to keep tools out of a request is not documented anywhere the caller controls.
tool_choiceshould carry the caller's value through, the way the Ollama branch already does. Where the target cannot express it, rejecting the request would be better than replacing it withauto.- On the
azure-anthropicpath, a client tool thatsanitiseAzureToolsrejects should produce an error naming the tool, not a substitution with a different tool set.
If injection is intentional for a passthrough mode, then the case worth separating is the one where tool_choice: "none" is present. There is no reading of that request under which the caller wants Bash.
Hi Thanks for reporting this issue I have fixed this in this PR https://github.com/Fast-Editor/Lynkr/pull/117
Hi Thanks for reporting this issue I have fixed this in this PR #117
Hello @veerareddyvishal144 the fix does not cover this case. Please correct me from wrong.
1. /v1/chat/completions still adds tools when the caller sends no tools
OpenAI Chat to OpenAI and OpenAI Chat to azure-anthropic. The chat completions router has its own injection (src/api/openai-router.js:563). It skips only when tool_choice is "none" or tools is an array. A request with no tools field gets IDE_SAFE_TOOLS before any provider branch runs.
sent: {"model": "<model>", "messages": [{"role": "user", "content": "..."}]}
Forwarded to OpenAI: 15 tools (Write, Read, Edit, Bash, Glob, Grep, MultiEdit, LS, NotebookRead, TodoWrite, Task, WebSearch, WebFetch, WebAgent, NotebookEdit) with "tool_choice": "auto".
Forwarded to azure-anthropic: Bash, WebSearch and WebFetch, with the STANDARD_TOOLS schemas.
Observed on 0b1cd6e with the setup from the original report. Code references are to 24f5c60.