522
*/
523
export function parseMcpChannelUri(uri: string): IMcpChannelRoute | undefined {
525
>
if (!uri.startsWith(prefix)) {
526
return undefined;
527
}
529
>
const slash = rest.indexOf('/');
530
>
if (slash <= 0) {
531
return undefined;
532
}
534
>
const tail = rest.slice(slash + 1);
535
>
const sep = tail.indexOf('/');
536
>
if (sep <= 0 || sep === tail.length - 1) {
537
return undefined;
538
}
540
>
let serverName: string;
541
>
try {
542
>
// `decodeURIComponent` throws `URIError` on malformed percent
543
>
// escapes (e.g. a lone `%`). Treat any decode failure as a
544
>
// malformed channel rather than letting it escape — the caller
545
>
// translates `undefined` into a clean `Method not found`.
546
>
sessionId = decodeURIComponent(tail.slice(0, sep));
547
>
serverName = decodeURIComponent(tail.slice(sep + 1));
548
>
} catch {
549
return undefined;
550
}
552
return undefined;
553
}