(pathname: string)
| 77 | * org-scoped path to the bare path the shared envelope actually routes. |
| 78 | */ |
| 79 | export const classifyMcpPath = (pathname: string): McpRoute => { |
| 80 | if (pathname === AUTHORIZATION_SERVER_METADATA_PATH) { |
| 81 | return { kind: "oauth-authorization-server", organizationId: null }; |
| 82 | } |
| 83 | const segments = pathname.split("/").filter((segment) => segment.length > 0); |
| 84 | |
| 85 | // Protected-resource metadata: `${prefix}/mcp` or `${prefix}/<org>/mcp`. The |
| 86 | // org sits after the well-known prefix (RFC 9728), not at the path root. |
| 87 | const prmPrefix = "/.well-known/oauth-protected-resource"; |
| 88 | if (pathname.startsWith(`${prmPrefix}/`)) { |
| 89 | const matched = matchMcpSuffix(segments.slice(2)); |
| 90 | return matched === undefined ? null : { kind: "oauth-protected-resource", ...matched }; |
| 91 | } |
| 92 | |
| 93 | // MCP transport: `/mcp` or `/<org>/mcp`. |
| 94 | const matched = matchMcpSuffix(segments); |
| 95 | return matched === undefined ? null : { kind: "mcp", ...matched }; |
| 96 | }; |
| 97 | |
| 98 | const bareMcpPath = (route: Exclude<McpRoute, null>): string => |
| 99 | route.kind === "mcp" |
no test coverage detected