( toolName: string, )
| 411 | * @returns ConfigScope or null if not an MCP tool or server not found |
| 412 | */ |
| 413 | export function getMcpServerScopeFromToolName( |
| 414 | toolName: string, |
| 415 | ): ConfigScope | null { |
| 416 | if (!isMcpTool({ name: toolName } as Tool)) { |
| 417 | return null |
| 418 | } |
| 419 | |
| 420 | // Extract server name from tool name (format: mcp__serverName__toolName) |
| 421 | const mcpInfo = mcpInfoFromString(toolName) |
| 422 | if (!mcpInfo) { |
| 423 | return null |
| 424 | } |
| 425 | |
| 426 | // Look up server config |
| 427 | const serverConfig = getMcpConfigByName(mcpInfo.serverName) |
| 428 | |
| 429 | // Fallback: managed connector servers still normalize to the legacy |
| 430 | // "claude_ai_" prefix so MCP tool names stay stable during migration, but |
| 431 | // they aren't in getMcpConfigByName (they're fetched async separately). |
| 432 | if (!serverConfig && mcpInfo.serverName.startsWith('claude_ai_')) { |
| 433 | return 'claudeai' |
| 434 | } |
| 435 | |
| 436 | return serverConfig?.scope ?? null |
| 437 | } |
| 438 | |
| 439 | // Type guards for MCP server config types |
| 440 | function isStdioConfig( |
no test coverage detected