skybridge 1.2.6 → 1.3.0

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 (84) hide show
  1. package/README.md +1 -0
  2. package/dist/cli/build-helpers.d.ts +5 -1
  3. package/dist/cli/build-helpers.js +30 -10
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +58 -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/run-plain.d.ts +18 -0
  15. package/dist/cli/run-plain.js +89 -0
  16. package/dist/cli/run-plain.js.map +1 -0
  17. package/dist/cli/use-nodemon.d.ts +14 -0
  18. package/dist/cli/use-nodemon.js +71 -60
  19. package/dist/cli/use-nodemon.js.map +1 -1
  20. package/dist/cli/use-typescript-check.d.ts +8 -2
  21. package/dist/cli/use-typescript-check.js +70 -67
  22. package/dist/cli/use-typescript-check.js.map +1 -1
  23. package/dist/commands/build.d.ts +0 -2
  24. package/dist/commands/build.js +2 -61
  25. package/dist/commands/build.js.map +1 -1
  26. package/dist/commands/dev.d.ts +1 -0
  27. package/dist/commands/dev.js +32 -0
  28. package/dist/commands/dev.js.map +1 -1
  29. package/dist/server/auth/providers/custom.d.ts +6 -0
  30. package/dist/server/auth/providers/custom.js +7 -4
  31. package/dist/server/auth/providers/custom.js.map +1 -1
  32. package/dist/server/auth/providers/custom.test.js +21 -0
  33. package/dist/server/auth/providers/custom.test.js.map +1 -1
  34. package/dist/server/auth/providers/descope.js +1 -0
  35. package/dist/server/auth/providers/descope.js.map +1 -1
  36. package/dist/server/auth/providers/descope.test.js +1 -0
  37. package/dist/server/auth/providers/descope.test.js.map +1 -1
  38. package/dist/server/auth/security-schemes.d.ts +23 -0
  39. package/dist/server/auth/security-schemes.js +64 -0
  40. package/dist/server/auth/security-schemes.js.map +1 -0
  41. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  42. package/dist/server/auth/security-schemes.test.js +99 -0
  43. package/dist/server/auth/security-schemes.test.js.map +1 -0
  44. package/dist/server/auth/setup.d.ts +3 -1
  45. package/dist/server/auth/setup.js +62 -21
  46. package/dist/server/auth/setup.js.map +1 -1
  47. package/dist/server/auth/setup.test.js +291 -2
  48. package/dist/server/auth/setup.test.js.map +1 -1
  49. package/dist/server/host.d.ts +2 -0
  50. package/dist/server/host.js +11 -0
  51. package/dist/server/host.js.map +1 -0
  52. package/dist/server/host.test.d.ts +1 -0
  53. package/dist/server/host.test.js +13 -0
  54. package/dist/server/host.test.js.map +1 -0
  55. package/dist/server/index.d.ts +2 -1
  56. package/dist/server/index.js +2 -1
  57. package/dist/server/index.js.map +1 -1
  58. package/dist/server/server.d.ts +40 -4
  59. package/dist/server/server.js +114 -15
  60. package/dist/server/server.js.map +1 -1
  61. package/dist/server/skills-integration.test.d.ts +1 -0
  62. package/dist/server/skills-integration.test.js +63 -0
  63. package/dist/server/skills-integration.test.js.map +1 -0
  64. package/dist/server/skills.d.ts +23 -0
  65. package/dist/server/skills.js +178 -0
  66. package/dist/server/skills.js.map +1 -0
  67. package/dist/server/skills.test.d.ts +1 -0
  68. package/dist/server/skills.test.js +210 -0
  69. package/dist/server/skills.test.js.map +1 -0
  70. package/dist/server/viewsDevServer.js +4 -1
  71. package/dist/server/viewsDevServer.js.map +1 -1
  72. package/dist/test/view.test.js +3 -3
  73. package/dist/test/view.test.js.map +1 -1
  74. package/dist/web/bridges/adaptor.js +17 -0
  75. package/dist/web/bridges/adaptor.js.map +1 -1
  76. package/dist/web/bridges/adaptor.test.js +11 -0
  77. package/dist/web/bridges/adaptor.test.js.map +1 -1
  78. package/dist/web/components/modal-provider.d.ts +1 -1
  79. package/dist/web/data-llm.d.ts +1 -1
  80. package/dist/web/data-llm.test.js +8 -0
  81. package/dist/web/data-llm.test.js.map +1 -1
  82. package/dist/web/plugin/plugin.js +0 -1
  83. package/dist/web/plugin/plugin.js.map +1 -1
  84. package/package.json +21 -20
@@ -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"]}
@@ -11,5 +11,6 @@ export { FileRef } from "./file-ref.js";
11
11
  export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
12
12
  export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
13
13
  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";
14
+ export { __setBuildManifest, __setSkillsManifest, McpServer, normalizeContent, } from "./server.js";
15
+ export { discoverSkills, type Skill, type SkillsManifest, } from "./skills.js";
15
16
  export { viewsDevServer } from "./viewsDevServer.js";
@@ -7,6 +7,7 @@ export { workosProvider } from "./auth/providers/workos.js";
7
7
  export { InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
8
8
  export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
9
9
  export { FileRef } from "./file-ref.js";
10
- export { __setBuildManifest, McpServer, normalizeContent, } from "./server.js";
10
+ export { __setBuildManifest, __setSkillsManifest, McpServer, normalizeContent, } from "./server.js";
11
+ export { discoverSkills, } from "./skills.js";
11
12
  export { viewsDevServer } from "./viewsDevServer.js";
12
13
  //# 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,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 { 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`.
@@ -88,6 +89,20 @@ export type SecurityScheme = {
88
89
  type: "oauth2";
89
90
  scopes?: string[];
90
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
+ };
91
106
  /**
92
107
  * Options forwarded to the built-in `express.json()` body parser. Derived
93
108
  * from Express's own types so the public API doesn't depend on `body-parser`.
@@ -99,6 +114,11 @@ export interface SkybridgeServerOptions {
99
114
  json?: JsonOptions;
100
115
  /** Resource-server OAuth config. When set, mounts well-known metadata and bearer auth on `/mcp`. */
101
116
  oauth?: OAuthConfig;
117
+ /**
118
+ * @experimental Serve Agent Skills from `src/skills` over MCP (SEP-2640).
119
+ * API may change.
120
+ */
121
+ skills?: boolean;
102
122
  }
103
123
  /**
104
124
  * Well-known keys recognized by host runtimes when set on a tool's `_meta`.
@@ -161,7 +181,7 @@ type ExtractMeta<T> = [Extract<T, {
161
181
  type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
162
182
  [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
163
183
  }>;
164
- interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
184
+ interface ToolConfigBase<TInput extends ZodRawShapeCompat | AnySchema> {
165
185
  name: string;
166
186
  title?: string;
167
187
  description?: string;
@@ -169,6 +189,17 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
169
189
  outputSchema?: ZodRawShapeCompat | AnySchema;
170
190
  annotations?: ToolAnnotations;
171
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;
172
203
  /**
173
204
  * Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
174
205
  * Lets clients label tools that require sign-in before calling, and pass
@@ -177,8 +208,8 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
177
208
  * enhanced behavior to authenticated ones.
178
209
  */
179
210
  securitySchemes?: SecurityScheme[];
180
- _meta?: ToolMeta;
181
- }
211
+ };
212
+ type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = ToolConfigBase<TInput> & ToolAuthConfig;
182
213
  /**
183
214
  * Optional client-supplied hints attached to `params._meta` on every tool call
184
215
  * by the Apps SDK host. Hints only: never use for authorization, and tolerate
@@ -236,6 +267,7 @@ declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof M
236
267
  export declare function __setBuildManifest(manifest: Record<string, {
237
268
  file: string;
238
269
  }>): void;
270
+ export declare function __setSkillsManifest(manifest: SkillsManifest): void;
239
271
  export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
240
272
  readonly $types: McpServerTypes<TTools>;
241
273
  /**
@@ -268,7 +300,11 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
268
300
  private viteManifest;
269
301
  private readonly serverInfo;
270
302
  private readonly serverOptions?;
303
+ private oauthEnabled;
304
+ private resolveResourceMetadataUrl?;
305
+ private securitySchemesByTool;
271
306
  constructor(serverInfo: Implementation, options?: ServerOptions, skybridgeOptions?: SkybridgeServerOptions);
307
+ private setupSkills;
272
308
  /**
273
309
  * Register Express middleware on the underlying app. Mirrors `app.use` —
274
310
  * pass handlers directly or a path-prefixed handler list. Register before
@@ -366,7 +402,7 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
366
402
  private registerViewResources;
367
403
  private registerViewResource;
368
404
  private serveLegacyAppsSdkUrl;
369
- private wrapHandler;
405
+ private decorateToolHandler;
370
406
  private computeViewVersionParam;
371
407
  private lookupViewFile;
372
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,7 @@ const mergeWithUnion = (target, source) => {
19
22
  }
20
23
  });
21
24
  };
25
+ const SKILLS_DIR = "src/skills";
22
26
  /**
23
27
  * Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
24
28
  * path. Takes the first hop of a comma-separated proxy chain.
@@ -105,6 +109,47 @@ let pendingBuildManifest = null;
105
109
  export function __setBuildManifest(manifest) {
106
110
  pendingBuildManifest = manifest;
107
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
+ }
108
153
  export class McpServer extends McpServerBaseOmitted {
109
154
  /**
110
155
  * The underlying Express app. Use this to extend the HTTP server with
@@ -136,14 +181,19 @@ export class McpServer extends McpServerBaseOmitted {
136
181
  viteManifest = null;
137
182
  serverInfo;
138
183
  serverOptions;
184
+ oauthEnabled = false;
185
+ resolveResourceMetadataUrl;
186
+ securitySchemesByTool = new Map();
139
187
  constructor(serverInfo, options, skybridgeOptions) {
140
- super(serverInfo, options);
188
+ const mergedOptions = withSkillsCapability(options, skybridgeOptions);
189
+ super(serverInfo, mergedOptions);
141
190
  this.serverInfo = serverInfo;
142
- this.serverOptions = options;
191
+ this.serverOptions = mergedOptions;
143
192
  this.express = express();
144
193
  this.express.use(express.json(skybridgeOptions?.json));
145
194
  if (skybridgeOptions?.oauth) {
146
- setupOAuth(this.express, skybridgeOptions.oauth);
195
+ this.oauthEnabled = true;
196
+ this.resolveResourceMetadataUrl = setupOAuth(this.express, skybridgeOptions.oauth, this.securitySchemesByTool);
147
197
  }
148
198
  // Pick up the manifest if `dist/__entry.js` primed it before importing
149
199
  // user code. Consume-once: clear after the first construction so a
@@ -154,6 +204,19 @@ export class McpServer extends McpServerBaseOmitted {
154
204
  this.setViteManifest(pendingBuildManifest);
155
205
  pendingBuildManifest = null;
156
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);
157
220
  }
158
221
  use(pathOrHandler, ...handlers) {
159
222
  // Branching is load-bearing: Express's `app.use` overloads can't be
@@ -262,16 +325,33 @@ export class McpServer extends McpServerBaseOmitted {
262
325
  }
263
326
  },
264
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
+ };
265
347
  const monitoringEntry = createMiddlewareEntry();
266
348
  const entries = [
267
349
  ...(monitoringEntry ? [monitoringEntry] : []),
268
350
  viewListMetaEntry,
269
351
  viewReadResolveEntry,
352
+ toolsListSecuritySchemesEntry,
270
353
  ...this.mcpMiddlewareEntries,
271
354
  ];
272
- if (entries.length === 0) {
273
- return;
274
- }
275
355
  const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
276
356
  const instrumentMap = (map, isNotification) => {
277
357
  for (const [method, handler] of map) {
@@ -394,7 +474,7 @@ export class McpServer extends McpServerBaseOmitted {
394
474
  const val = headers[key];
395
475
  return Array.isArray(val) ? val[0] : val;
396
476
  };
397
- const isClaude = header("user-agent") === "Claude-User";
477
+ const isClaude = hostFromUserAgent(header("user-agent")) === "claude";
398
478
  const serverUrl = resolveServerOrigin(header);
399
479
  // Path prefix the proxy routed this request under (e.g. `foo.com/v1`). Read
400
480
  // per-request so one process can serve many hosts/prefixes at once: the
@@ -538,8 +618,19 @@ export class McpServer extends McpServerBaseOmitted {
538
618
  this.viewUriByPath.set(`ui://widgets/apps-sdk/${component}.html`, canonicalUri);
539
619
  this.viewUriByPath.set(`ui://widgets/ext-apps/${component}.html`, canonicalUri);
540
620
  }
541
- wrapHandler(cb, { attachViewUUID }) {
621
+ decorateToolHandler(cb, { attachViewUUID, securitySchemes, }) {
542
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
+ }
543
634
  const result = await cb(args, extra);
544
635
  return {
545
636
  ...result,
@@ -604,14 +695,19 @@ export class McpServer extends McpServerBaseOmitted {
604
695
  }
605
696
  registerTool(...args) {
606
697
  const baseFn = McpServerBase.prototype.registerTool;
607
- if (typeof args[0] === "string") {
608
- baseFn.call(this, args[0], args[1], args[2]);
609
- 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.`);
610
706
  }
611
- const config = args[0];
612
- const cb = args[1];
613
- const { name, view, securitySchemes, _meta: userToolMeta, ...toolFields } = config;
707
+ const securitySchemes = rawSecuritySchemes ??
708
+ (auth && this.oauthEnabled ? authToSecuritySchemes(auth) : undefined);
614
709
  const toolMeta = { ...userToolMeta };
710
+ this.securitySchemesByTool.set(name, securitySchemes);
615
711
  if (securitySchemes) {
616
712
  // SEP-1488 puts `securitySchemes` at the top level of the tool
617
713
  // descriptor, but the SDK's `registerTool` drops unknown top-level
@@ -624,7 +720,10 @@ export class McpServer extends McpServerBaseOmitted {
624
720
  this.enforceOneToolPerView(view.component, name);
625
721
  this.registerViewResources(name, view, toolMeta);
626
722
  }
627
- const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) });
723
+ const wrappedCb = this.decorateToolHandler(cb, {
724
+ attachViewUUID: Boolean(view),
725
+ securitySchemes,
726
+ });
628
727
  baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb);
629
728
  return this;
630
729
  }