Skip to content

Commit ed1de83

Browse files
committed
feat: namespace MCP tools with server name prefix
Tools are now namespaced as `servername_toolname` (e.g., `memory_create_entities`) to prevent collisions when multiple servers expose tools with the same name.
1 parent 015894f commit ed1de83

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/node/services/mcpServerManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ export class MCPServerManager {
295295
private collectTools(instances: Map<string, MCPServerInstance>): Record<string, Tool> {
296296
const aggregated: Record<string, Tool> = {};
297297
for (const instance of instances.values()) {
298-
Object.assign(aggregated, instance.tools);
298+
for (const [toolName, tool] of Object.entries(instance.tools)) {
299+
// Namespace tools with server name to prevent collisions
300+
const namespacedName = `${instance.name}_${toolName}`;
301+
aggregated[namespacedName] = tool;
302+
}
299303
}
300304
return aggregated;
301305
}

tests/ipc/mcpConfig.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ describeIntegration("MCP server integration with model", () => {
136136
toolCallEnds.map((e) => ({ toolName: e.toolName, resultType: typeof e.result }))
137137
);
138138

139-
// Find the screenshot tool result
140-
const screenshotResult = toolCallEnds.find((e) => e.toolName === "take_screenshot");
139+
// Find the screenshot tool result (namespaced as chrome_take_screenshot)
140+
const screenshotResult = toolCallEnds.find((e) => e.toolName === "chrome_take_screenshot");
141141
expect(screenshotResult).toBeDefined();
142142

143143
// Verify the result has correct AI SDK format with mediaType
@@ -275,8 +275,8 @@ describeIntegration("MCP server integration with model", () => {
275275
// Should have at least one tool call
276276
expect(toolCallStarts.length).toBeGreaterThan(0);
277277

278-
// Should have called the MCP memory tool (create_entities)
279-
const mcpToolCall = toolCallStarts.find((e) => e.toolName === "create_entities");
278+
// Should have called the MCP memory tool (namespaced as memory_create_entities)
279+
const mcpToolCall = toolCallStarts.find((e) => e.toolName === "memory_create_entities");
280280
expect(mcpToolCall).toBeDefined();
281281

282282
// Verify response mentions the entity was created

0 commit comments

Comments
 (0)