From 2acebf13532a3e9499495127ea7b8bcdaa060e3b Mon Sep 17 00:00:00 2001 From: LiuVaayne <10231735+vaayne@users.noreply.github.com> Date: Mon, 19 May 2025 11:20:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20improve=20sanitization=20and=20form?= =?UTF-8?q?atting=20in=20buildFunctionCallToo=E2=80=A6=20(#6152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: improve sanitization and formatting in buildFunctionCallToolName function --- src/main/utils/mcp.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/utils/mcp.ts b/src/main/utils/mcp.ts index ded81d71fe..23d19806d9 100644 --- a/src/main/utils/mcp.ts +++ b/src/main/utils/mcp.ts @@ -1,8 +1,11 @@ export function buildFunctionCallToolName(serverName: string, toolName: string) { + const sanitizedServer = serverName.trim().replace(/-/g, '_') + const sanitizedTool = toolName.trim().replace(/-/g, '_') + // Combine server name and tool name - let name = toolName - if (!toolName.includes(serverName.slice(0, 7))) { - name = `${serverName.slice(0, 7) || ''}_${toolName || ''}` + let name = sanitizedTool + if (!sanitizedTool.includes(sanitizedServer.slice(0, 7))) { + name = `${sanitizedServer.slice(0, 7) || ''}-${sanitizedTool || ''}` } // Replace invalid characters with underscores or dashes @@ -11,7 +14,7 @@ export function buildFunctionCallToolName(serverName: string, toolName: string) // Ensure name starts with a letter or underscore (for valid JavaScript identifier) if (!/^[a-zA-Z]/.test(name)) { - name = `tool_${name}` + name = `tool-${name}` } // Remove consecutive underscores/dashes (optional improvement)