skybridge 0.0.0-dev.a05e8da → 0.0.0-dev.a08278b

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 (95) hide show
  1. package/README.md +14 -14
  2. package/dist/cli/run-plain.js +2 -1
  3. package/dist/cli/run-plain.js.map +1 -1
  4. package/dist/cli/telemetry.js +2 -0
  5. package/dist/cli/telemetry.js.map +1 -1
  6. package/dist/cli/use-nodemon.d.ts +11 -1
  7. package/dist/cli/use-nodemon.js +19 -5
  8. package/dist/cli/use-nodemon.js.map +1 -1
  9. package/dist/commands/dev.js +3 -3
  10. package/dist/commands/dev.js.map +1 -1
  11. package/dist/server/auth/providers/custom.d.ts +5 -3
  12. package/dist/server/auth/providers/custom.js +1 -1
  13. package/dist/server/auth/providers/custom.js.map +1 -1
  14. package/dist/server/auth/providers/workos.d.ts +3 -2
  15. package/dist/server/auth/providers/workos.js +2 -1
  16. package/dist/server/auth/providers/workos.js.map +1 -1
  17. package/dist/server/auth/verify.d.ts +5 -3
  18. package/dist/server/auth/verify.js.map +1 -1
  19. package/dist/server/auth/verify.test.js +16 -0
  20. package/dist/server/auth/verify.test.js.map +1 -1
  21. package/dist/server/auth.d.ts +3 -3
  22. package/dist/server/auth.js +1 -1
  23. package/dist/server/auth.js.map +1 -1
  24. package/dist/server/events.d.ts +113 -0
  25. package/dist/server/events.js +318 -0
  26. package/dist/server/events.js.map +1 -0
  27. package/dist/server/events.test.d.ts +1 -0
  28. package/dist/server/events.test.js +172 -0
  29. package/dist/server/events.test.js.map +1 -0
  30. package/dist/server/index.d.ts +3 -2
  31. package/dist/server/index.js +2 -1
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/server/register-tool.test.js +83 -0
  34. package/dist/server/register-tool.test.js.map +1 -1
  35. package/dist/server/server.d.ts +153 -9
  36. package/dist/server/server.js +121 -8
  37. package/dist/server/server.js.map +1 -1
  38. package/dist/web/bridges/adaptor.d.ts +8 -3
  39. package/dist/web/bridges/adaptor.js +83 -13
  40. package/dist/web/bridges/adaptor.js.map +1 -1
  41. package/dist/web/bridges/adaptor.test.js +45 -6
  42. package/dist/web/bridges/adaptor.test.js.map +1 -1
  43. package/dist/web/bridges/apps-sdk/bridge.js +1 -1
  44. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  45. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +3 -3
  46. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +3 -3
  47. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  48. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -1
  49. package/dist/web/bridges/mcp-app/bridge.js +9 -2
  50. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  51. package/dist/web/bridges/mcp-app/types.d.ts +18 -3
  52. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  53. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +2 -2
  54. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  55. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  56. package/dist/web/bridges/types.d.ts +30 -4
  57. package/dist/web/bridges/types.js +1 -1
  58. package/dist/web/bridges/types.js.map +1 -1
  59. package/dist/web/data-llm.js +3 -2
  60. package/dist/web/data-llm.js.map +1 -1
  61. package/dist/web/data-llm.test.js +6 -0
  62. package/dist/web/data-llm.test.js.map +1 -1
  63. package/dist/web/generate-helpers.d.ts +2 -2
  64. package/dist/web/generate-helpers.js +2 -2
  65. package/dist/web/generate-helpers.js.map +1 -1
  66. package/dist/web/hooks/index.d.ts +4 -1
  67. package/dist/web/hooks/index.js +4 -1
  68. package/dist/web/hooks/index.js.map +1 -1
  69. package/dist/web/hooks/openai-extensions.test.d.ts +1 -0
  70. package/dist/web/hooks/openai-extensions.test.js +107 -0
  71. package/dist/web/hooks/openai-extensions.test.js.map +1 -0
  72. package/dist/web/hooks/use-call-tool.d.ts +2 -2
  73. package/dist/web/hooks/use-call-tool.js +15 -10
  74. package/dist/web/hooks/use-call-tool.js.map +1 -1
  75. package/dist/web/hooks/use-call-tool.test.js +13 -2
  76. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  77. package/dist/web/hooks/use-deep-link.d.ts +22 -0
  78. package/dist/web/hooks/use-deep-link.js +34 -0
  79. package/dist/web/hooks/use-deep-link.js.map +1 -0
  80. package/dist/web/hooks/use-host.d.ts +27 -5
  81. package/dist/web/hooks/use-host.js +20 -5
  82. package/dist/web/hooks/use-host.js.map +1 -1
  83. package/dist/web/hooks/use-model-context.d.ts +44 -0
  84. package/dist/web/hooks/use-model-context.js +63 -0
  85. package/dist/web/hooks/use-model-context.js.map +1 -0
  86. package/dist/web/hooks/use-open-file.d.ts +20 -0
  87. package/dist/web/hooks/use-open-file.js +25 -0
  88. package/dist/web/hooks/use-open-file.js.map +1 -0
  89. package/dist/web/hooks/use-register-view-tool.d.ts +1 -1
  90. package/dist/web/hooks/use-register-view-tool.js +1 -1
  91. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  92. package/dist/web/hooks/use-send-follow-up-message.d.ts +8 -2
  93. package/dist/web/hooks/use-send-follow-up-message.js +6 -0
  94. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  95. package/package.json +8 -6
@@ -1,8 +1,9 @@
1
1
  import type { McpUiToolMeta } from "@modelcontextprotocol/ext-apps";
2
- import { type ContentBlock, type Implementation, McpServer as McpServerBase, type RequestMeta, type ServerOptions, type ServerResult, type StandardSchemaV1, type StandardSchemaWithJSON, type ToolAnnotations } from "@modelcontextprotocol/server";
2
+ import { type ContentBlock, type Icon, type Implementation, McpServer as McpServerBase, type RequestMeta, type ResourceLink, type ServerOptions, type ServerResult, type StandardSchemaV1, type StandardSchemaWithJSON, type ToolAnnotations } from "@modelcontextprotocol/server";
3
3
  import type express from "express";
4
4
  import type { ResourceMetadataUrlResolver } from "./auth/setup.js";
5
5
  import type { ExtraClaims } from "./auth.js";
6
+ import { type EventConfig, type EventHooks, type InferEventSchema } from "./events.js";
6
7
  import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareEntry, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
7
8
  import { type SkillsManifest } from "./skills.js";
8
9
  /**
@@ -27,7 +28,7 @@ export interface ViewCsp {
27
28
  resourceDomains?: string[];
28
29
  /** Origins the view may contact via fetch/XHR. */
29
30
  connectDomains?: string[];
30
- /** Origins allowed for iframe embeds (opts into stricter app review). */
31
+ /** Origins allowed for iframe embeds (opts into stricter plugin review). */
31
32
  frameDomains?: string[];
32
33
  /** Origins that can receive openExternal redirects without the safe-link modal. */
33
34
  redirectDomains?: string[];
@@ -75,6 +76,65 @@ export type SecurityScheme = {
75
76
  type: "oauth2";
76
77
  scopes?: string[];
77
78
  };
79
+ /** A display mode ChatGPT can render a view in. ChatGPT doesn't support `pip`. */
80
+ export type OpenAIDisplayMode = "inline" | "fullscreen";
81
+ /** A sidebar shortcut that calls another tool of the same server. */
82
+ export interface OpenAIQuickAction {
83
+ title: string;
84
+ icons: [Icon, ...Icon[]];
85
+ target: {
86
+ type: "tool";
87
+ name: string;
88
+ arguments?: Record<string, unknown>;
89
+ };
90
+ }
91
+ /**
92
+ * A place in ChatGPT where users can open the tool's view without the model.
93
+ *
94
+ * - `global`: an entry in the sidebar, opened fullscreen.
95
+ * - `thread`: a tab in a conversation's side panel.
96
+ * - `file`: a viewer for files with these extensions, such as `".stl"`.
97
+ * ChatGPT calls the tool with `{ file: { name, resourceUri } }`.
98
+ * - `settings`: an entry in the plugin settings.
99
+ *
100
+ * ChatGPT calls the tool with `{}` for global and thread entrypoints, so the
101
+ * tool must not require any input.
102
+ */
103
+ export type OpenAIEntrypoint = {
104
+ type: "global";
105
+ quickAction?: OpenAIQuickAction;
106
+ } | {
107
+ type: "thread";
108
+ } | {
109
+ type: "file";
110
+ extensions: string[];
111
+ } | {
112
+ type: "settings";
113
+ searchTerms?: string[];
114
+ };
115
+ /**
116
+ * ChatGPT-only tool options, emitted as `_meta["openai/ui"]` on the tool and
117
+ * on its view resource. Every field is optional: ChatGPT applies the defaults
118
+ * of the OpenAI MCP extensions spec when one is omitted. Requires `view`.
119
+ *
120
+ * @see https://github.com/openai/mcp-extensions/blob/main/docs/spec.md
121
+ */
122
+ export interface OpenAIToolConfig {
123
+ /** Places where users can open the view directly. */
124
+ entrypoints?: OpenAIEntrypoint[];
125
+ /**
126
+ * Display modes the view supports, read before the view loads. Defaults to
127
+ * `[preferredDisplayMode]` when that is set, otherwise to both modes.
128
+ */
129
+ availableDisplayModes?: OpenAIDisplayMode[];
130
+ /**
131
+ * Display mode the view prefers to open in. Setting it alone makes it the
132
+ * only available mode, so also set `availableDisplayModes` to keep the other.
133
+ */
134
+ preferredDisplayMode?: OpenAIDisplayMode;
135
+ /** Display mode the view opens in first when the model calls the tool. */
136
+ preferredModelDisplayMode?: OpenAIDisplayMode;
137
+ }
78
138
  /**
79
139
  * Declarative per-tool auth. Enforced when the server has an `oauth` provider:
80
140
  * anonymous or under-scoped calls are rejected before the handler runs. Omit
@@ -112,16 +172,16 @@ export interface SkybridgeServerOptions {
112
172
  * Well-known keys recognized by host runtimes when set on a tool's `_meta`.
113
173
  * Use {@link ToolMeta} to also pass arbitrary custom metadata alongside these.
114
174
  *
115
- * @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters
175
+ * @see https://developers.openai.com/plugins/reference#tool-descriptor-parameters
116
176
  */
117
177
  export interface KnownToolMeta {
118
- /** Apps SDK: allow the rendered view to call this tool from inside its iframe. */
178
+ /** ChatGPT: allow the rendered view to call this tool from inside its iframe. */
119
179
  "openai/widgetAccessible"?: boolean;
120
- /** Apps SDK: status text shown while the tool is running (e.g. `"Searching trips"`). */
180
+ /** ChatGPT: status text shown while the tool is running (e.g. `"Searching trips"`). */
121
181
  "openai/toolInvocation/invoking"?: string;
122
- /** Apps SDK: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
182
+ /** ChatGPT: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
123
183
  "openai/toolInvocation/invoked"?: string;
124
- /** Apps SDK: input parameters that hold file references — the host attaches uploaded files to them. */
184
+ /** ChatGPT: input parameters that hold file references — the host attaches uploaded files to them. */
125
185
  "openai/fileParams"?: string[];
126
186
  /** MCP Apps: control whether the tool is exposed to the model, the app, or both. */
127
187
  ui?: Pick<McpUiToolMeta, "visibility">;
@@ -175,7 +235,15 @@ interface ToolConfigBase<TInput extends Record<string, StandardSchemaWithJSON> |
175
235
  inputSchema?: TInput;
176
236
  outputSchema?: Record<string, StandardSchemaWithJSON> | StandardSchemaWithJSON;
177
237
  annotations?: ToolAnnotations;
238
+ /**
239
+ * Icons for the tool, a standard MCP field. Hosts choose whether and where
240
+ * to show them. ChatGPT asks for them on every entrypoint tool, as a
241
+ * monochrome SVG on a 20x20 viewport that uses `currentColor`.
242
+ */
243
+ icons?: Icon[];
178
244
  view?: ViewConfig;
245
+ /** ChatGPT-only options. See {@link OpenAIToolConfig}. */
246
+ openai?: OpenAIToolConfig;
179
247
  _meta?: ToolMeta;
180
248
  }
181
249
  /**
@@ -199,9 +267,9 @@ type ToolAuthConfig = {
199
267
  type ToolConfig<TInput extends Record<string, StandardSchemaWithJSON> | StandardSchemaWithJSON> = ToolConfigBase<TInput> & ToolAuthConfig;
200
268
  /**
201
269
  * Optional client-supplied hints attached to `params._meta` on every tool call
202
- * by the Apps SDK host. Hints only: never use for authorization, and tolerate
270
+ * by the ChatGPT host. Hints only: never use for authorization, and tolerate
203
271
  * absence.
204
- * @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides
272
+ * @see https://developers.openai.com/plugins/reference#_meta-fields-the-client-provides
205
273
  */
206
274
  export interface ClientHintsMeta {
207
275
  /** Requested locale (BCP-47, e.g. `"en-US"`). */
@@ -225,12 +293,35 @@ export interface ClientHintsMeta {
225
293
  "openai/organization"?: string;
226
294
  /** Stable id for the currently mounted widget instance. */
227
295
  "openai/widgetSessionId"?: string;
296
+ /**
297
+ * Set by ChatGPT desktop on tool calls from a view opened through a file
298
+ * entrypoint. `path` is the absolute path of the opened file. Any MCP client
299
+ * can send this key: never use it for authorization, and resolve the path
300
+ * and keep it inside an allowed directory before touching the filesystem.
301
+ */
302
+ "openai/resource"?: {
303
+ path?: string;
304
+ };
228
305
  }
229
306
  type ToolHandlerExtra<TAuthExtra extends ExtraClaims = ExtraClaims> = Omit<McpExtra<TAuthExtra>, "mcpReq"> & {
230
307
  mcpReq: Omit<McpExtra<TAuthExtra>["mcpReq"], "_meta"> & {
231
308
  _meta?: RequestMeta & ClientHintsMeta;
232
309
  };
233
310
  };
311
+ /** Composer at-mention search, registered with `server.registerMentions`. */
312
+ export interface OpenAIMentionsConfig<TAuthExtra extends ExtraClaims = ExtraClaims> {
313
+ /** Name of the tool ChatGPT calls for each search. */
314
+ name: string;
315
+ description?: string;
316
+ /** Returns the items matching the typed text, which may be empty. */
317
+ handler: (params: {
318
+ query: string;
319
+ }, extra: ToolHandlerExtra<TAuthExtra>) => Promise<{
320
+ items: ResourceLink[];
321
+ }> | {
322
+ items: ResourceLink[];
323
+ };
324
+ }
234
325
  type ToolHandler<TInput extends Record<string, StandardSchemaWithJSON>, TReturn extends {
235
326
  content?: HandlerContent;
236
327
  } = {
@@ -303,6 +394,7 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
303
394
  private resolveResourceMetadataUrl?;
304
395
  private readonly toolSecuritySchemes;
305
396
  private readonly userMiddlewareEntries;
397
+ private eventRegistry?;
306
398
  constructor(serverInfo: Implementation, options?: ServerOptions, skybridgeOptions?: SkybridgeServerOptions);
307
399
  /**
308
400
  * The per-tool security schemes collected during registration, keyed by tool
@@ -379,6 +471,58 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
379
471
  file: string;
380
472
  }>): this;
381
473
  private readManifest;
474
+ /**
475
+ * @experimental Register an MCP Events type that hosts can subscribe to, per
476
+ * the Triggers & Events working group draft. Skybridge serves `events/list`,
477
+ * `events/subscribe` and `events/unsubscribe`, checks auth and arguments,
478
+ * verifies the callback URL, then hands each subscription to `onSubscribe`.
479
+ * Delivering the events is up to you, for example with {@link deliverEvent}.
480
+ * API may change.
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * server.registerEvent(
485
+ * {
486
+ * name: "comment.created",
487
+ * description: "Fires when someone comments on a document",
488
+ * inputSchema: { documentId: z.string() },
489
+ * payloadSchema: { documentId: z.string(), excerpt: z.string() },
490
+ * },
491
+ * {
492
+ * onSubscribe: ({ documentId }, { subscription }) =>
493
+ * webhooks.upsert({ ...subscription, filter: { documentId } }),
494
+ * onUnsubscribe: (_args, { subscription }) =>
495
+ * webhooks.remove(subscription.id),
496
+ * },
497
+ * );
498
+ * ```
499
+ *
500
+ * @see https://docs.skybridge.tech/api-reference/register-event
501
+ */
502
+ registerEvent<TInput extends Record<string, StandardSchemaWithJSON> | StandardSchemaWithJSON = Record<never, StandardSchemaWithJSON>>(config: EventConfig<TInput>, hooks: EventHooks<InferEventSchema<TInput>, McpExtra<TAuthExtra>>): this;
503
+ /**
504
+ * Register the composer at-mention search for ChatGPT, from the OpenAI MCP
505
+ * extensions. When the user types `@` and your app name, ChatGPT calls
506
+ * `handler` with the typed text and lists the returned resource links.
507
+ * Skybridge registers it as a tool hidden from the model.
508
+ *
509
+ * @example
510
+ * ```ts
511
+ * server.registerMentions({
512
+ * name: "search_parts",
513
+ * handler: async ({ query }) => ({
514
+ * items: findParts(query).map((part) => ({
515
+ * type: "resource_link",
516
+ * uri: `parts://${part.id}`,
517
+ * name: part.name,
518
+ * })),
519
+ * }),
520
+ * });
521
+ * ```
522
+ *
523
+ * @see https://docs.skybridge.tech/api-reference/register-mentions
524
+ */
525
+ registerMentions(config: OpenAIMentionsConfig<TAuthExtra>): this;
382
526
  /**
383
527
  * Register a tool. Pass a `config` describing the tool (name, schemas,
384
528
  * optional {@link ViewConfig}, optional {@link ToolMeta}) and a handler that
@@ -2,14 +2,31 @@ import crypto from "node:crypto";
2
2
  import { readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { McpServer as McpServerBase, } from "@modelcontextprotocol/server";
5
+ import { z } from "zod/v4";
5
6
  import { warnOnLargeToolOutput } from "../context-warnings.js";
6
7
  import { authToSecuritySchemes, evaluateSecuritySchemes, inBandChallengeResult, } from "./auth/security-schemes.js";
8
+ import { EventRegistry, } from "./events.js";
7
9
  import { hostFromUserAgent } from "./host.js";
8
10
  import { captureToolError } from "./middleware.js";
9
11
  import { resolveServerOrigin } from "./requestOrigin.js";
10
12
  import { discoverSkills, registerSkills, SKILLS_EXTENSION_KEY, } from "./skills.js";
11
13
  import { templateHelper } from "./templateHelper.js";
12
14
  const unionOf = (base, extra) => extra ? [...new Set([...base, ...extra])] : base;
15
+ function mergeOpenAIUi(meta, values) {
16
+ const defined = Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
17
+ if (Object.keys(defined).length > 0) {
18
+ meta["openai/ui"] = { ...meta["openai/ui"], ...defined };
19
+ }
20
+ }
21
+ function acceptsEmptyInput(inputSchema) {
22
+ if (inputSchema === undefined) {
23
+ return true;
24
+ }
25
+ const checks = "~standard" in inputSchema
26
+ ? [inputSchema["~standard"].validate({})]
27
+ : Object.values(inputSchema).map((schema) => schema["~standard"].validate(undefined));
28
+ return checks.every((result) => result instanceof Promise || result.issues === undefined);
29
+ }
13
30
  const SKILLS_DIR = "src/skills";
14
31
  /**
15
32
  * Normalize an `x-forwarded-prefix` value into a leading-slash, no-trailing-slash
@@ -138,6 +155,7 @@ export class McpServer extends McpServerBaseOmitted {
138
155
  resolveResourceMetadataUrl;
139
156
  toolSecuritySchemes = new Map();
140
157
  userMiddlewareEntries = [];
158
+ eventRegistry;
141
159
  constructor(serverInfo, options, skybridgeOptions) {
142
160
  super(serverInfo, withSkillsCapability(options, skybridgeOptions));
143
161
  this.oauthEnabled = Boolean(skybridgeOptions?.oauth);
@@ -331,7 +349,7 @@ export class McpServer extends McpServerBaseOmitted {
331
349
  }
332
350
  return { serverUrl, assetsBasePath, connectDomains, contentMetaOverrides };
333
351
  }
334
- registerViewResources(toolName, view, toolMeta) {
352
+ registerViewResources(toolName, view, toolMeta, openai) {
335
353
  // Append a content-derived version param so hosts (e.g. ChatGPT) bust
336
354
  // their cache when the bundle changes, but keep the URI stable across
337
355
  // `tools/list` calls when the bundle hasn't changed.
@@ -366,10 +384,12 @@ export class McpServer extends McpServerBaseOmitted {
366
384
  "openai/widgetCSP": { redirect_domains: view.csp.redirectDomains },
367
385
  }),
368
386
  };
369
- if (view._meta) {
370
- return { ...base, ...view._meta };
371
- }
372
- return base;
387
+ const meta = { ...base, ...view._meta };
388
+ mergeOpenAIUi(meta, {
389
+ availableDisplayModes: openai?.availableDisplayModes,
390
+ preferredDisplayMode: openai?.preferredDisplayMode,
391
+ });
392
+ return meta;
373
393
  },
374
394
  };
375
395
  this.registerViewResource({ name: toolName, viewResource, view });
@@ -504,11 +524,85 @@ export class McpServer extends McpServerBaseOmitted {
504
524
  cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
505
525
  return cachedDiskManifest ?? {};
506
526
  }
527
+ /**
528
+ * @experimental Register an MCP Events type that hosts can subscribe to, per
529
+ * the Triggers & Events working group draft. Skybridge serves `events/list`,
530
+ * `events/subscribe` and `events/unsubscribe`, checks auth and arguments,
531
+ * verifies the callback URL, then hands each subscription to `onSubscribe`.
532
+ * Delivering the events is up to you, for example with {@link deliverEvent}.
533
+ * API may change.
534
+ *
535
+ * @example
536
+ * ```ts
537
+ * server.registerEvent(
538
+ * {
539
+ * name: "comment.created",
540
+ * description: "Fires when someone comments on a document",
541
+ * inputSchema: { documentId: z.string() },
542
+ * payloadSchema: { documentId: z.string(), excerpt: z.string() },
543
+ * },
544
+ * {
545
+ * onSubscribe: ({ documentId }, { subscription }) =>
546
+ * webhooks.upsert({ ...subscription, filter: { documentId } }),
547
+ * onUnsubscribe: (_args, { subscription }) =>
548
+ * webhooks.remove(subscription.id),
549
+ * },
550
+ * );
551
+ * ```
552
+ *
553
+ * @see https://docs.skybridge.tech/api-reference/register-event
554
+ */
555
+ registerEvent(config, hooks) {
556
+ if (!this.eventRegistry) {
557
+ this.server.registerCapabilities({ events: {} });
558
+ this.eventRegistry = new EventRegistry(this.server);
559
+ }
560
+ this.eventRegistry.add(config, hooks);
561
+ return this;
562
+ }
563
+ /**
564
+ * Register the composer at-mention search for ChatGPT, from the OpenAI MCP
565
+ * extensions. When the user types `@` and your app name, ChatGPT calls
566
+ * `handler` with the typed text and lists the returned resource links.
567
+ * Skybridge registers it as a tool hidden from the model.
568
+ *
569
+ * @example
570
+ * ```ts
571
+ * server.registerMentions({
572
+ * name: "search_parts",
573
+ * handler: async ({ query }) => ({
574
+ * items: findParts(query).map((part) => ({
575
+ * type: "resource_link",
576
+ * uri: `parts://${part.id}`,
577
+ * name: part.name,
578
+ * })),
579
+ * }),
580
+ * });
581
+ * ```
582
+ *
583
+ * @see https://docs.skybridge.tech/api-reference/register-mentions
584
+ */
585
+ registerMentions(config) {
586
+ this.registerTool({
587
+ name: config.name,
588
+ description: config.description ?? "Search items to mention.",
589
+ annotations: { readOnlyHint: true },
590
+ inputSchema: { query: z.string() },
591
+ _meta: {
592
+ "openai/extensions": { "mentions/search": {} },
593
+ ui: { visibility: ["app"] },
594
+ },
595
+ }, async ({ query }, extra) => ({
596
+ content: [],
597
+ structuredContent: await config.handler({ query }, extra),
598
+ }));
599
+ return this;
600
+ }
507
601
  registerTool(rawConfig, rawCb) {
508
602
  const baseFn = McpServerBase.prototype.registerTool;
509
603
  const config = rawConfig;
510
604
  const cb = rawCb;
511
- const { name, view, auth, securitySchemes: rawSecuritySchemes, _meta: userToolMeta, ...toolFields } = config;
605
+ const { name, view, auth, securitySchemes: rawSecuritySchemes, openai, _meta: userToolMeta, ...toolFields } = config;
512
606
  const authNeedsProvider = auth !== undefined &&
513
607
  (!auth.allowsAnonymous || Boolean(auth.scopes?.length));
514
608
  if (rawSecuritySchemes === undefined &&
@@ -525,12 +619,31 @@ export class McpServer extends McpServerBaseOmitted {
525
619
  // descriptor, but the SDK's `registerTool` drops unknown top-level
526
620
  // fields, so the canonical spot isn't reachable without intercepting
527
621
  // `tools/list`. Use the `_meta` back-compat mirror documented in the
528
- // Apps SDK reference until SEP-1488 lands in the spec.
622
+ // ChatGPT plugin reference until SEP-1488 lands in the spec.
529
623
  toolMeta.securitySchemes = securitySchemes;
530
624
  }
625
+ if (openai) {
626
+ if (!view) {
627
+ throw new Error(`skybridge: tool "${name}" sets \`openai\` options but has no \`view\`.`);
628
+ }
629
+ const opensWithoutInput = openai.entrypoints?.some(({ type }) => type === "global" || type === "thread");
630
+ if (opensWithoutInput && !acceptsEmptyInput(toolFields.inputSchema)) {
631
+ throw new Error(`skybridge: tool "${name}" has a global or thread entrypoint, so ChatGPT calls it with \`{}\`, but its input schema rejects \`{}\`. Make every input optional.`);
632
+ }
633
+ const badExtension = openai.entrypoints
634
+ ?.flatMap((entrypoint) => entrypoint.type === "file" ? entrypoint.extensions : [])
635
+ .find((extension) => !extension.startsWith("."));
636
+ if (badExtension !== undefined) {
637
+ throw new Error(`skybridge: tool "${name}" has a file entrypoint extension "${badExtension}" that doesn't start with ".".`);
638
+ }
639
+ mergeOpenAIUi(toolMeta, {
640
+ entrypoints: openai.entrypoints,
641
+ preferredModelDisplayMode: openai.preferredModelDisplayMode,
642
+ });
643
+ }
531
644
  if (view) {
532
645
  this.enforceOneToolPerView(view.component, name);
533
- this.registerViewResources(name, view, toolMeta);
646
+ this.registerViewResources(name, view, toolMeta, openai);
534
647
  }
535
648
  const wrappedCb = this.decorateToolHandler(cb, {
536
649
  attachViewUUID: Boolean(view),