fix: strip mcp_ prefix from tool names before dispatch

The model emits tool names like mcp_background_output but the runtime
registry has them as background_output. While transformToolName already
handles the prefix for display purposes, the tool dispatch path in
tool-execute-before was not stripping it, causing 'unavailable tool' errors.

This adds mcp_ prefix stripping at the earliest point in the tool
execution pipeline, fixing background_output, background_cancel, and
all nocturne-memory_* tools.

Closes #2697
This commit is contained in:
YeonGyu-Kim
2026-04-02 19:22:33 +09:00
parent 6c0252fae4
commit a562d5367f
2 changed files with 115 additions and 0 deletions
+13
View File
@@ -52,6 +52,19 @@ export function createToolExecuteBeforeHandler(args: {
}
return async (input, output): Promise<void> => {
// Strip mcp_ prefix from tool names — the model may emit mcp_background_output
// but the runtime registry has it as background_output (fixes #2697)
if (/^mcp_/i.test(input.tool)) {
const stripped = input.tool.replace(/^mcp_/i, "")
log("[tool-execute-before] Stripped mcp_ prefix from tool name", {
original: input.tool,
resolved: stripped,
sessionID: input.sessionID,
callID: input.callID,
})
input.tool = stripped
}
if (input.tool.toLowerCase() === "bash" && typeof output.args.command === "string") {
if (output.args.command.includes("\x00")) {
replaceToolArgs(output, { command: output.args.command.replace(/\x00/g, "") })