skybridge 0.0.0-dev.ffaef7a → 0.0.0-dev.ffdf126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/cli/build-helpers.d.ts +3 -2
- package/dist/cli/build-helpers.js +24 -10
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +48 -5
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.js +10 -5
- package/dist/cli/build-steps.js.map +1 -1
- package/dist/cli/build-steps.test.js +3 -3
- package/dist/cli/build-steps.test.js.map +1 -1
- package/dist/cli/detect-port.js +0 -1
- package/dist/cli/detect-port.js.map +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
- package/dist/cli/resolve-skybridge-config.js.map +1 -0
- package/dist/cli/use-nodemon.js +12 -4
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.js +1 -1
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/dev.js +3 -3
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/start.js +2 -2
- package/dist/commands/start.js.map +1 -1
- package/dist/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- package/dist/server/app.d.ts +194 -0
- package/dist/server/app.js +266 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/app.test.js +97 -0
- package/dist/server/app.test.js.map +1 -0
- package/dist/server/auth/discovery.d.ts +2 -1
- package/dist/server/auth/discovery.js +2 -2
- package/dist/server/auth/discovery.js.map +1 -1
- package/dist/server/auth/index.d.ts +35 -5
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +25 -3
- package/dist/server/auth/providers/auth0.js +13 -8
- package/dist/server/auth/providers/auth0.js.map +1 -1
- package/dist/server/auth/providers/auth0.test.js +5 -3
- package/dist/server/auth/providers/auth0.test.js.map +1 -1
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.js +143 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +40 -3
- package/dist/server/auth/providers/clerk.js +4 -1
- package/dist/server/auth/providers/clerk.js.map +1 -1
- package/dist/server/auth/providers/clerk.test.js +5 -3
- package/dist/server/auth/providers/clerk.test.js.map +1 -1
- package/dist/server/auth/providers/custom.d.ts +20 -4
- package/dist/server/auth/providers/custom.js +33 -11
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +71 -17
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +32 -3
- package/dist/server/auth/providers/descope.js +13 -2
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +42 -17
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- package/dist/server/auth/providers/stytch.d.ts +16 -3
- package/dist/server/auth/providers/stytch.js +4 -1
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +25 -3
- package/dist/server/auth/providers/workos.js +4 -1
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/security-schemes.d.ts +10 -0
- package/dist/server/auth/security-schemes.js +15 -4
- package/dist/server/auth/security-schemes.js.map +1 -1
- package/dist/server/auth/security-schemes.test.js +11 -2
- package/dist/server/auth/security-schemes.test.js.map +1 -1
- package/dist/server/auth/setup.d.ts +1 -1
- package/dist/server/auth/setup.js +10 -17
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +123 -59
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.d.ts +37 -3
- package/dist/server/auth/verify.js +27 -3
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +49 -0
- package/dist/server/auth/verify.test.js.map +1 -1
- package/dist/server/auth-extra.test-d.js +130 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +43 -6
- package/dist/server/auth.js +4 -5
- package/dist/server/auth.js.map +1 -1
- package/dist/server/build-manifest.test.js +7 -6
- package/dist/server/build-manifest.test.js.map +1 -1
- package/dist/server/content-helpers.d.ts +1 -1
- package/dist/server/content-helpers.js.map +1 -1
- package/dist/server/express.d.ts +23 -3
- package/dist/server/express.js +38 -32
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +220 -103
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/file-ref.d.ts +1 -1
- package/dist/server/file-ref.js +1 -1
- package/dist/server/file-ref.js.map +1 -1
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +16 -9
- package/dist/server/index.js +9 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-errors.test.d.ts +1 -0
- package/dist/server/mcp-errors.test.js +41 -0
- package/dist/server/mcp-errors.test.js.map +1 -0
- package/dist/server/middleware.d.ts +35 -10
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test-d.js +1 -1
- package/dist/server/middleware.test-d.js.map +1 -1
- package/dist/server/middleware.test.js +242 -134
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/register-tool.test.d.ts +1 -0
- package/dist/server/register-tool.test.js +27 -0
- package/dist/server/register-tool.test.js.map +1 -0
- package/dist/server/server.d.ts +110 -122
- package/dist/server/server.js +146 -286
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +86 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +27 -0
- package/dist/server/skills.js +188 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +243 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/templateHelper.d.ts +0 -3
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates.generated.js +4 -8
- package/dist/server/templates.generated.js.map +1 -1
- package/dist/server/tool-extra.test.d.ts +1 -0
- package/dist/server/tool-extra.test.js +88 -0
- package/dist/server/tool-extra.test.js.map +1 -0
- package/dist/server/view-resource-resolution.test.js +18 -13
- package/dist/server/view-resource-resolution.test.js.map +1 -1
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +9 -11
- package/dist/test/utils.js +220 -201
- package/dist/test/utils.js.map +1 -1
- package/dist/test/view.test.js +44 -40
- package/dist/test/view.test.js.map +1 -1
- package/dist/views/index.d.ts +10 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/{web/plugin → views}/scan-views.js +1 -1
- package/dist/views/scan-views.js.map +1 -0
- package/dist/views/scan-views.test.d.ts +1 -0
- package/dist/views/scan-views.test.js.map +1 -0
- package/dist/views/validate-view.d.ts +1 -0
- package/dist/{web/plugin → views}/validate-view.js +2 -2
- package/dist/views/validate-view.js.map +1 -0
- package/dist/views/validate-view.test.d.ts +1 -0
- package/dist/views/validate-view.test.js.map +1 -0
- package/dist/web/bridges/adaptor.js +14 -17
- package/dist/web/bridges/adaptor.js.map +1 -1
- package/dist/web/bridges/adaptor.test.js +24 -7
- package/dist/web/bridges/adaptor.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.js +2 -2
- package/dist/web/bridges/get-adaptor.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +6 -4
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.js +2 -2
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +17 -12
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/create-store.test.js +2 -2
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.test.js +5 -4
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/generate-helpers.d.ts +22 -18
- package/dist/web/generate-helpers.js +19 -15
- package/dist/web/generate-helpers.js.map +1 -1
- package/dist/web/generate-helpers.test-d.js +3 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -1
- package/dist/web/generate-helpers.test.js +2 -2
- package/dist/web/generate-helpers.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +2 -1
- package/dist/web/hooks/index.js +2 -1
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +2 -1
- package/dist/web/hooks/test/utils.js +1 -1
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +2 -2
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +1 -1
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +1 -1
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.d.ts +1 -3
- package/dist/web/hooks/use-download.js +1 -2
- package/dist/web/hooks/use-download.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +7 -7
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +1 -1
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host.d.ts +22 -0
- package/dist/web/hooks/use-host.js +30 -0
- package/dist/web/hooks/use-host.js.map +1 -0
- package/dist/web/hooks/use-host.test.d.ts +1 -0
- package/dist/web/hooks/use-host.test.js +59 -0
- package/dist/web/hooks/use-host.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.js +2 -2
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
- package/dist/web/hooks/use-register-view-tool.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +1 -1
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +1 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.d.ts +1 -1
- package/dist/web/hooks/use-request-size.js +1 -1
- package/dist/web/hooks/use-request-size.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +1 -1
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +2 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.d.ts +1 -20
- package/dist/web/hooks/use-tool-info.js +0 -1
- package/dist/web/hooks/use-tool-info.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test-d.js +0 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +2 -7
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.d.ts +3 -2
- package/dist/web/hooks/use-user.js +4 -3
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +5 -3
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +33 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/hooks/use-viewport.d.ts +20 -0
- package/dist/web/hooks/use-viewport.js +21 -0
- package/dist/web/hooks/use-viewport.js.map +1 -0
- package/dist/web/hooks/use-viewport.test.d.ts +1 -0
- package/dist/web/hooks/{use-layout.test.js → use-viewport.test.js} +12 -32
- package/dist/web/hooks/use-viewport.test.js.map +1 -0
- package/dist/web/mount-view.d.ts +3 -2
- package/dist/web/mount-view.js +5 -8
- package/dist/web/mount-view.js.map +1 -1
- package/package.json +20 -17
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
- package/dist/web/hooks/use-layout.d.ts +0 -24
- package/dist/web/hooks/use-layout.js +0 -25
- package/dist/web/hooks/use-layout.js.map +0 -1
- package/dist/web/hooks/use-layout.test.js.map +0 -1
- package/dist/web/plugin/data-llm.test.js +0 -81
- package/dist/web/plugin/data-llm.test.js.map +0 -1
- package/dist/web/plugin/plugin.d.ts +0 -33
- package/dist/web/plugin/plugin.js +0 -188
- package/dist/web/plugin/plugin.js.map +0 -1
- package/dist/web/plugin/scan-views.js.map +0 -1
- package/dist/web/plugin/scan-views.test.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.d.ts +0 -12
- package/dist/web/plugin/transform-data-llm.js +0 -96
- package/dist/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/web/plugin/transform-data-llm.test.js +0 -81
- package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/web/plugin/validate-view.d.ts +0 -1
- package/dist/web/plugin/validate-view.js.map +0 -1
- package/dist/web/plugin/validate-view.test.js.map +0 -1
- /package/dist/{web/hooks/use-layout.test.d.ts → context-warnings.test.d.ts} +0 -0
- /package/dist/{web/plugin/data-llm.test.d.ts → server/app.test.d.ts} +0 -0
- /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
- /package/dist/{web/plugin/scan-views.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
- /package/dist/{web/plugin/validate-view.test.d.ts → server/host.test.d.ts} +0 -0
- /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
- /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
- /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { hostFromUserAgent } from "../host.js";
|
|
1
2
|
export function authToSecuritySchemes(auth) {
|
|
2
3
|
const oauth2 = {
|
|
3
4
|
type: "oauth2",
|
|
4
5
|
...(auth.scopes?.length ? { scopes: auth.scopes } : {}),
|
|
5
6
|
};
|
|
6
|
-
return auth.
|
|
7
|
+
return auth.allowsAnonymous ? [{ type: "noauth" }, oauth2] : [oauth2];
|
|
7
8
|
}
|
|
8
9
|
export function securitySchemesAllowAnonymous(schemes) {
|
|
9
10
|
return !!schemes?.some((scheme) => scheme.type === "noauth");
|
|
10
11
|
}
|
|
11
12
|
export function evaluateSecuritySchemes(schemes, authInfo) {
|
|
12
|
-
if (securitySchemesAllowAnonymous(schemes)) {
|
|
13
|
+
if (securitySchemesAllowAnonymous(schemes) && !authInfo) {
|
|
13
14
|
return undefined;
|
|
14
15
|
}
|
|
15
16
|
const oauth2 = (schemes ?? []).filter((scheme) => scheme.type === "oauth2");
|
|
@@ -37,8 +38,7 @@ export function httpStatusForFailure(failure) {
|
|
|
37
38
|
return failure.error === "insufficient_scope" ? 403 : 401;
|
|
38
39
|
}
|
|
39
40
|
export function clientPrefersInBandChallenge(userAgent) {
|
|
40
|
-
|
|
41
|
-
return ua.includes("openai") || ua.includes("chatgpt");
|
|
41
|
+
return hostFromUserAgent(userAgent) === "openai";
|
|
42
42
|
}
|
|
43
43
|
export function wwwAuthenticateHeader(failure, resourceMetadataUrl) {
|
|
44
44
|
let header = `Bearer error="${failure.error}", error_description="${failure.description}"`;
|
|
@@ -50,4 +50,15 @@ export function wwwAuthenticateHeader(failure, resourceMetadataUrl) {
|
|
|
50
50
|
}
|
|
51
51
|
return header;
|
|
52
52
|
}
|
|
53
|
+
export function inBandChallengeResult(failure, resourceMetadataUrl) {
|
|
54
|
+
return {
|
|
55
|
+
isError: true,
|
|
56
|
+
content: [{ type: "text", text: failure.description }],
|
|
57
|
+
_meta: {
|
|
58
|
+
"mcp/www_authenticate": [
|
|
59
|
+
wwwAuthenticateHeader(failure, resourceMetadataUrl),
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
53
64
|
//# sourceMappingURL=security-schemes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-schemes.js","sourceRoot":"","sources":["../../../src/server/auth/security-schemes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"security-schemes.js","sourceRoot":"","sources":["../../../src/server/auth/security-schemes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,UAAU,qBAAqB,CAAC,IAAc;IAClD,MAAM,MAAM,GAAmB;QAC7B,IAAI,EAAE,QAAQ;QACd,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EA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["import type { AuthInfo } from \"../auth.js\";\nimport { hostFromUserAgent } from \"../host.js\";\nimport type { SecurityScheme, ToolAuth } from \"../server.js\";\n\nexport function authToSecuritySchemes(auth: ToolAuth): SecurityScheme[] {\n const oauth2: SecurityScheme = {\n type: \"oauth2\",\n ...(auth.scopes?.length ? { scopes: auth.scopes } : {}),\n };\n return auth.allowsAnonymous ? [{ type: \"noauth\" }, oauth2] : [oauth2];\n}\n\nexport function securitySchemesAllowAnonymous(\n schemes: SecurityScheme[] | undefined,\n): boolean {\n return !!schemes?.some((scheme) => scheme.type === \"noauth\");\n}\n\nexport type SchemeFailure = {\n error: \"invalid_token\" | \"insufficient_scope\";\n description: string;\n scopes: string[];\n};\n\nexport function evaluateSecuritySchemes(\n schemes: SecurityScheme[] | undefined,\n authInfo: AuthInfo | undefined,\n): SchemeFailure | undefined {\n if (securitySchemesAllowAnonymous(schemes) && !authInfo) {\n return undefined;\n }\n const oauth2 = (schemes ?? []).filter((scheme) => scheme.type === \"oauth2\");\n const required = oauth2.length ? oauth2 : [{ type: \"oauth2\" as const }];\n const scopes = [\n ...new Set(required.flatMap((scheme) => scheme.scopes ?? [])),\n ];\n if (!authInfo) {\n return {\n error: \"invalid_token\",\n description: \"Sign in to use this tool.\",\n scopes,\n };\n }\n const satisfied = required.some((scheme) =>\n (scheme.scopes ?? []).every((scope) => authInfo.scopes.includes(scope)),\n );\n return satisfied\n ? undefined\n : {\n error: \"insufficient_scope\",\n description: \"Missing required scope for this tool.\",\n scopes,\n };\n}\n\nexport function httpStatusForFailure(failure: SchemeFailure): 401 | 403 {\n return failure.error === \"insufficient_scope\" ? 403 : 401;\n}\n\nexport function clientPrefersInBandChallenge(\n userAgent: string | undefined,\n): boolean {\n return hostFromUserAgent(userAgent) === \"openai\";\n}\n\nexport function wwwAuthenticateHeader(\n failure: SchemeFailure,\n resourceMetadataUrl?: string,\n): string {\n let header = `Bearer error=\"${failure.error}\", error_description=\"${failure.description}\"`;\n if (failure.scopes.length) {\n header += `, scope=\"${failure.scopes.join(\" \")}\"`;\n }\n if (resourceMetadataUrl) {\n header += `, resource_metadata=\"${resourceMetadataUrl}\"`;\n }\n return header;\n}\n\nexport function inBandChallengeResult(\n failure: SchemeFailure,\n resourceMetadataUrl?: string,\n) {\n return {\n isError: true,\n content: [{ type: \"text\" as const, text: failure.description }],\n _meta: {\n \"mcp/www_authenticate\": [\n wwwAuthenticateHeader(failure, resourceMetadataUrl),\n ],\n },\n };\n}\n"]}
|
|
@@ -10,7 +10,7 @@ describe("clientPrefersInBandChallenge", () => {
|
|
|
10
10
|
});
|
|
11
11
|
describe("authToSecuritySchemes", () => {
|
|
12
12
|
it("maps the auth shorthand", () => {
|
|
13
|
-
expect(authToSecuritySchemes({
|
|
13
|
+
expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([
|
|
14
14
|
{ type: "noauth" },
|
|
15
15
|
{ type: "oauth2" },
|
|
16
16
|
]);
|
|
@@ -18,7 +18,7 @@ describe("authToSecuritySchemes", () => {
|
|
|
18
18
|
expect(authToSecuritySchemes({ scopes: ["checkout"] })).toEqual([
|
|
19
19
|
{ type: "oauth2", scopes: ["checkout"] },
|
|
20
20
|
]);
|
|
21
|
-
expect(authToSecuritySchemes({
|
|
21
|
+
expect(authToSecuritySchemes({ allowsAnonymous: true, scopes: ["checkout"] })).toEqual([{ type: "noauth" }, { type: "oauth2", scopes: ["checkout"] }]);
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
const authInfo = (scopes) => ({
|
|
@@ -39,6 +39,15 @@ describe("evaluateSecuritySchemes", () => {
|
|
|
39
39
|
const schemes = [{ type: "noauth" }, { type: "oauth2" }];
|
|
40
40
|
expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
|
|
41
41
|
});
|
|
42
|
+
it("enforces oauth2 scopes on a public tool once a token is present", () => {
|
|
43
|
+
const schemes = [
|
|
44
|
+
{ type: "noauth" },
|
|
45
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
46
|
+
];
|
|
47
|
+
expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
|
|
48
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.error).toBe("insufficient_scope");
|
|
49
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["checkout"]))).toBeUndefined();
|
|
50
|
+
});
|
|
42
51
|
it("fails an oauth2-only tool with no token (invalid_token / 401)", () => {
|
|
43
52
|
expect(evaluateSecuritySchemes([{ type: "oauth2" }], undefined)?.error).toBe("invalid_token");
|
|
44
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-schemes.test.js","sourceRoot":"","sources":["../../../src/server/auth/security-schemes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,uBAAuB,EACvB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAE/B,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,4BAA4B,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpE,MAAM,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MA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AC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,KAAK,EAAE,oBAAoB;YAC3B,WAAW,EAAE,uCAAuC;YACpD,MAAM,EAAE,CAAC,UAAU,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,KAAK,EAAE,eAAe;YACtB,WAAW,EAAE,2BAA2B;YACxC,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { AuthInfo } from \"../auth.js\";\nimport type { SecurityScheme } from \"../server.js\";\nimport {\n authToSecuritySchemes,\n clientPrefersInBandChallenge,\n evaluateSecuritySchemes,\n securitySchemesAllowAnonymous,\n wwwAuthenticateHeader,\n} from \"./security-schemes.js\";\n\ndescribe(\"clientPrefersInBandChallenge\", () => {\n it(\"detects ChatGPT / OpenAI user agents\", () => {\n expect(clientPrefersInBandChallenge(\"openai-mcp/1.0\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"ChatGPT\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"Claude-User/1.0\")).toBe(false);\n expect(clientPrefersInBandChallenge(undefined)).toBe(false);\n });\n});\n\ndescribe(\"authToSecuritySchemes\", () => {\n it(\"maps the auth shorthand\", () => {\n expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([\n { type: \"noauth\" },\n { type: \"oauth2\" },\n ]);\n expect(authToSecuritySchemes({})).toEqual([{ type: \"oauth2\" }]);\n expect(authToSecuritySchemes({ scopes: [\"checkout\"] })).toEqual([\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ]);\n expect(\n authToSecuritySchemes({ allowsAnonymous: true, scopes: [\"checkout\"] }),\n ).toEqual([{ type: \"noauth\" }, { type: \"oauth2\", scopes: [\"checkout\"] }]);\n });\n});\n\nconst authInfo = (scopes: string[]): AuthInfo => ({\n token: \"t\",\n clientId: \"c\",\n scopes,\n});\n\ndescribe(\"securitySchemesAllowAnonymous\", () => {\n it(\"is true only when a noauth scheme is present\", () => {\n expect(securitySchemesAllowAnonymous([{ type: \"noauth\" }])).toBe(true);\n expect(\n securitySchemesAllowAnonymous([{ type: \"noauth\" }, { type: \"oauth2\" }]),\n ).toBe(true);\n expect(securitySchemesAllowAnonymous([{ type: \"oauth2\" }])).toBe(false);\n expect(securitySchemesAllowAnonymous(undefined)).toBe(false);\n });\n});\n\ndescribe(\"evaluateSecuritySchemes\", () => {\n it(\"lets anonymous callers through a noauth tool\", () => {\n const schemes: SecurityScheme[] = [{ type: \"noauth\" }, { type: \"oauth2\" }];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n });\n\n it(\"enforces oauth2 scopes on a public tool once a token is present\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"noauth\" },\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"fails an oauth2-only tool with no token (invalid_token / 401)\", () => {\n expect(\n evaluateSecuritySchemes([{ type: \"oauth2\" }], undefined)?.error,\n ).toBe(\"invalid_token\");\n });\n\n it(\"fails when the token is missing a required scope (insufficient_scope / 403)\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n });\n\n it(\"passes when the token carries every required scope\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\", \"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"treats an undeclared tool as auth-required, satisfied by any valid token\", () => {\n expect(evaluateSecuritySchemes(undefined, undefined)?.error).toBe(\n \"invalid_token\",\n );\n expect(evaluateSecuritySchemes(undefined, authInfo([]))).toBeUndefined();\n });\n\n it(\"carries the tool's required scopes on the failure\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)?.scopes).toEqual([\n \"checkout\",\n ]);\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.scopes,\n ).toEqual([\"checkout\"]);\n });\n});\n\ndescribe(\"wwwAuthenticateHeader\", () => {\n it(\"names the required scopes so the client can step up\", () => {\n const header = wwwAuthenticateHeader({\n error: \"insufficient_scope\",\n description: \"Missing required scope for this tool.\",\n scopes: [\"checkout\"],\n });\n expect(header).toContain('error=\"insufficient_scope\"');\n expect(header).toContain('scope=\"checkout\"');\n });\n\n it(\"omits the scope parameter when there are none\", () => {\n const header = wwwAuthenticateHeader({\n error: \"invalid_token\",\n description: \"Sign in to use this tool.\",\n scopes: [],\n });\n expect(header).not.toContain(\"scope=\");\n });\n});\n"]}
|
|
@@ -3,4 +3,4 @@ import type { SecurityScheme } from "../server.js";
|
|
|
3
3
|
import type { OAuthConfig } from "./index.js";
|
|
4
4
|
export type ResourceMetadataUrlResolver = (getHeader: (key: string) => string | undefined) => string;
|
|
5
5
|
/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */
|
|
6
|
-
export declare function setupOAuth(app: Express, config: OAuthConfig, schemesByTool:
|
|
6
|
+
export declare function setupOAuth(app: Express, config: OAuthConfig<Record<string, unknown>>, schemesByTool: ReadonlyMap<string, SecurityScheme[] | undefined>): ResourceMetadataUrlResolver;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter, } from "@modelcontextprotocol/
|
|
1
|
+
import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter, } from "@modelcontextprotocol/express";
|
|
2
2
|
import cors from "cors";
|
|
3
3
|
import { optionalBearerAuth, requireBearerAuth } from "../auth.js";
|
|
4
4
|
import { resolveServerOrigin } from "../requestOrigin.js";
|
|
5
|
-
import { clientPrefersInBandChallenge, evaluateSecuritySchemes, httpStatusForFailure, securitySchemesAllowAnonymous, wwwAuthenticateHeader, } from "./security-schemes.js";
|
|
6
|
-
import { createJwksVerifier } from "./verify.js";
|
|
5
|
+
import { clientPrefersInBandChallenge, evaluateSecuritySchemes, httpStatusForFailure, inBandChallengeResult, securitySchemesAllowAnonymous, wwwAuthenticateHeader, } from "./security-schemes.js";
|
|
7
6
|
/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */
|
|
8
7
|
export function setupOAuth(app, config, schemesByTool) {
|
|
9
|
-
if (!config.
|
|
10
|
-
throw new Error("oauth
|
|
8
|
+
if (!config.verifier) {
|
|
9
|
+
throw new Error("oauth requires a `verifier`");
|
|
11
10
|
}
|
|
12
11
|
const acceptsAnonymous = () => [...schemesByTool.values()].some(securitySchemesAllowAnonymous);
|
|
13
|
-
const verifier =
|
|
12
|
+
const verifier = config.verifier;
|
|
14
13
|
const bearer = (options) => {
|
|
15
14
|
const required = requireBearerAuth(options);
|
|
16
15
|
const optional = optionalBearerAuth(options);
|
|
@@ -71,23 +70,17 @@ export function setupOAuth(app, config, schemesByTool) {
|
|
|
71
70
|
if (!failure) {
|
|
72
71
|
return next();
|
|
73
72
|
}
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
return next();
|
|
78
|
-
}
|
|
73
|
+
const url = resourceMetadataUrl((key) => req.get(key));
|
|
74
|
+
if (!Array.isArray(body) &&
|
|
75
|
+
clientPrefersInBandChallenge(req.get("user-agent"))) {
|
|
79
76
|
res.json({
|
|
80
77
|
jsonrpc: "2.0",
|
|
81
78
|
id: body?.id ?? null,
|
|
82
|
-
result:
|
|
83
|
-
content: [{ type: "text", text: failure.description }],
|
|
84
|
-
isError: true,
|
|
85
|
-
_meta: { "mcp/www_authenticate": [challenge] },
|
|
86
|
-
},
|
|
79
|
+
result: inBandChallengeResult(failure, url),
|
|
87
80
|
});
|
|
88
81
|
return;
|
|
89
82
|
}
|
|
90
|
-
res.set("WWW-Authenticate",
|
|
83
|
+
res.set("WWW-Authenticate", wwwAuthenticateHeader(failure, url));
|
|
91
84
|
res.status(httpStatusForFailure(failure)).json({
|
|
92
85
|
error: failure.error,
|
|
93
86
|
error_description: failure.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/server/auth/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/server/auth/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EAErB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,uBAAuB,CA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;gBACpB,MAAM,EAAE,qBAAqB,CAAC,OAAO,EAAE,GAAG,CAAC;aAC5C,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACjE,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7C,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,iBAAiB,EAAE,OAAO,CAAC,WAAW;SACvC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import {\n type BearerAuthMiddlewareOptions,\n getOAuthProtectedResourceMetadataUrl,\n mcpAuthMetadataRouter,\n} from \"@modelcontextprotocol/express\";\nimport cors from \"cors\";\nimport type { Express, Request, RequestHandler } from \"express\";\nimport type { AuthInfo } from \"../auth.js\";\nimport { optionalBearerAuth, requireBearerAuth } from \"../auth.js\";\nimport { resolveServerOrigin } from \"../requestOrigin.js\";\nimport type { SecurityScheme } from \"../server.js\";\nimport type { OAuthConfig } from \"./index.js\";\nimport {\n clientPrefersInBandChallenge,\n evaluateSecuritySchemes,\n httpStatusForFailure,\n inBandChallengeResult,\n type SchemeFailure,\n securitySchemesAllowAnonymous,\n wwwAuthenticateHeader,\n} from \"./security-schemes.js\";\n\nexport type ResourceMetadataUrlResolver = (\n getHeader: (key: string) => string | undefined,\n) => string;\n\n/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */\nexport function setupOAuth(\n app: Express,\n config: OAuthConfig<Record<string, unknown>>,\n schemesByTool: ReadonlyMap<string, SecurityScheme[] | undefined>,\n): ResourceMetadataUrlResolver {\n if (!config.verifier) {\n throw new Error(\"oauth requires a `verifier`\");\n }\n\n const acceptsAnonymous = () =>\n [...schemesByTool.values()].some(securitySchemesAllowAnonymous);\n const verifier = config.verifier;\n const bearer = (options: BearerAuthMiddlewareOptions): RequestHandler => {\n const required = requireBearerAuth(options);\n const optional = optionalBearerAuth(options);\n return (req, res, next) =>\n (acceptsAnonymous() ? optional : required)(req, res, next);\n };\n\n let resourceMetadataUrl: ResourceMetadataUrlResolver;\n\n // baseUrl known at boot: bake the resource URLs once, no Host-header trust.\n if (config.baseUrl !== undefined) {\n let baseUrl: URL;\n try {\n baseUrl = new URL(config.baseUrl);\n } catch {\n throw new Error(\n `oauth.baseUrl must be a valid absolute URL, got: ${JSON.stringify(\n config.baseUrl,\n )}`,\n );\n }\n app.use(\n mcpAuthMetadataRouter({\n oauthMetadata: config.oauthMetadata,\n resourceServerUrl: baseUrl,\n scopesSupported: config.scopesSupported,\n }),\n );\n const url = getOAuthProtectedResourceMetadataUrl(baseUrl);\n resourceMetadataUrl = () => url;\n } else {\n // No baseUrl: resolve the resource origin per request from forwarded headers\n // (same precedence the framework uses for view serverUrl). Origin headers are\n // pathless, so the PRM path stays at root, matching the SDK's static layout.\n const resolveOrigin = (getHeader: (key: string) => string | undefined) =>\n new URL(resolveServerOrigin(getHeader));\n app.use(\n \"/.well-known/oauth-authorization-server\",\n cors(),\n (_req, res) => void res.json(config.oauthMetadata),\n );\n app.use(\"/.well-known/oauth-protected-resource\", cors(), (req, res) => {\n res.json({\n resource: resolveOrigin((key) => req.get(key)).href,\n authorization_servers: [config.oauthMetadata.issuer],\n scopes_supported: config.scopesSupported,\n });\n });\n resourceMetadataUrl = (getHeader) =>\n getOAuthProtectedResourceMetadataUrl(resolveOrigin(getHeader));\n }\n\n app.use(\"/mcp\", (req, res, next) =>\n bearer({\n verifier,\n requiredScopes: config.requiredScopes,\n resourceMetadataUrl: resourceMetadataUrl((key) => req.get(key)),\n })(req, res, next),\n );\n\n app.use(\"/mcp\", (req, res, next) => {\n type Call = {\n id?: string | number | null;\n method?: string;\n params?: { name?: string };\n };\n const body = req.body as Call | Call[] | undefined;\n const calls = Array.isArray(body) ? body : [body];\n const auth = (req as Request & { auth?: AuthInfo }).auth;\n let failure: SchemeFailure | undefined;\n for (const call of calls) {\n const tool = call?.params?.name;\n if (call?.method === \"tools/call\" && tool && schemesByTool.has(tool)) {\n failure = evaluateSecuritySchemes(schemesByTool.get(tool), auth);\n if (failure) {\n break;\n }\n }\n }\n if (!failure) {\n return next();\n }\n const url = resourceMetadataUrl((key) => req.get(key));\n if (\n !Array.isArray(body) &&\n clientPrefersInBandChallenge(req.get(\"user-agent\"))\n ) {\n res.json({\n jsonrpc: \"2.0\",\n id: body?.id ?? null,\n result: inBandChallengeResult(failure, url),\n });\n return;\n }\n res.set(\"WWW-Authenticate\", wwwAuthenticateHeader(failure, url));\n res.status(httpStatusForFailure(failure)).json({\n error: failure.error,\n error_description: failure.description,\n });\n });\n\n return resourceMetadataUrl;\n}\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
2
|
import http from "node:http";
|
|
3
|
-
import { Client } from "@modelcontextprotocol/
|
|
4
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import { Client, StreamableHTTPClientTransport, } from "@modelcontextprotocol/client";
|
|
5
4
|
import * as jose from "jose";
|
|
6
5
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { Skybridge } from "../app.js";
|
|
7
7
|
import { McpServer } from "../server.js";
|
|
8
|
+
import { createJwksVerifier } from "./verify.js";
|
|
8
9
|
vi.mock("@skybridge/devtools", () => ({
|
|
9
10
|
devtoolsStaticServer: () => ((_req, _res, next) => next()),
|
|
10
11
|
}));
|
|
@@ -50,7 +51,9 @@ function signToken(key, scope = "openid email") {
|
|
|
50
51
|
}
|
|
51
52
|
async function bootServer(jwksUri, { baseUrl = "https://app.example.test" } = {}) {
|
|
52
53
|
const { createApp } = await import("../express.js");
|
|
53
|
-
const
|
|
54
|
+
const app = new Skybridge({
|
|
55
|
+
name: "auth-test",
|
|
56
|
+
version: "0.0.0",
|
|
54
57
|
oauth: {
|
|
55
58
|
...(baseUrl === null ? {} : { baseUrl }),
|
|
56
59
|
oauthMetadata: {
|
|
@@ -59,21 +62,30 @@ async function bootServer(jwksUri, { baseUrl = "https://app.example.test" } = {}
|
|
|
59
62
|
token_endpoint: `${ISSUER}/token`,
|
|
60
63
|
response_types_supported: ["code"],
|
|
61
64
|
},
|
|
62
|
-
|
|
65
|
+
verifier: createJwksVerifier({
|
|
66
|
+
issuer: ISSUER,
|
|
67
|
+
audience: AUDIENCE,
|
|
68
|
+
jwksUri,
|
|
69
|
+
}),
|
|
63
70
|
scopesSupported: ["openid", "email"],
|
|
64
71
|
requiredScopes: ["openid"],
|
|
65
72
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
handler: (server) => server.registerTool({
|
|
74
|
+
name: "whoami",
|
|
75
|
+
description: "Returns the caller identity.",
|
|
76
|
+
inputSchema: {},
|
|
77
|
+
}, (_args, extra) => ({
|
|
78
|
+
structuredContent: {
|
|
79
|
+
clientId: extra.http?.authInfo?.clientId ?? null,
|
|
80
|
+
},
|
|
81
|
+
content: [
|
|
82
|
+
{ type: "text", text: extra.http?.authInfo?.clientId ?? "anon" },
|
|
83
|
+
],
|
|
84
|
+
})),
|
|
85
|
+
});
|
|
74
86
|
const httpServer = http.createServer();
|
|
75
|
-
await createApp({
|
|
76
|
-
const listening = http.createServer(
|
|
87
|
+
await createApp({ app, httpServer });
|
|
88
|
+
const listening = http.createServer(app.express);
|
|
77
89
|
await new Promise((resolve) => listening.listen(0, resolve));
|
|
78
90
|
appServer = listening;
|
|
79
91
|
const port = listening.address().port;
|
|
@@ -167,7 +179,9 @@ describe("baseUrl inferred from headers", () => {
|
|
|
167
179
|
});
|
|
168
180
|
async function bootMixedServer(jwksUri) {
|
|
169
181
|
const { createApp } = await import("../express.js");
|
|
170
|
-
const
|
|
182
|
+
const app = new Skybridge({
|
|
183
|
+
name: "mixed-auth-test",
|
|
184
|
+
version: "0.0.0",
|
|
171
185
|
oauth: {
|
|
172
186
|
baseUrl: "https://app.example.test",
|
|
173
187
|
oauthMetadata: {
|
|
@@ -176,34 +190,46 @@ async function bootMixedServer(jwksUri) {
|
|
|
176
190
|
token_endpoint: `${ISSUER}/token`,
|
|
177
191
|
response_types_supported: ["code"],
|
|
178
192
|
},
|
|
179
|
-
|
|
193
|
+
verifier: createJwksVerifier({
|
|
194
|
+
issuer: ISSUER,
|
|
195
|
+
audience: AUDIENCE,
|
|
196
|
+
jwksUri,
|
|
197
|
+
}),
|
|
180
198
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
handler: (server) => server
|
|
200
|
+
.registerTool({
|
|
201
|
+
name: "public-whoami",
|
|
202
|
+
description: "Public.",
|
|
203
|
+
inputSchema: {},
|
|
204
|
+
auth: { allowsAnonymous: true },
|
|
205
|
+
}, (_args, extra) => ({
|
|
206
|
+
content: [
|
|
207
|
+
{ type: "text", text: extra.http?.authInfo?.clientId ?? "anon" },
|
|
208
|
+
],
|
|
209
|
+
}))
|
|
210
|
+
.registerTool({
|
|
211
|
+
name: "private-whoami",
|
|
212
|
+
description: "Private.",
|
|
213
|
+
inputSchema: {},
|
|
214
|
+
auth: {},
|
|
215
|
+
}, (_args, extra) => ({
|
|
216
|
+
content: [
|
|
217
|
+
{ type: "text", text: extra.http?.authInfo?.clientId ?? "anon" },
|
|
218
|
+
],
|
|
219
|
+
}))
|
|
220
|
+
.registerTool({
|
|
221
|
+
name: "undeclared-whoami",
|
|
222
|
+
description: "Registered without auth or securitySchemes.",
|
|
223
|
+
inputSchema: {},
|
|
224
|
+
}, (_args, extra) => ({
|
|
225
|
+
content: [
|
|
226
|
+
{ type: "text", text: extra.http?.authInfo?.clientId ?? "anon" },
|
|
227
|
+
],
|
|
228
|
+
})),
|
|
229
|
+
});
|
|
204
230
|
const httpServer = http.createServer();
|
|
205
|
-
await createApp({
|
|
206
|
-
const listening = http.createServer(
|
|
231
|
+
await createApp({ app, httpServer });
|
|
232
|
+
const listening = http.createServer(app.express);
|
|
207
233
|
await new Promise((resolve) => listening.listen(0, resolve));
|
|
208
234
|
appServer = listening;
|
|
209
235
|
const port = listening.address().port;
|
|
@@ -278,7 +304,7 @@ describe("mixed-auth door", () => {
|
|
|
278
304
|
const text = await res.text();
|
|
279
305
|
expect(text).not.toContain("client-1");
|
|
280
306
|
});
|
|
281
|
-
it("gates a tool
|
|
307
|
+
it("gates a tool with no declared schemes (secure default)", async () => {
|
|
282
308
|
const { jwksUri } = await startJwks();
|
|
283
309
|
const base = await bootMixedServer(jwksUri);
|
|
284
310
|
const res = await fetch(`${base}/mcp`, {
|
|
@@ -291,7 +317,7 @@ describe("mixed-auth door", () => {
|
|
|
291
317
|
jsonrpc: "2.0",
|
|
292
318
|
id: 1,
|
|
293
319
|
method: "tools/call",
|
|
294
|
-
params: { name: "
|
|
320
|
+
params: { name: "undeclared-whoami", arguments: {} },
|
|
295
321
|
}),
|
|
296
322
|
});
|
|
297
323
|
expect(res.status).toBe(401);
|
|
@@ -343,10 +369,36 @@ describe("mixed-auth door", () => {
|
|
|
343
369
|
expect(challenge[0]).toMatch(/error="invalid_token"/);
|
|
344
370
|
expect(challenge[0]).toMatch(/resource_metadata=/);
|
|
345
371
|
});
|
|
372
|
+
it("fails closed on a ChatGPT batch (transport 401, no in-band challenge)", async () => {
|
|
373
|
+
const { jwksUri } = await startJwks();
|
|
374
|
+
const base = await bootMixedServer(jwksUri);
|
|
375
|
+
const res = await fetch(`${base}/mcp`, {
|
|
376
|
+
method: "POST",
|
|
377
|
+
headers: {
|
|
378
|
+
"Content-Type": "application/json",
|
|
379
|
+
Accept: "application/json, text/event-stream",
|
|
380
|
+
"User-Agent": "openai-mcp/1.0",
|
|
381
|
+
},
|
|
382
|
+
body: JSON.stringify([
|
|
383
|
+
{
|
|
384
|
+
jsonrpc: "2.0",
|
|
385
|
+
id: 1,
|
|
386
|
+
method: "tools/call",
|
|
387
|
+
params: { name: "private-whoami", arguments: {} },
|
|
388
|
+
},
|
|
389
|
+
]),
|
|
390
|
+
});
|
|
391
|
+
expect(res.status).toBe(401);
|
|
392
|
+
expect(res.headers.get("www-authenticate")).toMatch(/^Bearer /);
|
|
393
|
+
const text = await res.text();
|
|
394
|
+
expect(text).not.toContain("client-1");
|
|
395
|
+
});
|
|
346
396
|
});
|
|
347
397
|
async function bootScopedServer(jwksUri) {
|
|
348
398
|
const { createApp } = await import("../express.js");
|
|
349
|
-
const
|
|
399
|
+
const app = new Skybridge({
|
|
400
|
+
name: "scoped-auth-test",
|
|
401
|
+
version: "0.0.0",
|
|
350
402
|
oauth: {
|
|
351
403
|
baseUrl: "https://app.example.test",
|
|
352
404
|
oauthMetadata: {
|
|
@@ -355,17 +407,22 @@ async function bootScopedServer(jwksUri) {
|
|
|
355
407
|
token_endpoint: `${ISSUER}/token`,
|
|
356
408
|
response_types_supported: ["code"],
|
|
357
409
|
},
|
|
358
|
-
|
|
410
|
+
verifier: createJwksVerifier({
|
|
411
|
+
issuer: ISSUER,
|
|
412
|
+
audience: AUDIENCE,
|
|
413
|
+
jwksUri,
|
|
414
|
+
}),
|
|
359
415
|
},
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
416
|
+
handler: (server) => server.registerTool({
|
|
417
|
+
name: "checkout",
|
|
418
|
+
description: "Needs the checkout scope.",
|
|
419
|
+
inputSchema: {},
|
|
420
|
+
auth: { scopes: ["checkout"] },
|
|
421
|
+
}, () => ({ content: [{ type: "text", text: "ok" }] })),
|
|
422
|
+
});
|
|
366
423
|
const httpServer = http.createServer();
|
|
367
|
-
await createApp({
|
|
368
|
-
const listening = http.createServer(
|
|
424
|
+
await createApp({ app, httpServer });
|
|
425
|
+
const listening = http.createServer(app.express);
|
|
369
426
|
await new Promise((resolve) => listening.listen(0, resolve));
|
|
370
427
|
appServer = listening;
|
|
371
428
|
const port = listening.address().port;
|
|
@@ -418,8 +475,8 @@ describe("auth shorthand validation", () => {
|
|
|
418
475
|
it("throws when `auth` sets scopes but no oauth provider is configured", () => {
|
|
419
476
|
expect(() => new McpServer({ name: "t", version: "0" }).registerTool({ name: "x", inputSchema: {}, auth: { scopes: ["checkout"] } }, () => ({ content: [{ type: "text", text: "" }] }))).toThrow(/no `oauth` provider/);
|
|
420
477
|
});
|
|
421
|
-
it("allows `auth: {
|
|
422
|
-
expect(() => new McpServer({ name: "t", version: "0" }).registerTool({ name: "x", inputSchema: {}, auth: {
|
|
478
|
+
it("allows `auth: { allowsAnonymous: true }` without an oauth provider", () => {
|
|
479
|
+
expect(() => new McpServer({ name: "t", version: "0" }).registerTool({ name: "x", inputSchema: {}, auth: { allowsAnonymous: true } }, () => ({ content: [{ type: "text", text: "" }] }))).not.toThrow();
|
|
423
480
|
});
|
|
424
481
|
it("prefers `securitySchemes` over `auth` when both are set (untyped path)", () => {
|
|
425
482
|
expect(() => new McpServer({ name: "t", version: "0" }).registerTool({
|
|
@@ -437,14 +494,21 @@ describe("oauth config validation", () => {
|
|
|
437
494
|
token_endpoint: `${ISSUER}/token`,
|
|
438
495
|
response_types_supported: ["code"],
|
|
439
496
|
};
|
|
440
|
-
it("
|
|
441
|
-
|
|
497
|
+
it("rejects a non-absolute baseUrl when the app is first used", async () => {
|
|
498
|
+
const app = new Skybridge({
|
|
499
|
+
name: "t",
|
|
500
|
+
version: "0",
|
|
442
501
|
oauth: {
|
|
443
502
|
baseUrl: "not-a-url",
|
|
444
503
|
oauthMetadata: validMetadata,
|
|
445
|
-
|
|
504
|
+
verifier: createJwksVerifier({
|
|
505
|
+
issuer: ISSUER,
|
|
506
|
+
audience: AUDIENCE,
|
|
507
|
+
}),
|
|
446
508
|
},
|
|
447
|
-
|
|
509
|
+
handler: (server) => server,
|
|
510
|
+
});
|
|
511
|
+
await expect(app.createServerInstance()).rejects.toThrow(/baseUrl must be a valid absolute URL/);
|
|
448
512
|
});
|
|
449
513
|
});
|
|
450
514
|
//# sourceMappingURL=setup.test.js.map
|