Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("getMcpServerTools", () => {

// Should only have one tool (from project server)
expect(result).toHaveLength(1)
expect(getFunction(result[0]).name).toBe("mcp--context7--resolve___library___id")
expect(getFunction(result[0]).name).toBe("mcp--context7--resolve-library-id")
// Project server takes priority
expect(getFunction(result[0]).description).toBe("Project description")
})
Expand Down
18 changes: 16 additions & 2 deletions src/services/mcp/McpHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { fileExistsAtPath } from "../../utils/fs"
import { arePathsEqual, getWorkspacePath } from "../../utils/path"
import { injectVariables } from "../../utils/config"
import { safeWriteJson } from "../../utils/safeWriteJson"
import { sanitizeMcpName } from "../../utils/mcp-name"
import { sanitizeMcpName, toolNamesMatch } from "../../utils/mcp-name"

// Discriminated union for connection states
export type ConnectedMcpConnection = {
Expand Down Expand Up @@ -940,16 +940,30 @@ export class McpHub {
* Find a connection by sanitized server name.
* This is used when parsing MCP tool responses where the server name has been
* sanitized (e.g., hyphens replaced with underscores) for API compliance.
* Uses fuzzy matching to handle cases where models convert hyphens to underscores.
* @param sanitizedServerName The sanitized server name from the API tool call
* @returns The original server name if found, or null if no match
*/
public findServerNameBySanitizedName(sanitizedServerName: string): string | null {
// First, check for an exact match
const exactMatch = this.connections.find((conn) => conn.server.name === sanitizedServerName)
if (exactMatch) {
return exactMatch.server.name
}

return this.sanitizedNameRegistry.get(sanitizedServerName) ?? null
// Check the registry for sanitized name mapping
const registryMatch = this.sanitizedNameRegistry.get(sanitizedServerName)
if (registryMatch) {
return registryMatch
}

// Use fuzzy matching: treat hyphens and underscores as equivalent
const fuzzyMatch = this.connections.find((conn) => toolNamesMatch(conn.server.name, sanitizedServerName))
if (fuzzyMatch) {
return fuzzyMatch.server.name
}

return null
Comment thread
daniel-lxs marked this conversation as resolved.
}

private async fetchToolsList(serverName: string, source?: "global" | "project"): Promise<McpTool[]> {
Expand Down
Loading
Loading