( 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: claude.ai servers have normalized names starting with "claude_ai_" |
| 430 | // but aren't in getMcpConfigByName (they're fetched async separately) |
| 431 | if (!serverConfig && mcpInfo.serverName.startsWith('claude_ai_')) { |
| 432 | return 'claudeai' |
| 433 | } |
| 434 | |
| 435 | return serverConfig?.scope ?? null |
| 436 | } |
| 437 | |
| 438 | // Type guards for MCP server config types |
| 439 | function isStdioConfig( |
no test coverage detected