From 4d8ecbb6bedfe6bc2fccf1b3e612b8973edebc63 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Fri, 10 Apr 2026 23:08:07 +0300 Subject: [PATCH] fix(litellm): sanitize customer ID in MCP server alias LiteLLM rejects server names containing `-`, but customer IDs are UUIDs. Replace `-` with `_` in both the MCP server alias and key alias. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/auth/litellm.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/auth/litellm.ts b/src/auth/litellm.ts index 00568f3..6556b13 100644 --- a/src/auth/litellm.ts +++ b/src/auth/litellm.ts @@ -20,8 +20,13 @@ interface LiteLLMMCPServerResponse { * so we create one MCP server entry per customer with the customer-specific * demux URL. The virtual key is then scoped to only that server. */ +/** LiteLLM rejects server names containing `-`; replace with `_`. */ +function toServerAlias(customerId: string): string { + return `sitebridge_${customerId.replace(/-/g, "_")}`; +} + export async function provisionMcpServer(customerId: string): Promise { - const serverAlias = `sitebridge-${customerId}`; + const serverAlias = toServerAlias(customerId); const demuxUrl = `${config.agilitonAccountUrl}/mcp/demux/${customerId}/mcp`; const body = { @@ -63,7 +68,7 @@ export async function provisionLiteLLMKey(customerId: string, email: string): Pr // 2. Create virtual key scoped to that MCP server const body = { - key_alias: `sb-${customerId}`, + key_alias: `sb_${customerId.replace(/-/g, "_")}`, models: config.defaultModels, mcp_servers: [mcpServerAlias], max_budget: config.defaultBudgetUsd,