Skip to content

Commit 80dbf88

Browse files
committed
fix(server): preserve native OpenCode tools with MCP prefix collisions
1 parent 4b0ba73 commit 80dbf88

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.test.ts‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ describe("OpenCodeAdapterV2", () => {
908908
"my.server_with_underscores": { status: "connected" },
909909
ambiguous: { status: "connected" },
910910
ambiguous_server: { status: "connected" },
911+
code: { status: "connected" },
912+
apply: { status: "connected" },
911913
},
912914
};
913915
},
@@ -972,17 +974,50 @@ describe("OpenCodeAdapterV2", () => {
972974
},
973975
}),
974976
);
977+
for (const tool of ["code_search", "apply_patch"]) {
978+
yield* Effect.promise(() =>
979+
nativeEvents.push({
980+
type: "message.part.updated",
981+
properties: {
982+
sessionID: nativeSessionId,
983+
part: {
984+
id: `native-${tool}`,
985+
sessionID: nativeSessionId,
986+
messageID: "mcp-assistant",
987+
type: "tool",
988+
callID: `native-${tool}`,
989+
tool,
990+
state: {
991+
status: "completed",
992+
input: { query: "needle", filePath: "local.ts" },
993+
title: `Native ${tool}`,
994+
metadata: {},
995+
output: "done",
996+
time: { start: 1, end: 2 },
997+
},
998+
},
999+
},
1000+
}),
1001+
);
1002+
}
9751003
yield* Effect.promise(() =>
9761004
nativeEvents.push({
9771005
type: "session.compacted",
9781006
properties: { sessionID: nativeSessionId },
9791007
}),
9801008
);
981-
const items = (yield* Fiber.join(received)).flatMap((event) =>
982-
event.type === "turn_item.updated" && event.turnItem.type === "dynamic_tool"
983-
? [event.turnItem]
984-
: [],
1009+
const allItems = (yield* Fiber.join(received)).flatMap((event) =>
1010+
event.type === "turn_item.updated" ? [event.turnItem] : [],
1011+
);
1012+
assert.equal(
1013+
allItems.find((item) => item.title === "Native code_search")?.type,
1014+
"web_search",
1015+
);
1016+
assert.equal(
1017+
allItems.find((item) => item.title === "Native apply_patch")?.type,
1018+
"file_change",
9851019
);
1020+
const items = allItems.filter((item) => item.type === "dynamic_tool");
9861021
assert.deepEqual(
9871022
items.slice(0, 3).map((item) => item.status),
9881023
["running", "completed", "failed"],

‎apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,11 @@ export function makeOpenCodeAdapterV2(
16051605
Effect.catch(() => Effect.succeed([])),
16061606
);
16071607
}
1608-
const matchingServers = turn.mcpServerNames?.filter((name) =>
1609-
part.tool.startsWith(`${name.replace(/[^a-zA-Z0-9_-]/g, "_")}_`),
1608+
const matchingServers = turn.mcpServerNames?.filter(
1609+
(name) =>
1610+
part.tool !== "code_search" &&
1611+
part.tool !== "apply_patch" &&
1612+
part.tool.startsWith(`${name.replace(/[^a-zA-Z0-9_-]/g, "_")}_`),
16101613
);
16111614
const serverName = matchingServers?.length === 1 ? matchingServers[0] : undefined;
16121615
const presentation =

0 commit comments

Comments
 (0)