Merge pull request #5991 from continuedev/dallin/tool_names
Include mcp server names in tool names
This commit is contained in:
commit
0545e17d27
5 changed files with 75 additions and 6 deletions
|
|
@ -27,6 +27,7 @@ import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
|
|||
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
|
||||
import { getConfigDependentToolDefinitions } from "../../tools";
|
||||
import { encodeMCPToolUri } from "../../tools/callTool";
|
||||
import { getMCPToolName } from "../../tools/mcpToolName";
|
||||
import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths";
|
||||
import { localPathOrUriToPath } from "../../util/pathToUri";
|
||||
import { Telemetry } from "../../util/posthog";
|
||||
|
|
@ -156,7 +157,7 @@ export default async function doLoadConfig(options: {
|
|||
displayTitle: server.name + " " + tool.name,
|
||||
function: {
|
||||
description: tool.description,
|
||||
name: tool.name,
|
||||
name: getMCPToolName(server, tool),
|
||||
parameters: tool.inputSchema,
|
||||
},
|
||||
faviconUrl: server.faviconUrl,
|
||||
|
|
@ -164,6 +165,7 @@ export default async function doLoadConfig(options: {
|
|||
type: "function" as const,
|
||||
uri: encodeMCPToolUri(server.id, tool.name),
|
||||
group: server.name,
|
||||
originalFunctionName: tool.name,
|
||||
}));
|
||||
newConfig.tools.push(...serverTools);
|
||||
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -992,6 +992,7 @@ export interface Tool {
|
|||
uri?: string;
|
||||
faviconUrl?: string;
|
||||
group: string;
|
||||
originalFunctionName?: string;
|
||||
}
|
||||
|
||||
interface ToolChoice {
|
||||
|
|
|
|||
9
core/tools/mcpToolName.ts
Normal file
9
core/tools/mcpToolName.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { MCPServerStatus, MCPTool } from "..";
|
||||
|
||||
export function getMCPToolName(server: MCPServerStatus, tool: MCPTool) {
|
||||
const serverPrefix = server.name.split(" ").join("_").toLowerCase();
|
||||
if (tool.name.startsWith(serverPrefix)) {
|
||||
return tool.name;
|
||||
}
|
||||
return `${serverPrefix}_${tool.name}`;
|
||||
}
|
||||
57
core/tools/mcpToolName.vitest.ts
Normal file
57
core/tools/mcpToolName.vitest.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { expect, test } from "vitest";
|
||||
import { MCPServerStatus, MCPTool } from "..";
|
||||
import { getMCPToolName } from "./mcpToolName";
|
||||
|
||||
const createMcpServer = (name: string): MCPServerStatus => ({
|
||||
name,
|
||||
errors: [],
|
||||
prompts: [],
|
||||
tools: [],
|
||||
resources: [],
|
||||
resourceTemplates: [],
|
||||
status: "connected",
|
||||
id: "",
|
||||
transport: {
|
||||
type: "sse",
|
||||
url: "",
|
||||
},
|
||||
});
|
||||
|
||||
const createMCPTool = (name: string): MCPTool => ({
|
||||
name,
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
},
|
||||
});
|
||||
|
||||
test("getMCPToolName - adds server prefix to tool name when not present", () => {
|
||||
const server = createMcpServer("Github");
|
||||
const tool = createMCPTool("create_pull_request");
|
||||
|
||||
const result = getMCPToolName(server, tool);
|
||||
expect(result).toBe("github_create_pull_request");
|
||||
});
|
||||
|
||||
test("getMCPToolName - preserves tool name when it already starts with server prefix", () => {
|
||||
const server = createMcpServer("Github");
|
||||
const tool = createMCPTool("github_create_pull_request");
|
||||
|
||||
const result = getMCPToolName(server, tool);
|
||||
expect(result).toBe("github_create_pull_request");
|
||||
});
|
||||
|
||||
test("getMCPToolName - handles server names with spaces", () => {
|
||||
const server = createMcpServer("Azure DevOps");
|
||||
const tool = createMCPTool("create_pipeline");
|
||||
|
||||
const result = getMCPToolName(server, tool);
|
||||
expect(result).toBe("azure_devops_create_pipeline");
|
||||
});
|
||||
|
||||
test("getMCPToolName - handles mixed case in server names", () => {
|
||||
const server = createMcpServer("GitLab");
|
||||
const tool = createMCPTool("create_merge_request");
|
||||
|
||||
const result = getMCPToolName(server, tool);
|
||||
expect(result).toBe("gitlab_create_merge_request");
|
||||
});
|
||||
|
|
@ -102,7 +102,7 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
|
|||
/>
|
||||
)}
|
||||
<span className="line-clamp-1 break-all">
|
||||
{props.tool.function.name}
|
||||
{props.tool.originalFunctionName ?? props.tool.function.name}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -124,16 +124,16 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
|
|||
</>
|
||||
) : policy === "allowedWithoutPermission" ? (
|
||||
<>
|
||||
<span className="text-green-500 sm:hidden">Auto</span>
|
||||
<span className="hidden text-green-500 sm:inline-block">
|
||||
<span className="text-success sm:hidden">Auto</span>
|
||||
<span className="text-success hidden sm:inline-block">
|
||||
Automatic
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
// allowedWithPermission
|
||||
<>
|
||||
<span className="text-yellow-500 sm:hidden">Ask</span>
|
||||
<span className="hidden text-yellow-500 sm:inline-block">
|
||||
<span className="text-warning sm:hidden">Ask</span>
|
||||
<span className="text-warning hidden sm:inline-block">
|
||||
Ask First
|
||||
</span>
|
||||
</>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue