diff options
Diffstat (limited to 'packages/core/src/tools/mcp-tool.ts')
| -rw-r--r-- | packages/core/src/tools/mcp-tool.ts | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/packages/core/src/tools/mcp-tool.ts b/packages/core/src/tools/mcp-tool.ts index aadc484a..9916d7f9 100644 --- a/packages/core/src/tools/mcp-tool.ts +++ b/packages/core/src/tools/mcp-tool.ts @@ -28,15 +28,15 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> { constructor( private readonly mcpTool: CallableTool, readonly serverName: string, - readonly name: string, - readonly description: string, - readonly parameterSchemaJson: unknown, readonly serverToolName: string, + description: string, + readonly parameterSchemaJson: unknown, readonly timeout?: number, readonly trust?: boolean, + nameOverride?: string, ) { super( - name, + nameOverride ?? generateValidName(serverToolName), `${serverToolName} (${serverName} MCP Server)`, description, Icon.Hammer, @@ -46,6 +46,19 @@ export class DiscoveredMCPTool extends BaseTool<ToolParams, ToolResult> { ); } + asFullyQualifiedTool(): DiscoveredMCPTool { + return new DiscoveredMCPTool( + this.mcpTool, + this.serverName, + this.serverToolName, + this.description, + this.parameterSchemaJson, + this.timeout, + this.trust, + `${this.serverName}__${this.serverToolName}`, + ); + } + /** * Overrides the base schema to use parametersJsonSchema when building * FunctionDeclaration @@ -166,3 +179,17 @@ function getStringifiedResultForDisplay(result: Part[]) { return '```json\n' + JSON.stringify(processedResults, null, 2) + '\n```'; } + +/** Visible for testing */ +export function generateValidName(name: string) { + // Replace invalid characters (based on 400 error message from Gemini API) with underscores + let validToolname = name.replace(/[^a-zA-Z0-9_.-]/g, '_'); + + // If longer than 63 characters, replace middle with '___' + // (Gemini API says max length 64, but actual limit seems to be 63) + if (validToolname.length > 63) { + validToolname = + validToolname.slice(0, 28) + '___' + validToolname.slice(-32); + } + return validToolname; +} |
