Fix MCP tool naming for OpenRouter API compatibility
- Change tool name separator from dot to double underscore (server__tool)
- Update tool discovery to use server__tool_name format
- Update tool execution routing to parse double underscore separator
- Fix OpenRouter API error: tool names must match pattern '^[a-zA-Z0-9_-]{1,64}'
This resolves the silent failure when MCP tools were present in conversations.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e689acee53
commit
0a06544bda
2 changed files with 9 additions and 8 deletions
|
|
@ -225,10 +225,10 @@ export function useAgentLoop(config: Partial<AgentLoopConfig> = {}): UseAgentLoo
|
|||
return { result };
|
||||
}
|
||||
|
||||
// Check if it's an MCP tool (prefixed with server name)
|
||||
if (toolCall.function.name.includes('.')) {
|
||||
// Extract server name from tool name (format: "server.tool_name")
|
||||
const [serverName] = toolCall.function.name.split('.');
|
||||
// Check if it's an MCP tool (prefixed with server name using double underscore)
|
||||
if (toolCall.function.name.includes('__')) {
|
||||
// Extract server name from tool name (format: "server__tool_name")
|
||||
const [serverName] = toolCall.function.name.split('__');
|
||||
|
||||
// Find the connection ID for this server name
|
||||
const connection = connections.find(conn => conn.name === serverName);
|
||||
|
|
|
|||
|
|
@ -581,10 +581,11 @@ export class MCPConnectionManager implements MCPConnectionManager {
|
|||
const result = await this.client.listTools();
|
||||
|
||||
// Transform MCP tools to our Tool interface with name prefixing
|
||||
// Use double underscore instead of dot to comply with OpenRouter API requirements
|
||||
return result.tools.map(tool => ({
|
||||
type: 'function' as const,
|
||||
function: {
|
||||
name: `${this.connection.name}.${tool.name}`,
|
||||
name: `${this.connection.name}__${tool.name}`,
|
||||
description: `[${this.connection.name}] ${tool.description || ''}`,
|
||||
parameters: tool.inputSchema || {},
|
||||
},
|
||||
|
|
@ -636,9 +637,9 @@ export class MCPConnectionManager implements MCPConnectionManager {
|
|||
throw new Error('Client not connected');
|
||||
}
|
||||
|
||||
// Remove the server prefix from the tool name
|
||||
const unprefixedName = toolName.startsWith(`${this.connection.name}.`)
|
||||
? toolName.slice(this.connection.name.length + 1)
|
||||
// Remove the server prefix from the tool name (using double underscore separator)
|
||||
const unprefixedName = toolName.startsWith(`${this.connection.name}__`)
|
||||
? toolName.slice(this.connection.name.length + 2)
|
||||
: toolName;
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue