fix mcp tool names that are long or have invalid characters (based on 400 error) (#602)
This commit is contained in:
parent
2db5d83023
commit
fe049c286f
|
@ -116,12 +116,25 @@ async function connectAndDiscover(
|
||||||
};
|
};
|
||||||
removeSchemaProps(tool.inputSchema);
|
removeSchemaProps(tool.inputSchema);
|
||||||
|
|
||||||
|
// if there are multiple MCP servers, prefix tool name with mcpServerName to avoid collisions
|
||||||
|
let toolNameForModel = tool.name;
|
||||||
|
if (Object.keys(mcpServers).length > 1) {
|
||||||
|
toolNameForModel = mcpServerName + '__' + toolNameForModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace invalid characters (based on 400 error message) with underscores
|
||||||
|
toolNameForModel = toolNameForModel.replace(/[^a-zA-Z0-9_.-]/g, '_');
|
||||||
|
|
||||||
|
// if longer than 63 characters, replace middle with '___'
|
||||||
|
// note 400 error message says max length is 64, but actual limit seems to be 63
|
||||||
|
if (toolNameForModel.length > 63) {
|
||||||
|
toolNameForModel =
|
||||||
|
toolNameForModel.slice(0, 28) + '___' + toolNameForModel.slice(-32);
|
||||||
|
}
|
||||||
toolRegistry.registerTool(
|
toolRegistry.registerTool(
|
||||||
new DiscoveredMCPTool(
|
new DiscoveredMCPTool(
|
||||||
mcpClient,
|
mcpClient,
|
||||||
Object.keys(mcpServers).length > 1
|
toolNameForModel,
|
||||||
? mcpServerName + '__' + tool.name
|
|
||||||
: tool.name,
|
|
||||||
tool.description ?? '',
|
tool.description ?? '',
|
||||||
tool.inputSchema,
|
tool.inputSchema,
|
||||||
tool.name,
|
tool.name,
|
||||||
|
|
Loading…
Reference in New Issue