Skip to content

Commit 0bf3447

Browse files
committed
Reproduce mid-handshake tool_search miss while a connector starts
1 parent a76f1c6 commit 0bf3447

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎src/agent/tool-search.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,36 @@ describe("createToolSearchTool", () => {
287287
"No tools matched",
288288
);
289289
});
290+
291+
test("mid-handshake search waits for a connecting server instead of reporting no match", async () => {
292+
const live: ToolDefinition[] = [];
293+
let resolveConnect!: () => void;
294+
const connected = new Promise<void>((resolve) => {
295+
resolveConnect = resolve;
296+
});
297+
const tool = createToolSearchTool({
298+
search: (query) => createToolIndex(() => live).search(query),
299+
lookup: (name) => live.find((def) => def.name === name),
300+
promote: () => undefined,
301+
awaitPendingConnections: async (timeoutMs = 50) => {
302+
await Promise.race([
303+
connected,
304+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
305+
]);
306+
return live.length === 0 ? 1 : 0;
307+
},
308+
});
309+
const pending = call(tool, { query: "linear tracker" });
310+
live.push({
311+
name: "mcp__linear__create_issue",
312+
description: "Create an issue in the tracker",
313+
inputSchema: { type: "object", properties: {}, required: [] },
314+
});
315+
resolveConnect();
316+
const out = await pending;
317+
expect(out).toContain("mcp__linear__create_issue");
318+
expect(out).not.toContain("No tools matched");
319+
});
290320
});
291321

292322
describe("advertisedTools", () => {

0 commit comments

Comments
 (0)