Skip to content

Commit 845fe16

Browse files
committed
fix(cursor): name redirect tools with the request catalog
1 parent 09631ae commit 845fe16

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎src/adapters/cursor/tool-wording.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function cursorPlainNativeExecRedirectHint(
1818
): string | undefined {
1919
const clientTools = tools ?? [];
2020
const names = [...new Set([
21-
...clientTools.map(cursorToolWireName),
21+
...clientTools.map(tool => cursorToolWireName(tool, clientTools)),
2222
...mcpToolDefs.map(def => `mcp_${def.providerIdentifier}_${def.name}`),
2323
])];
2424
if (names.length === 0) return CURSOR_NO_CLIENT_TOOLS;

‎structure/providers/cursor.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ Cursor-private tool collisions. Other non-proxy-owned bare tools always receive
8080
proxy-owned execution/edit tools and namespaced MCP tools retain their existing identities.
8181
Registration, guidance, denied-native-exec redirects, live call mapping, and protobuf history
8282
replay use this catalog-dependent rule. Return mapping restores the client's semantic tool name.
83+
Claude factual redirects resolve each tool against the complete visible request catalog, regardless
84+
of declaration order, so their listed names match registration with or without a bare shell bridge.
85+
`tests/providers/cursor/cursor-tool-wording.test.ts` checks both bridge orders and no-bridge catalogs
86+
through redirect guidance and live transport request preparation.
8387
Request construction resolves accepted bare wire aliases in forced and allowed-tool choices to
8488
semantic names against the original catalog, retaining only the originally selected identities
8589
before prompt and budget filtering so a removed bridge cannot invalidate registration or widen

‎tests/providers/cursor/cursor-tool-wording.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { nativeShellDisabledMessage } from "../../../src/adapters/cursor/native-
1212
import { encodeCursorRunRequest } from "../../../src/adapters/cursor/protobuf-request";
1313
import { createCursorRequest } from "../../../src/adapters/cursor/request-builder";
1414
import { buildCursorToolGuidanceSystemNote } from "../../../src/adapters/cursor/tool-guidance";
15+
import { buildCursorToolDefinitions } from "../../../src/adapters/cursor/tool-definitions";
1516
import { CURSOR_TOOL_CALL_CONTINUATION, cursorUsesPlainToolWording } from "../../../src/adapters/cursor/tool-wording";
1617
import { parseRequest } from "../../../src/responses/parser";
1718
import type { CursorRunRequest, CursorServerMessage } from "../../../src/adapters/cursor/types";
@@ -22,6 +23,11 @@ import { createTestTranslatorBudget } from "../../helpers/translator-budget";
2223
const CONCEALMENT = /do not (narrate|comment|mention|re-announce)|commentary is forbidden|must not appear in your output/i;
2324
const CLAUDE_MODELS = ["claude-sonnet-5-5", "cursor/claude-4.6-opus-high", "claude-opus-5-thinking-high-fast", "claude-4.5-haiku", "claude-fable-5", "claude-4-sonnet-1m"];
2425
const OTHER_MODELS = [undefined, "cursor-grok-4.6-high", "cursor/gpt-5", "gemini-3-pro", "composer-2.5", "cursor/auto", "default", "not-claude-sonnet"];
26+
const CLAUDE_CLIENT_CATALOGS = [
27+
{ names: ["Bash", "Read"], wireNames: ["Bash", "Read"] },
28+
{ names: ["Read", "exec_command"], wireNames: ["ocx_client_Read", "exec_command"] },
29+
{ names: ["exec_command", "Read"], wireNames: ["exec_command", "ocx_client_Read"] },
30+
];
2531

2632
function execMessage(message: Parameters<typeof create<typeof ExecServerMessageSchema>>[1]["message"]) {
2733
return create(ExecServerMessageSchema, { id: 1, execId: "wording-test", message });
@@ -55,6 +61,37 @@ const frames = {
5561
afterEach(() => resetCursorBlobStateForTests());
5662

5763
describe("Cursor target-specific tool wording", () => {
64+
test.each(CLAUDE_CLIENT_CATALOGS)("Claude redirect matches the request catalog: %j", ({ names, wireNames }) => {
65+
const tools = names.map(name => ({ name, description: "Fixture tool", parameters: {} }));
66+
const definitions = buildCursorToolDefinitions(tools);
67+
expect(definitions.map(tool => tool.name)).toEqual(wireNames);
68+
const hint = cursorNativeExecRedirectHint(tools, [], "claude-sonnet-5-5")!;
69+
expect(hint.match(/Available tools in this request's catalog: (.*?)\. /)?.[1])
70+
.toBe(wireNames.map(name => `\`${name}\``).join(", "));
71+
const guidance = buildCursorToolGuidanceSystemNote(tools, undefined, "claude-sonnet-5-5")!;
72+
for (const name of wireNames) expect(guidance).toContain(`\`${name}\``);
73+
});
74+
test.each(CLAUDE_CLIENT_CATALOGS)("Claude live transport prepares the request catalog: %j", async ({ names, wireNames }) => {
75+
const transport = createLiveCursorTransport({ provider: { adapter: "cursor", baseUrl: "https://api2.cursor.sh", apiKey: "fixture-token" },
76+
translatorBudget: createTestTranslatorBudget(), headers: new Headers() });
77+
const internal = transport as unknown as { open(bytes: Uint8Array): void; execContext: CursorNativeExecContext };
78+
let preparedBytes: Uint8Array | undefined;
79+
internal.open = bytes => { preparedBytes = bytes; throw new Error("catalog fixture stops before network"); };
80+
try {
81+
const request: CursorRunRequest = { modelId: "claude-sonnet-5-5", conversationId: "catalog-fixture", system: [],
82+
messages: [{ role: "user", content: "Inspect the project." }],
83+
tools: names.map(name => ({ name, description: "Fixture tool", parameters: {} })) };
84+
await expect(transport.run(request)[Symbol.asyncIterator]().next()).rejects.toThrow("catalog fixture stops before network");
85+
expect(preparedBytes).toBeDefined();
86+
const decoded = fromBinary(AgentClientMessageSchema, preparedBytes!);
87+
if (decoded.message.case !== "runRequest") throw new Error("Expected runRequest");
88+
expect(decoded.message.value.mcpTools?.mcpTools.map(tool => tool.name)).toEqual(wireNames);
89+
expect(internal.execContext.clientToolDefs?.map(tool => tool.name)).toEqual(wireNames);
90+
expect(internal.execContext.nativeExecRedirectHint?.match(/Available tools in this request's catalog: (.*?)\. /)?.[1])
91+
.toBe(wireNames.map(name => `\`${name}\``).join(", "));
92+
expect(internal.execContext.plainToolWording).toBe(true);
93+
} finally { await transport.close?.(); }
94+
});
5895
test.each(CLAUDE_MODELS)("recognizes Claude target %s", modelId => {
5996
expect(cursorUsesPlainToolWording(modelId)).toBe(true);
6097
});

0 commit comments

Comments
 (0)