source dump of claude code
at main 23 lines 879 B view raw
1/** 2 * Pure utility functions for MCP name normalization. 3 * This file has no dependencies to avoid circular imports. 4 */ 5 6// Claude.ai server names are prefixed with this string 7const CLAUDEAI_SERVER_PREFIX = 'claude.ai ' 8 9/** 10 * Normalize server names to be compatible with the API pattern ^[a-zA-Z0-9_-]{1,64}$ 11 * Replaces any invalid characters (including dots and spaces) with underscores. 12 * 13 * For claude.ai servers (names starting with "claude.ai "), also collapses 14 * consecutive underscores and strips leading/trailing underscores to prevent 15 * interference with the __ delimiter used in MCP tool names. 16 */ 17export function normalizeNameForMCP(name: string): string { 18 let normalized = name.replace(/[^a-zA-Z0-9_-]/g, '_') 19 if (name.startsWith(CLAUDEAI_SERVER_PREFIX)) { 20 normalized = normalized.replace(/_+/g, '_').replace(/^_|_$/g, '') 21 } 22 return normalized 23}