normalization.ts
services/mcp/normalization.ts
24
Lines
879
Bytes
1
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with integrations, mcp. It contains 24 lines, 0 detected imports, and 1 detected exports.
Important relationships
Detected exports
normalizeNameForMCP
Keywords
nameclaudenamesnormalizedunderscoresreplaceserverclaudeai_server_prefixa-za-z0-9_-pure
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Pure utility functions for MCP name normalization.
* This file has no dependencies to avoid circular imports.
*/
// Claude.ai server names are prefixed with this string
const CLAUDEAI_SERVER_PREFIX = 'claude.ai '
/**
* Normalize server names to be compatible with the API pattern ^[a-zA-Z0-9_-]{1,64}$
* Replaces any invalid characters (including dots and spaces) with underscores.
*
* For claude.ai servers (names starting with "claude.ai "), also collapses
* consecutive underscores and strips leading/trailing underscores to prevent
* interference with the __ delimiter used in MCP tool names.
*/
export function normalizeNameForMCP(name: string): string {
let normalized = name.replace(/[^a-zA-Z0-9_-]/g, '_')
if (name.startsWith(CLAUDEAI_SERVER_PREFIX)) {
normalized = normalized.replace(/_+/g, '_').replace(/^_|_$/g, '')
}
return normalized
}