11import { describe , expect , it } from "@effect/vitest" ;
22
3- import { protectedResourceMetadataUrlFor , resourceUrlFor , toolkitSlugFromRequest } from "./auth" ;
3+ import { mcpResourceFromRequest , protectedResourceMetadataUrlFor , resourceUrlFor } from "./auth" ;
44import { classifyMcpPath , prepareMcpOrgScope } from "./mount" ;
55
6- describe ( "cloud MCP toolkit route normalization" , ( ) => {
7- it ( "classifies toolkit MCP and protected-resource metadata paths" , ( ) => {
6+ describe ( "cloud MCP scoped route normalization" , ( ) => {
7+ it ( "classifies scoped MCP and protected-resource metadata paths" , ( ) => {
8+ expect ( classifyMcpPath ( "/mcp" ) ) . toEqual ( {
9+ kind : "mcp" ,
10+ organizationId : null ,
11+ resource : { kind : "default" } ,
12+ } ) ;
813 expect ( classifyMcpPath ( "/mcp/toolkits/deploy" ) ) . toEqual ( {
914 kind : "mcp" ,
1015 organizationId : null ,
11- toolkitSlug : " deploy",
16+ resource : { kind : "toolkit" , slug : " deploy" } ,
1217 } ) ;
1318 expect ( classifyMcpPath ( "/acme/mcp/toolkits/deploy" ) ) . toEqual ( {
1419 kind : "mcp" ,
1520 organizationId : "acme" ,
16- toolkitSlug : "deploy" ,
21+ resource : { kind : "toolkit" , slug : "deploy" } ,
22+ } ) ;
23+ expect ( classifyMcpPath ( "/acme/mcp/integrations/github,linear" ) ) . toEqual ( {
24+ kind : "mcp" ,
25+ organizationId : "acme" ,
26+ resource : { kind : "integrations" , slugs : [ "github" , "linear" ] } ,
27+ } ) ;
28+ expect ( classifyMcpPath ( "/mcp/tools/github.repos.list" ) ) . toEqual ( {
29+ kind : "mcp" ,
30+ organizationId : null ,
31+ resource : { kind : "tool" , toolId : "github.repos.list" } ,
1732 } ) ;
1833 expect ( classifyMcpPath ( "/.well-known/oauth-protected-resource/mcp/toolkits/deploy" ) ) . toEqual ( {
1934 kind : "oauth-protected-resource" ,
2035 organizationId : null ,
21- toolkitSlug : " deploy",
36+ resource : { kind : "toolkit" , slug : " deploy" } ,
2237 } ) ;
2338 expect (
2439 classifyMcpPath ( "/.well-known/oauth-protected-resource/acme/mcp/toolkits/deploy" ) ,
2540 ) . toEqual ( {
2641 kind : "oauth-protected-resource" ,
2742 organizationId : "acme" ,
28- toolkitSlug : " deploy",
43+ resource : { kind : "toolkit" , slug : " deploy" } ,
2944 } ) ;
45+ expect ( classifyMcpPath ( "/mcp/unknown/x" ) ) . toBeNull ( ) ;
46+ expect ( classifyMcpPath ( "/mcp/toolkits" ) ) . toBeNull ( ) ;
3047 } ) ;
3148
3249 it ( "rewrites org-scoped toolkit metadata to the mounted toolkit metadata route" , ( ) => {
@@ -41,17 +58,33 @@ describe("cloud MCP toolkit route normalization", () => {
4158 expect ( url . pathname ) . toBe ( "/.well-known/oauth-protected-resource/mcp/toolkits/deploy" ) ;
4259 expect ( url . search ) . toBe ( "?x=1" ) ;
4360 expect ( rewritten . headers . get ( "x-executor-mcp-organization" ) ) . toBe ( "acme" ) ;
44- expect ( toolkitSlugFromRequest ( rewritten ) ) . toBe ( " deploy") ;
61+ expect ( mcpResourceFromRequest ( rewritten ) ) . toEqual ( { kind : "toolkit" , slug : " deploy" } ) ;
4562 } ) ;
4663
47- it ( "builds toolkit-specific resource and metadata URLs" , ( ) => {
48- expect ( resourceUrlFor ( null , "deploy" ) ) . toBe ( "https://executor.sh/mcp/toolkits/deploy" ) ;
49- expect ( resourceUrlFor ( "acme" , "deploy" ) ) . toBe ( "https://executor.sh/acme/mcp/toolkits/deploy" ) ;
50- expect ( protectedResourceMetadataUrlFor ( null , "deploy" ) ) . toBe (
64+ it ( "rewrites an org-scoped integrations endpoint to the bare scoped path" , ( ) => {
65+ const rewritten = prepareMcpOrgScope (
66+ new Request ( "https://executor.sh/acme/mcp/integrations/github,linear" ) ,
67+ ) ;
68+ expect ( new URL ( rewritten . url ) . pathname ) . toBe ( "/mcp/integrations/github,linear" ) ;
69+ expect ( rewritten . headers . get ( "x-executor-mcp-organization" ) ) . toBe ( "acme" ) ;
70+ expect ( mcpResourceFromRequest ( rewritten ) ) . toEqual ( {
71+ kind : "integrations" ,
72+ slugs : [ "github" , "linear" ] ,
73+ } ) ;
74+ } ) ;
75+
76+ it ( "builds scoped resource and metadata URLs" , ( ) => {
77+ const toolkit = { kind : "toolkit" , slug : "deploy" } as const ;
78+ expect ( resourceUrlFor ( null , toolkit ) ) . toBe ( "https://executor.sh/mcp/toolkits/deploy" ) ;
79+ expect ( resourceUrlFor ( "acme" , toolkit ) ) . toBe ( "https://executor.sh/acme/mcp/toolkits/deploy" ) ;
80+ expect ( protectedResourceMetadataUrlFor ( null , toolkit ) ) . toBe (
5181 "https://executor.sh/.well-known/oauth-protected-resource/mcp/toolkits/deploy" ,
5282 ) ;
53- expect ( protectedResourceMetadataUrlFor ( "acme" , "deploy" ) ) . toBe (
83+ expect ( protectedResourceMetadataUrlFor ( "acme" , toolkit ) ) . toBe (
5484 "https://executor.sh/.well-known/oauth-protected-resource/acme/mcp/toolkits/deploy" ,
5585 ) ;
86+ expect ( resourceUrlFor ( "acme" , { kind : "tool" , toolId : "github.repos.list" } ) ) . toBe (
87+ "https://executor.sh/acme/mcp/tools/github.repos.list" ,
88+ ) ;
5689 } ) ;
5790} ) ;
0 commit comments