skybridge 0.0.0-dev.f3a1db3 → 0.0.0-dev.f3a8932

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.
Files changed (121) hide show
  1. package/README.md +2 -9
  2. package/dist/cli/build-helpers.d.ts +6 -2
  3. package/dist/cli/build-helpers.js +37 -12
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +69 -3
  6. package/dist/cli/build-helpers.test.js.map +1 -1
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.d.ts +1 -0
  11. package/dist/cli/build-steps.test.js +52 -0
  12. package/dist/cli/build-steps.test.js.map +1 -0
  13. package/dist/cli/header.d.ts +1 -1
  14. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  15. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  16. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  17. package/dist/cli/run-plain.d.ts +18 -0
  18. package/dist/cli/run-plain.js +89 -0
  19. package/dist/cli/run-plain.js.map +1 -0
  20. package/dist/cli/use-nodemon.d.ts +14 -0
  21. package/dist/cli/use-nodemon.js +71 -60
  22. package/dist/cli/use-nodemon.js.map +1 -1
  23. package/dist/cli/use-typescript-check.d.ts +8 -2
  24. package/dist/cli/use-typescript-check.js +70 -67
  25. package/dist/cli/use-typescript-check.js.map +1 -1
  26. package/dist/commands/build.d.ts +0 -2
  27. package/dist/commands/build.js +2 -61
  28. package/dist/commands/build.js.map +1 -1
  29. package/dist/commands/dev.d.ts +1 -0
  30. package/dist/commands/dev.js +34 -2
  31. package/dist/commands/dev.js.map +1 -1
  32. package/dist/server/auth/providers/authplane.d.ts +47 -0
  33. package/dist/server/auth/providers/authplane.js +57 -0
  34. package/dist/server/auth/providers/authplane.js.map +1 -0
  35. package/dist/server/auth/providers/authplane.test.d.ts +1 -0
  36. package/dist/server/auth/providers/authplane.test.js +138 -0
  37. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  38. package/dist/server/auth/providers/custom.d.ts +8 -0
  39. package/dist/server/auth/providers/custom.js +19 -7
  40. package/dist/server/auth/providers/custom.js.map +1 -1
  41. package/dist/server/auth/providers/custom.test.js +53 -4
  42. package/dist/server/auth/providers/custom.test.js.map +1 -1
  43. package/dist/server/auth/providers/descope.js +13 -2
  44. package/dist/server/auth/providers/descope.js.map +1 -1
  45. package/dist/server/auth/providers/descope.test.js +38 -15
  46. package/dist/server/auth/providers/descope.test.js.map +1 -1
  47. package/dist/server/auth/security-schemes.d.ts +23 -0
  48. package/dist/server/auth/security-schemes.js +64 -0
  49. package/dist/server/auth/security-schemes.js.map +1 -0
  50. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  51. package/dist/server/auth/security-schemes.test.js +99 -0
  52. package/dist/server/auth/security-schemes.test.js.map +1 -0
  53. package/dist/server/auth/setup.d.ts +3 -1
  54. package/dist/server/auth/setup.js +62 -21
  55. package/dist/server/auth/setup.js.map +1 -1
  56. package/dist/server/auth/setup.test.js +291 -2
  57. package/dist/server/auth/setup.test.js.map +1 -1
  58. package/dist/server/host.d.ts +2 -0
  59. package/dist/server/host.js +11 -0
  60. package/dist/server/host.js.map +1 -0
  61. package/dist/server/host.test.d.ts +1 -0
  62. package/dist/server/host.test.js +13 -0
  63. package/dist/server/host.test.js.map +1 -0
  64. package/dist/server/index.d.ts +3 -1
  65. package/dist/server/index.js +3 -1
  66. package/dist/server/index.js.map +1 -1
  67. package/dist/server/server.d.ts +49 -5
  68. package/dist/server/server.js +142 -19
  69. package/dist/server/server.js.map +1 -1
  70. package/dist/server/skills-integration.test.d.ts +1 -0
  71. package/dist/server/skills-integration.test.js +63 -0
  72. package/dist/server/skills-integration.test.js.map +1 -0
  73. package/dist/server/skills.d.ts +23 -0
  74. package/dist/server/skills.js +178 -0
  75. package/dist/server/skills.js.map +1 -0
  76. package/dist/server/skills.test.d.ts +1 -0
  77. package/dist/server/skills.test.js +210 -0
  78. package/dist/server/skills.test.js.map +1 -0
  79. package/dist/server/view-name.test-d.d.ts +1 -0
  80. package/dist/server/view-name.test-d.js +8 -0
  81. package/dist/server/view-name.test-d.js.map +1 -0
  82. package/dist/server/view-resource-resolution.test.js +69 -1
  83. package/dist/server/view-resource-resolution.test.js.map +1 -1
  84. package/dist/server/viewsDevServer.js +4 -1
  85. package/dist/server/viewsDevServer.js.map +1 -1
  86. package/dist/test/view.test.js +3 -3
  87. package/dist/test/view.test.js.map +1 -1
  88. package/dist/web/bridges/adaptor.js +36 -5
  89. package/dist/web/bridges/adaptor.js.map +1 -1
  90. package/dist/web/bridges/adaptor.test.js +31 -4
  91. package/dist/web/bridges/adaptor.test.js.map +1 -1
  92. package/dist/web/bridges/mcp-app/bridge.js +5 -3
  93. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  94. package/dist/web/bridges/mcp-app/types.d.ts +2 -0
  95. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  96. package/dist/web/components/modal-provider.d.ts +1 -1
  97. package/dist/web/data-llm.d.ts +1 -1
  98. package/dist/web/data-llm.test.js +8 -0
  99. package/dist/web/data-llm.test.js.map +1 -1
  100. package/dist/web/hooks/index.d.ts +1 -0
  101. package/dist/web/hooks/index.js +1 -0
  102. package/dist/web/hooks/index.js.map +1 -1
  103. package/dist/web/hooks/test/utils.d.ts +2 -1
  104. package/dist/web/hooks/test/utils.js +1 -1
  105. package/dist/web/hooks/test/utils.js.map +1 -1
  106. package/dist/web/hooks/use-host-info.d.ts +22 -0
  107. package/dist/web/hooks/use-host-info.js +30 -0
  108. package/dist/web/hooks/use-host-info.js.map +1 -0
  109. package/dist/web/hooks/use-host-info.test.d.ts +1 -0
  110. package/dist/web/hooks/use-host-info.test.js +59 -0
  111. package/dist/web/hooks/use-host-info.test.js.map +1 -0
  112. package/dist/web/hooks/use-view-state.js +19 -9
  113. package/dist/web/hooks/use-view-state.js.map +1 -1
  114. package/dist/web/hooks/use-view-state.test.js +31 -0
  115. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  116. package/dist/web/plugin/plugin.d.ts +6 -0
  117. package/dist/web/plugin/plugin.js +3 -3
  118. package/dist/web/plugin/plugin.js.map +1 -1
  119. package/package.json +21 -20
  120. package/dist/cli/resolve-views-dir.d.ts +0 -1
  121. package/dist/cli/resolve-views-dir.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.test.js","sourceRoot":"","sources":["../../src/server/host.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC3E,MAAM,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3D,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,MAAM,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7D,MAAM,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { hostFromUserAgent } from \"./host.js\";\n\ndescribe(\"hostFromUserAgent\", () => {\n it(\"classifies known hosts case-insensitively and defaults to unknown\", () => {\n expect(hostFromUserAgent(\"openai-mcp/1.0\")).toBe(\"openai\");\n expect(hostFromUserAgent(\"ChatGPT\")).toBe(\"openai\");\n expect(hostFromUserAgent(\"claude-user\")).toBe(\"claude\");\n expect(hostFromUserAgent(\"Claude-User/1.0\")).toBe(\"unknown\");\n expect(hostFromUserAgent(\"Mozilla/5.0\")).toBe(\"unknown\");\n expect(hostFromUserAgent(undefined)).toBe(\"unknown\");\n });\n});\n"]}
@@ -1,5 +1,6 @@
1
1
  export type { OAuthConfig } from "./auth/index.js";
2
2
  export { auth0Provider } from "./auth/providers/auth0.js";
3
+ export { authplaneProvider } from "./auth/providers/authplane.js";
3
4
  export { clerkProvider } from "./auth/providers/clerk.js";
4
5
  export { customProvider } from "./auth/providers/custom.js";
5
6
  export { descopeProvider } from "./auth/providers/descope.js";
@@ -11,5 +12,6 @@ export { FileRef } from "./file-ref.js";
11
12
  export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
12
13
  export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
13
14
  export type { HandlerContent, JsonOptions, KnownToolMeta, McpServerTypes, SecurityScheme, SkybridgeServerOptions, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
14
- export { __setBuildManifest, McpServer, normalizeContent, } from "./server.js";
15
+ export { __setBuildManifest, __setSkillsManifest, McpServer, normalizeContent, } from "./server.js";
16
+ export { discoverSkills, type Skill, type SkillsManifest, } from "./skills.js";
15
17
  export { viewsDevServer } from "./viewsDevServer.js";
@@ -1,4 +1,5 @@
1
1
  export { auth0Provider } from "./auth/providers/auth0.js";
2
+ export { authplaneProvider } from "./auth/providers/authplane.js";
2
3
  export { clerkProvider } from "./auth/providers/clerk.js";
3
4
  export { customProvider } from "./auth/providers/custom.js";
4
5
  export { descopeProvider } from "./auth/providers/descope.js";
@@ -7,6 +8,7 @@ export { workosProvider } from "./auth/providers/workos.js";
7
8
  export { InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
8
9
  export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
9
10
  export { FileRef } from "./file-ref.js";
10
- export { __setBuildManifest, McpServer, normalizeContent, } from "./server.js";
11
+ export { __setBuildManifest, __setSkillsManifest, McpServer, normalizeContent, } from "./server.js";
12
+ export { discoverSkills, } from "./skills.js";
11
13
  export { viewsDevServer } from "./viewsDevServer.js";
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export type { OAuthConfig } from \"./auth/index.js\";\nexport { auth0Provider } from \"./auth/providers/auth0.js\";\nexport { clerkProvider } from \"./auth/providers/clerk.js\";\nexport { customProvider } from \"./auth/providers/custom.js\";\nexport { descopeProvider } from \"./auth/providers/descope.js\";\nexport { stytchProvider } from \"./auth/providers/stytch.js\";\nexport { workosProvider } from \"./auth/providers/workos.js\";\nexport {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n InvalidTokenError,\n mcpAuthMetadataRouter,\n optionalBearerAuth,\n requireBearerAuth,\n} from \"./auth.js\";\nexport {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport { FileRef } from \"./file-ref.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n JsonOptions,\n KnownToolMeta,\n McpServerTypes,\n SecurityScheme,\n SkybridgeServerOptions,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n __setBuildManifest,\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export type { OAuthConfig } from \"./auth/index.js\";\nexport { auth0Provider } from \"./auth/providers/auth0.js\";\nexport { authplaneProvider } from \"./auth/providers/authplane.js\";\nexport { clerkProvider } from \"./auth/providers/clerk.js\";\nexport { customProvider } from \"./auth/providers/custom.js\";\nexport { descopeProvider } from \"./auth/providers/descope.js\";\nexport { stytchProvider } from \"./auth/providers/stytch.js\";\nexport { workosProvider } from \"./auth/providers/workos.js\";\nexport {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n InvalidTokenError,\n mcpAuthMetadataRouter,\n optionalBearerAuth,\n requireBearerAuth,\n} from \"./auth.js\";\nexport {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport { FileRef } from \"./file-ref.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n JsonOptions,\n KnownToolMeta,\n McpServerTypes,\n SecurityScheme,\n SkybridgeServerOptions,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n __setBuildManifest,\n __setSkillsManifest,\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport {\n discoverSkills,\n type Skill,\n type SkillsManifest,\n} from \"./skills.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
@@ -7,6 +7,7 @@ import type { ContentBlock, Implementation, RequestMeta, ServerNotification, Ser
7
7
  import express, { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
8
8
  import type { OAuthConfig } from "./auth/index.js";
9
9
  import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
10
+ import { type SkillsManifest } from "./skills.js";
10
11
  /**
11
12
  * Type marker for a registered tool — carries its input, output, and response
12
13
  * metadata shapes so views can infer types from `typeof server`.
@@ -49,8 +50,16 @@ export interface ViewCsp {
49
50
  */
50
51
  export interface ViewNameRegistry {
51
52
  }
53
+ /**
54
+ * Resolve view component names from a registry: the union of its keys, or
55
+ * `string` when the registry is empty. The empty case happens before
56
+ * `.skybridge/views.d.ts` is generated; falling back to `string` keeps valid
57
+ * view names from erroring on a fresh checkout, and narrowing kicks in once
58
+ * the generated file augments the registry.
59
+ */
60
+ export type ViewNameFor<Registry> = [keyof Registry & string] extends [never] ? string : keyof Registry & string;
52
61
  /** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
53
- export type ViewName = keyof ViewNameRegistry & string;
62
+ export type ViewName = ViewNameFor<ViewNameRegistry>;
54
63
  /**
55
64
  * Pass under `view` in a tool's `registerTool` config to render the tool's
56
65
  * result through a Skybridge view instead of a plain text response.
@@ -80,6 +89,20 @@ export type SecurityScheme = {
80
89
  type: "oauth2";
81
90
  scopes?: string[];
82
91
  };
92
+ /**
93
+ * Declarative per-tool auth. Enforced when the server has an `oauth` provider:
94
+ * anonymous or under-scoped calls are rejected before the handler runs. Omit
95
+ * `auth` entirely for the secure default (sign-in required, no specific scope).
96
+ */
97
+ export type ToolAuth = {
98
+ /**
99
+ * When `true`, the tool is callable signed out; the token is still used when
100
+ * one is present. Omit (or `false`) to require sign-in.
101
+ */
102
+ allowsAnonymous?: boolean;
103
+ /** OAuth scopes the caller's token must carry to invoke the tool. */
104
+ scopes?: string[];
105
+ };
83
106
  /**
84
107
  * Options forwarded to the built-in `express.json()` body parser. Derived
85
108
  * from Express's own types so the public API doesn't depend on `body-parser`.
@@ -91,6 +114,11 @@ export interface SkybridgeServerOptions {
91
114
  json?: JsonOptions;
92
115
  /** Resource-server OAuth config. When set, mounts well-known metadata and bearer auth on `/mcp`. */
93
116
  oauth?: OAuthConfig;
117
+ /**
118
+ * @experimental Serve Agent Skills from `src/skills` over MCP (SEP-2640).
119
+ * API may change.
120
+ */
121
+ skills?: boolean;
94
122
  }
95
123
  /**
96
124
  * Well-known keys recognized by host runtimes when set on a tool's `_meta`.
@@ -153,7 +181,7 @@ type ExtractMeta<T> = [Extract<T, {
153
181
  type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
154
182
  [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
155
183
  }>;
156
- interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
184
+ interface ToolConfigBase<TInput extends ZodRawShapeCompat | AnySchema> {
157
185
  name: string;
158
186
  title?: string;
159
187
  description?: string;
@@ -161,6 +189,17 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
161
189
  outputSchema?: ZodRawShapeCompat | AnySchema;
162
190
  annotations?: ToolAnnotations;
163
191
  view?: ViewConfig;
192
+ _meta?: ToolMeta;
193
+ }
194
+ /**
195
+ * The auth face of a tool config: either the high-level `auth` shorthand or the
196
+ * low-level `securitySchemes` escape hatch, never both.
197
+ */
198
+ type ToolAuthConfig = {
199
+ auth?: ToolAuth;
200
+ securitySchemes?: never;
201
+ } | {
202
+ auth?: never;
164
203
  /**
165
204
  * Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
166
205
  * Lets clients label tools that require sign-in before calling, and pass
@@ -169,8 +208,8 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
169
208
  * enhanced behavior to authenticated ones.
170
209
  */
171
210
  securitySchemes?: SecurityScheme[];
172
- _meta?: ToolMeta;
173
- }
211
+ };
212
+ type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = ToolConfigBase<TInput> & ToolAuthConfig;
174
213
  /**
175
214
  * Optional client-supplied hints attached to `params._meta` on every tool call
176
215
  * by the Apps SDK host. Hints only: never use for authorization, and tolerate
@@ -228,6 +267,7 @@ declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof M
228
267
  export declare function __setBuildManifest(manifest: Record<string, {
229
268
  file: string;
230
269
  }>): void;
270
+ export declare function __setSkillsManifest(manifest: SkillsManifest): void;
231
271
  export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
232
272
  readonly $types: McpServerTypes<TTools>;
233
273
  /**
@@ -260,7 +300,11 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
260
300
  private viteManifest;
261
301
  private readonly serverInfo;
262
302
  private readonly serverOptions?;
303
+ private oauthEnabled;
304
+ private resolveResourceMetadataUrl?;
305
+ private securitySchemesByTool;
263
306
  constructor(serverInfo: Implementation, options?: ServerOptions, skybridgeOptions?: SkybridgeServerOptions);
307
+ private setupSkills;
264
308
  /**
265
309
  * Register Express middleware on the underlying app. Mirrors `app.use` —
266
310
  * pass handlers directly or a path-prefixed handler list. Register before
@@ -358,7 +402,7 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
358
402
  private registerViewResources;
359
403
  private registerViewResource;
360
404
  private serveLegacyAppsSdkUrl;
361
- private wrapHandler;
405
+ private decorateToolHandler;
362
406
  private computeViewVersionParam;
363
407
  private lookupViewFile;
364
408
  private lookupDistFile;
@@ -6,11 +6,14 @@ import { Server as SdkServer, } from "@modelcontextprotocol/sdk/server/index.js"
6
6
  import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
7
7
  import { mergeWith, union } from "es-toolkit";
8
8
  import express, {} from "express";
9
+ import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
9
10
  import { setupOAuth } from "./auth/setup.js";
10
11
  import { createApp } from "./express.js";
12
+ import { hostFromUserAgent } from "./host.js";
11
13
  import { createMiddlewareEntry } from "./metric.js";
12
14
  import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
13
15
  import { resolveServerOrigin } from "./requestOrigin.js";
16
+ import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
14
17
  import { templateHelper } from "./templateHelper.js";
15
18
  const mergeWithUnion = (target, source) => {
16
19
  return mergeWith(target, source, (targetVal, sourceVal) => {
@@ -19,6 +22,20 @@ const mergeWithUnion = (target, source) => {
19
22
  }
20
23
  });
21
24
  };
25
+ const SKILLS_DIR = "src/skills";
26
+ /**
27
+ * Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
28
+ * path. Takes the first hop of a comma-separated proxy chain.
29
+ * "/v1/", "v1", "/v1, /internal" → "/v1"; "", "/", undefined → "".
30
+ */
31
+ function normalizeForwardedPrefix(raw) {
32
+ const firstHop = raw?.split(",")[0]?.trim() ?? "";
33
+ const trimmed = firstHop.replace(/\/+$/, "");
34
+ if (trimmed === "") {
35
+ return "";
36
+ }
37
+ return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
38
+ }
22
39
  /**
23
40
  * Drop the query string from a `ui://` view URI, leaving the bare path. The
24
41
  * `?v=` cache key is the only query we append, so a plain split is enough and
@@ -92,6 +109,47 @@ let pendingBuildManifest = null;
92
109
  export function __setBuildManifest(manifest) {
93
110
  pendingBuildManifest = manifest;
94
111
  }
112
+ let pendingSkillsManifest = null;
113
+ export function __setSkillsManifest(manifest) {
114
+ pendingSkillsManifest = manifest;
115
+ }
116
+ // Pure and `this`-free so it can run inside the `super(...)` call, before `this`
117
+ // exists — the capability must be present for the `initialize` response.
118
+ function withSkillsCapability(options, skybridgeOptions) {
119
+ if (!skybridgeOptions?.skills) {
120
+ return options;
121
+ }
122
+ return {
123
+ ...options,
124
+ capabilities: {
125
+ ...options?.capabilities,
126
+ extensions: {
127
+ ...options?.capabilities?.extensions,
128
+ [SKILLS_EXTENSION_KEY]: { directoryRead: true },
129
+ },
130
+ },
131
+ };
132
+ }
133
+ // Collapses registerTool's two overloads into a single { config, cb } shape.
134
+ // registerTool("greet", { description }, handler)
135
+ // -> { config: { name: "greet", description }, cb: handler }
136
+ // registerTool({ name: "greet", description }, handler)
137
+ // -> { config: { name: "greet", description }, cb: handler }
138
+ function normalizeRegisterToolArgs(args) {
139
+ if (typeof args[0] === "string") {
140
+ return {
141
+ config: {
142
+ name: args[0],
143
+ ...args[1],
144
+ },
145
+ cb: args[2],
146
+ };
147
+ }
148
+ return {
149
+ config: args[0],
150
+ cb: args[1],
151
+ };
152
+ }
95
153
  export class McpServer extends McpServerBaseOmitted {
96
154
  /**
97
155
  * The underlying Express app. Use this to extend the HTTP server with
@@ -123,14 +181,19 @@ export class McpServer extends McpServerBaseOmitted {
123
181
  viteManifest = null;
124
182
  serverInfo;
125
183
  serverOptions;
184
+ oauthEnabled = false;
185
+ resolveResourceMetadataUrl;
186
+ securitySchemesByTool = new Map();
126
187
  constructor(serverInfo, options, skybridgeOptions) {
127
- super(serverInfo, options);
188
+ const mergedOptions = withSkillsCapability(options, skybridgeOptions);
189
+ super(serverInfo, mergedOptions);
128
190
  this.serverInfo = serverInfo;
129
- this.serverOptions = options;
191
+ this.serverOptions = mergedOptions;
130
192
  this.express = express();
131
193
  this.express.use(express.json(skybridgeOptions?.json));
132
194
  if (skybridgeOptions?.oauth) {
133
- setupOAuth(this.express, skybridgeOptions.oauth);
195
+ this.oauthEnabled = true;
196
+ this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
134
197
  }
135
198
  // Pick up the manifest if `dist/__entry.js` primed it before importing
136
199
  // user code. Consume-once: clear after the first construction so a
@@ -141,6 +204,19 @@ export class McpServer extends McpServerBaseOmitted {
141
204
  this.setViteManifest(pendingBuildManifest);
142
205
  pendingBuildManifest = null;
143
206
  }
207
+ this.setupSkills(Boolean(skybridgeOptions?.skills));
208
+ }
209
+ setupSkills(enabled) {
210
+ const manifest = pendingSkillsManifest;
211
+ pendingSkillsManifest = null;
212
+ if (!enabled) {
213
+ return;
214
+ }
215
+ const skills = manifest ?? discoverSkills(SKILLS_DIR);
216
+ if (skills.length === 0) {
217
+ console.warn(`skybridge: the "skills" option is enabled but no skills were found in "${SKILLS_DIR}". Add a <name>/SKILL.md there, or remove the option.`);
218
+ }
219
+ registerSkills(this, skills);
144
220
  }
145
221
  use(pathOrHandler, ...handlers) {
146
222
  // Branching is load-bearing: Express's `app.use` overloads can't be
@@ -249,16 +325,33 @@ export class McpServer extends McpServerBaseOmitted {
249
325
  }
250
326
  },
251
327
  };
328
+ // ChatGPT reads `securitySchemes` at the tool descriptor top level (SEP-1488,
329
+ // still Draft), but the SDK's registerTool strips unknown top-level fields, so
330
+ // it's stashed in `_meta` at registration. This restores it to the top level
331
+ // on tools/list output. Remove once SEP-1488 lands and the SDK preserves it.
332
+ // { name: "checkout", _meta: { securitySchemes: [{ type: "oauth2" }] } }
333
+ // -> { name: "checkout", _meta: {…}, securitySchemes: [{ type: "oauth2" }] }
334
+ const toolsListSecuritySchemesEntry = {
335
+ filter: "tools/list",
336
+ handler: async (_req, _extra, next) => {
337
+ const result = (await next());
338
+ for (const tool of result.tools) {
339
+ const schemes = tool._meta?.securitySchemes;
340
+ if (schemes && !("securitySchemes" in tool)) {
341
+ tool.securitySchemes = schemes;
342
+ }
343
+ }
344
+ return result;
345
+ },
346
+ };
252
347
  const monitoringEntry = createMiddlewareEntry();
253
348
  const entries = [
254
349
  ...(monitoringEntry ? [monitoringEntry] : []),
255
350
  viewListMetaEntry,
256
351
  viewReadResolveEntry,
352
+ toolsListSecuritySchemesEntry,
257
353
  ...this.mcpMiddlewareEntries,
258
354
  ];
259
- if (entries.length === 0) {
260
- return;
261
- }
262
355
  const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
263
356
  const instrumentMap = (map, isNotification) => {
264
357
  for (const [method, handler] of map) {
@@ -381,8 +474,13 @@ export class McpServer extends McpServerBaseOmitted {
381
474
  const val = headers[key];
382
475
  return Array.isArray(val) ? val[0] : val;
383
476
  };
384
- const isClaude = header("user-agent") === "Claude-User";
477
+ const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
385
478
  const serverUrl = resolveServerOrigin(header);
479
+ // Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
480
+ // per-request so one process can serve many hosts/prefixes at once: the
481
+ // origin is recovered from x-forwarded-host, the prefix from
482
+ // x-forwarded-prefix. Empty when served at the origin root.
483
+ const assetsBasePath = normalizeForwardedPrefix(header("x-forwarded-prefix"));
386
484
  const connectDomains = [serverUrl];
387
485
  if (!isProduction) {
388
486
  const wsUrl = new URL(serverUrl);
@@ -403,7 +501,7 @@ export class McpServer extends McpServerBaseOmitted {
403
501
  .slice(0, 32);
404
502
  contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
405
503
  }
406
- return { serverUrl, connectDomains, contentMetaOverrides };
504
+ return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
407
505
  }
408
506
  registerViewResources(toolName, view, toolMeta) {
409
507
  // Append a content-derived version param so hosts (e.g. ChatGPT) bust
@@ -491,17 +589,21 @@ export class McpServer extends McpServerBaseOmitted {
491
589
  this.serveLegacyAppsSdkUrl(view.component, viewUri);
492
590
  this.registerResource(name, viewUri, { description: view.description }, async (uri, extra) => {
493
591
  const isProduction = process.env.NODE_ENV === "production";
494
- const { serverUrl } = this.resolveViewRequestContext(extra);
592
+ const { serverUrl, assetsBasePath } = this.resolveViewRequestContext(extra);
593
+ // The view resolves all assets (template imports + runtime lazy chunks
594
+ // via `window.skybridge.serverUrl`) against this base, so it carries the
595
+ // proxy path prefix. CSP domains in `buildMeta` stay the bare origin.
596
+ const viewBase = `${serverUrl}${assetsBasePath}`;
495
597
  const html = isProduction
496
598
  ? templateHelper.renderProduction({
497
599
  hostType,
498
- serverUrl,
600
+ serverUrl: viewBase,
499
601
  viewFile: this.lookupViewFile(view.component),
500
602
  styleFile: this.lookupDistFile("style.css") ?? "",
501
603
  })
502
604
  : templateHelper.renderDevelopment({
503
605
  hostType,
504
- serverUrl,
606
+ serverUrl: viewBase,
505
607
  viewName: view.component,
506
608
  });
507
609
  return {
@@ -513,9 +615,22 @@ export class McpServer extends McpServerBaseOmitted {
513
615
  }
514
616
  serveLegacyAppsSdkUrl(component, canonicalUri) {
515
617
  this.viewUriByPath.set(`ui://views/apps-sdk/${component}.html`, canonicalUri);
618
+ this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
619
+ this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
516
620
  }
517
- wrapHandler(cb, { attachViewUUID }) {
621
+ decorateToolHandler(cb, { attachViewUUID, securitySchemes, }) {
518
622
  return async (args, extra) => {
623
+ if (this.oauthEnabled) {
624
+ const failure = evaluateSecuritySchemes(securitySchemes, extra.authInfo);
625
+ if (failure) {
626
+ const headers = extra?.requestInfo?.headers ?? {};
627
+ const header = (key) => {
628
+ const value = headers[key];
629
+ return Array.isArray(value) ? value[0] : value;
630
+ };
631
+ return inBandChallengeResult(failure, this.resolveResourceMetadataUrl?.(header));
632
+ }
633
+ }
519
634
  const result = await cb(args, extra);
520
635
  return {
521
636
  ...result,
@@ -580,14 +695,19 @@ export class McpServer extends McpServerBaseOmitted {
580
695
  }
581
696
  registerTool(...args) {
582
697
  const baseFn = McpServerBase.prototype.registerTool;
583
- if (typeof args[0] === "string") {
584
- baseFn.call(this, args[0], args[1], args[2]);
585
- return this;
698
+ const { config, cb } = normalizeRegisterToolArgs(args);
699
+ const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
700
+ const authNeedsProvider = auth !== undefined &&
701
+ (!auth.allowsAnonymous || Boolean(auth.scopes?.length));
702
+ if (rawSecuritySchemes === undefined &&
703
+ authNeedsProvider &&
704
+ !this.oauthEnabled) {
705
+ throw new Error(`Tool "${name}" sets \`auth: ${JSON.stringify(auth)}\` but the server has no \`oauth\` provider configured.`);
586
706
  }
587
- const config = args[0];
588
- const cb = args[1];
589
- const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
707
+ const securitySchemes = rawSecuritySchemes ??
708
+ (auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
590
709
  const toolMeta = { ...userToolMeta };
710
+ this.securitySchemesByTool.set(name, securitySchemes);
591
711
  if (securitySchemes) {
592
712
  // SEP-1488 puts `securitySchemes` at the top level of the tool
593
713
  // descriptor, but the SDK's `registerTool` drops unknown top-level
@@ -600,7 +720,10 @@ export class McpServer extends McpServerBaseOmitted {
600
720
  this.enforceOneToolPerView(view.component, name);
601
721
  this.registerViewResources(name, view, toolMeta);
602
722
  }
603
- const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
723
+ const wrappedCb = this.decorateToolHandler(cb, {
724
+ attachViewUUID: Boolean(view),
725
+ securitySchemes,
726
+ });
604
727
  baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
605
728
  return this;
606
729
  }