mcp-use 1.0.7 → 1.1.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.
@@ -95,44 +95,91 @@ function buildWidgetUrl(widget, props, config) {
95
95
  return url.toString();
96
96
  }
97
97
  __name(buildWidgetUrl, "buildWidgetUrl");
98
- function createExternalUrlResource(uri, iframeUrl, encoding = "text") {
98
+ function createExternalUrlResource(uri, iframeUrl, encoding = "text", adapters, metadata) {
99
99
  return (0, import_server.createUIResource)({
100
100
  uri,
101
101
  content: { type: "externalUrl", iframeUrl },
102
- encoding
102
+ encoding,
103
+ adapters,
104
+ metadata
103
105
  });
104
106
  }
105
107
  __name(createExternalUrlResource, "createExternalUrlResource");
106
- function createRawHtmlResource(uri, htmlString, encoding = "text") {
108
+ function createRawHtmlResource(uri, htmlString, encoding = "text", adapters, metadata) {
107
109
  return (0, import_server.createUIResource)({
108
110
  uri,
109
111
  content: { type: "rawHtml", htmlString },
110
- encoding
112
+ encoding,
113
+ adapters,
114
+ metadata
111
115
  });
112
116
  }
113
117
  __name(createRawHtmlResource, "createRawHtmlResource");
114
- function createRemoteDomResource(uri, script, framework = "react", encoding = "text") {
118
+ function createRemoteDomResource(uri, script, framework = "react", encoding = "text", adapters, metadata) {
115
119
  return (0, import_server.createUIResource)({
116
120
  uri,
117
121
  content: { type: "remoteDom", script, framework },
118
- encoding
122
+ encoding,
123
+ adapters,
124
+ metadata
119
125
  });
120
126
  }
121
127
  __name(createRemoteDomResource, "createRemoteDomResource");
128
+ function createAppsSdkResource(uri, htmlTemplate, metadata) {
129
+ const resource = {
130
+ uri,
131
+ mimeType: "text/html+skybridge",
132
+ text: htmlTemplate
133
+ };
134
+ if (metadata && Object.keys(metadata).length > 0) {
135
+ resource._meta = metadata;
136
+ }
137
+ return {
138
+ type: "resource",
139
+ resource
140
+ };
141
+ }
142
+ __name(createAppsSdkResource, "createAppsSdkResource");
122
143
  function createUIResourceFromDefinition(definition, params, config) {
123
- const uri = `ui://widget/${definition.name}`;
144
+ const uri = definition.type === "appsSdk" ? `ui://widget/${definition.name}.html` : `ui://widget/${definition.name}`;
124
145
  const encoding = definition.encoding || "text";
125
146
  switch (definition.type) {
126
147
  case "externalUrl": {
127
148
  const widgetUrl = buildWidgetUrl(definition.widget, params, config);
128
- return createExternalUrlResource(uri, widgetUrl, encoding);
149
+ return createExternalUrlResource(
150
+ uri,
151
+ widgetUrl,
152
+ encoding,
153
+ definition.adapters,
154
+ definition.appsSdkMetadata
155
+ );
129
156
  }
130
157
  case "rawHtml": {
131
- return createRawHtmlResource(uri, definition.htmlContent, encoding);
158
+ return createRawHtmlResource(
159
+ uri,
160
+ definition.htmlContent,
161
+ encoding,
162
+ definition.adapters,
163
+ definition.appsSdkMetadata
164
+ );
132
165
  }
133
166
  case "remoteDom": {
134
167
  const framework = definition.framework || "react";
135
- return createRemoteDomResource(uri, definition.script, framework, encoding);
168
+ return createRemoteDomResource(
169
+ uri,
170
+ definition.script,
171
+ framework,
172
+ encoding,
173
+ definition.adapters,
174
+ definition.appsSdkMetadata
175
+ );
176
+ }
177
+ case "appsSdk": {
178
+ return createAppsSdkResource(
179
+ uri,
180
+ definition.htmlTemplate,
181
+ definition.appsSdkMetadata
182
+ );
136
183
  }
137
184
  default: {
138
185
  const _exhaustive = definition;
@@ -203,7 +250,7 @@ var McpServer = class {
203
250
  * @param resourceDefinition.description - Optional description of the resource
204
251
  * @param resourceDefinition.mimeType - MIME type of the resource content
205
252
  * @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
206
- * @param resourceDefinition.fn - Async function that returns the resource content
253
+ * @param resourceDefinition.readCallback - Async callback function that returns the resource content
207
254
  * @returns The server instance for method chaining
208
255
  *
209
256
  * @example
@@ -218,7 +265,7 @@ var McpServer = class {
218
265
  * audience: ['user'],
219
266
  * priority: 0.8
220
267
  * },
221
- * fn: async () => ({
268
+ * readCallback: async () => ({
222
269
  * contents: [{
223
270
  * uri: 'config://app-settings',
224
271
  * mimeType: 'application/json',
@@ -229,7 +276,7 @@ var McpServer = class {
229
276
  * ```
230
277
  */
231
278
  resource(resourceDefinition) {
232
- this.server.resource(
279
+ this.server.registerResource(
233
280
  resourceDefinition.name,
234
281
  resourceDefinition.uri,
235
282
  {
@@ -240,7 +287,7 @@ var McpServer = class {
240
287
  annotations: resourceDefinition.annotations
241
288
  },
242
289
  async () => {
243
- return await resourceDefinition.fn();
290
+ return await resourceDefinition.readCallback();
244
291
  }
245
292
  );
246
293
  return this;
@@ -255,7 +302,7 @@ var McpServer = class {
255
302
  * @param resourceTemplateDefinition - Configuration object for the resource template
256
303
  * @param resourceTemplateDefinition.name - Unique identifier for the template
257
304
  * @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
258
- * @param resourceTemplateDefinition.fn - Async function that generates resource content from URI and params
305
+ * @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
259
306
  * @returns The server instance for method chaining
260
307
  *
261
308
  * @example
@@ -267,7 +314,7 @@ var McpServer = class {
267
314
  * name: 'User Profile',
268
315
  * mimeType: 'application/json'
269
316
  * },
270
- * fn: async (uri, params) => ({
317
+ * readCallback: async (uri, params) => ({
271
318
  * contents: [{
272
319
  * uri: uri.toString(),
273
320
  * mimeType: 'application/json',
@@ -303,7 +350,7 @@ var McpServer = class {
303
350
  if (resourceTemplateDefinition.annotations) {
304
351
  metadata.annotations = resourceTemplateDefinition.annotations;
305
352
  }
306
- this.server.resource(
353
+ this.server.registerResource(
307
354
  resourceTemplateDefinition.name,
308
355
  template,
309
356
  metadata,
@@ -312,7 +359,7 @@ var McpServer = class {
312
359
  resourceTemplateDefinition.resourceTemplate.uriTemplate,
313
360
  uri.toString()
314
361
  );
315
- return await resourceTemplateDefinition.fn(uri, params);
362
+ return await resourceTemplateDefinition.readCallback(uri, params);
316
363
  }
317
364
  );
318
365
  return this;
@@ -324,11 +371,14 @@ var McpServer = class {
324
371
  * Tools are functions that perform actions, computations, or operations and
325
372
  * return results. They accept structured input parameters and return structured output.
326
373
  *
374
+ * Supports Apps SDK metadata for ChatGPT integration via the _meta field.
375
+ *
327
376
  * @param toolDefinition - Configuration object containing tool metadata and handler function
328
377
  * @param toolDefinition.name - Unique identifier for the tool
329
378
  * @param toolDefinition.description - Human-readable description of what the tool does
330
379
  * @param toolDefinition.inputs - Array of input parameter definitions with types and validation
331
- * @param toolDefinition.fn - Async function that executes the tool logic with provided parameters
380
+ * @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
381
+ * @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
332
382
  * @returns The server instance for method chaining
333
383
  *
334
384
  * @example
@@ -340,21 +390,31 @@ var McpServer = class {
340
390
  * { name: 'expression', type: 'string', required: true },
341
391
  * { name: 'precision', type: 'number', required: false }
342
392
  * ],
343
- * fn: async ({ expression, precision = 2 }) => {
393
+ * cb: async ({ expression, precision = 2 }) => {
344
394
  * const result = eval(expression)
345
395
  * return { result: Number(result.toFixed(precision)) }
396
+ * },
397
+ * _meta: {
398
+ * 'openai/outputTemplate': 'ui://widgets/calculator',
399
+ * 'openai/toolInvocation/invoking': 'Calculating...',
400
+ * 'openai/toolInvocation/invoked': 'Calculation complete'
346
401
  * }
347
402
  * })
348
403
  * ```
349
404
  */
350
405
  tool(toolDefinition) {
351
406
  const inputSchema = this.createToolInputSchema(toolDefinition.inputs || []);
352
- this.server.tool(
407
+ this.server.registerTool(
353
408
  toolDefinition.name,
354
- toolDefinition.description ?? "",
355
- inputSchema,
409
+ {
410
+ title: toolDefinition.title,
411
+ description: toolDefinition.description ?? "",
412
+ inputSchema,
413
+ annotations: toolDefinition.annotations,
414
+ _meta: toolDefinition._meta
415
+ },
356
416
  async (params) => {
357
- return await toolDefinition.fn(params);
417
+ return await toolDefinition.cb(params);
358
418
  }
359
419
  );
360
420
  return this;
@@ -370,7 +430,7 @@ var McpServer = class {
370
430
  * @param promptDefinition.name - Unique identifier for the prompt template
371
431
  * @param promptDefinition.description - Human-readable description of the prompt's purpose
372
432
  * @param promptDefinition.args - Array of argument definitions with types and validation
373
- * @param promptDefinition.fn - Async function that generates the prompt from provided arguments
433
+ * @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
374
434
  * @returns The server instance for method chaining
375
435
  *
376
436
  * @example
@@ -382,7 +442,7 @@ var McpServer = class {
382
442
  * { name: 'language', type: 'string', required: true },
383
443
  * { name: 'focus', type: 'string', required: false }
384
444
  * ],
385
- * fn: async ({ language, focus = 'general' }) => {
445
+ * cb: async ({ language, focus = 'general' }) => {
386
446
  * return {
387
447
  * messages: [{
388
448
  * role: 'user',
@@ -395,12 +455,15 @@ var McpServer = class {
395
455
  */
396
456
  prompt(promptDefinition) {
397
457
  const argsSchema = this.createPromptArgsSchema(promptDefinition.args || []);
398
- this.server.prompt(
458
+ this.server.registerPrompt(
399
459
  promptDefinition.name,
400
- promptDefinition.description ?? "",
401
- argsSchema,
460
+ {
461
+ title: promptDefinition.title,
462
+ description: promptDefinition.description ?? "",
463
+ argsSchema
464
+ },
402
465
  async (params) => {
403
- return await promptDefinition.fn(params);
466
+ return await promptDefinition.cb(params);
404
467
  }
405
468
  );
406
469
  return this;
@@ -412,19 +475,28 @@ var McpServer = class {
412
475
  * either as tools (with parameters) or as resources (static access). The tool
413
476
  * allows dynamic parameter passing while the resource provides discoverable access.
414
477
  *
478
+ * Supports multiple UI resource types:
479
+ * - externalUrl: Legacy MCP-UI iframe-based widgets
480
+ * - rawHtml: Legacy MCP-UI raw HTML content
481
+ * - remoteDom: Legacy MCP-UI Remote DOM scripting
482
+ * - appsSdk: OpenAI Apps SDK compatible widgets (text/html+skybridge)
483
+ *
415
484
  * @param definition - Configuration for the UI widget
416
485
  * @param definition.name - Unique identifier for the resource
417
- * @param definition.widget - Widget name (matches directory in dist/resources/mcp-use/widgets)
486
+ * @param definition.type - Type of UI resource (externalUrl, rawHtml, remoteDom, appsSdk)
418
487
  * @param definition.title - Human-readable title for the widget
419
488
  * @param definition.description - Description of the widget's functionality
420
489
  * @param definition.props - Widget properties configuration with types and defaults
421
490
  * @param definition.size - Preferred iframe size [width, height] (e.g., ['800px', '600px'])
422
491
  * @param definition.annotations - Resource annotations for discovery
492
+ * @param definition.appsSdkMetadata - Apps SDK specific metadata (CSP, widget description, etc.)
423
493
  * @returns The server instance for method chaining
424
494
  *
425
495
  * @example
426
496
  * ```typescript
497
+ * // Legacy MCP-UI widget
427
498
  * server.uiResource({
499
+ * type: 'externalUrl',
428
500
  * name: 'kanban-board',
429
501
  * widget: 'kanban-board',
430
502
  * title: 'Kanban Board',
@@ -434,18 +506,41 @@ var McpServer = class {
434
506
  * type: 'array',
435
507
  * description: 'Initial tasks to display',
436
508
  * required: false
437
- * },
438
- * theme: {
439
- * type: 'string',
440
- * default: 'light'
441
509
  * }
442
510
  * },
443
511
  * size: ['900px', '600px']
444
512
  * })
513
+ *
514
+ * // Apps SDK widget
515
+ * server.uiResource({
516
+ * type: 'appsSdk',
517
+ * name: 'kanban-board',
518
+ * title: 'Kanban Board',
519
+ * description: 'Interactive task management board',
520
+ * htmlTemplate: `
521
+ * <div id="kanban-root"></div>
522
+ * <style>${kanbanCSS}</style>
523
+ * <script type="module">${kanbanJS}</script>
524
+ * `,
525
+ * appsSdkMetadata: {
526
+ * 'openai/widgetDescription': 'Displays an interactive kanban board',
527
+ * 'openai/widgetCSP': {
528
+ * connect_domains: [],
529
+ * resource_domains: ['https://cdn.example.com']
530
+ * }
531
+ * }
532
+ * })
445
533
  * ```
446
534
  */
447
535
  uiResource(definition) {
448
- const toolName = definition.type === "externalUrl" ? `ui_${definition.widget}` : `ui_${definition.name}`;
536
+ let toolName;
537
+ if (definition.type === "appsSdk") {
538
+ toolName = definition.name;
539
+ } else if (definition.type === "externalUrl") {
540
+ toolName = `ui_${definition.widget}`;
541
+ } else {
542
+ toolName = `ui_${definition.name}`;
543
+ }
449
544
  const displayName = definition.title || definition.name;
450
545
  let resourceUri;
451
546
  let mimeType;
@@ -462,8 +557,12 @@ var McpServer = class {
462
557
  resourceUri = `ui://widget/${definition.name}`;
463
558
  mimeType = "application/vnd.mcp-ui.remote-dom+javascript";
464
559
  break;
560
+ case "appsSdk":
561
+ resourceUri = `ui://widget/${definition.name}.html`;
562
+ mimeType = "text/html+skybridge";
563
+ break;
465
564
  default:
466
- throw new Error(`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom`);
565
+ throw new Error(`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom, appsSdk`);
467
566
  }
468
567
  this.resource({
469
568
  name: definition.name,
@@ -472,20 +571,51 @@ var McpServer = class {
472
571
  description: definition.description,
473
572
  mimeType,
474
573
  annotations: definition.annotations,
475
- fn: /* @__PURE__ */ __name(async () => {
574
+ readCallback: /* @__PURE__ */ __name(async () => {
476
575
  const params = definition.type === "externalUrl" ? this.applyDefaultProps(definition.props) : {};
477
576
  const uiResource = this.createWidgetUIResource(definition, params);
478
577
  return {
479
578
  contents: [uiResource.resource]
480
579
  };
481
- }, "fn")
580
+ }, "readCallback")
482
581
  });
582
+ const toolMetadata = {};
583
+ if (definition.type === "appsSdk" && definition.appsSdkMetadata) {
584
+ toolMetadata["openai/outputTemplate"] = resourceUri;
585
+ const toolMetadataFields = [
586
+ "openai/toolInvocation/invoking",
587
+ "openai/toolInvocation/invoked",
588
+ "openai/widgetAccessible",
589
+ "openai/resultCanProduceWidget"
590
+ ];
591
+ for (const field of toolMetadataFields) {
592
+ if (definition.appsSdkMetadata[field] !== void 0) {
593
+ toolMetadata[field] = definition.appsSdkMetadata[field];
594
+ }
595
+ }
596
+ }
483
597
  this.tool({
484
598
  name: toolName,
485
- description: definition.description || `Display ${displayName}`,
599
+ title: definition.title,
600
+ // For Apps SDK, use title as description to match OpenAI's pizzaz reference implementation
601
+ description: definition.type === "appsSdk" && definition.title ? definition.title : definition.description || `Display ${displayName}`,
486
602
  inputs: this.convertPropsToInputs(definition.props),
487
- fn: /* @__PURE__ */ __name(async (params) => {
603
+ _meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0,
604
+ cb: /* @__PURE__ */ __name(async (params) => {
488
605
  const uiResource = this.createWidgetUIResource(definition, params);
606
+ if (definition.type === "appsSdk") {
607
+ return {
608
+ _meta: toolMetadata,
609
+ content: [
610
+ {
611
+ type: "text",
612
+ text: `Displaying ${displayName}`
613
+ }
614
+ ],
615
+ // structuredContent will be injected as window.openai.toolOutput by Apps SDK
616
+ structuredContent: params
617
+ };
618
+ }
489
619
  return {
490
620
  content: [
491
621
  {
@@ -496,7 +626,7 @@ var McpServer = class {
496
626
  uiResource
497
627
  ]
498
628
  };
499
- }, "fn")
629
+ }, "cb")
500
630
  });
501
631
  return this;
502
632
  }
@@ -825,6 +955,9 @@ var McpServer = class {
825
955
  default:
826
956
  zodType = import_zod.z.any();
827
957
  }
958
+ if (input.description) {
959
+ zodType = zodType.describe(input.description);
960
+ }
828
961
  if (!input.required) {
829
962
  zodType = zodType.optional();
830
963
  }
@@ -1,5 +1,5 @@
1
1
  export { createMCPServer, type McpServerInstance } from './mcp-server.js';
2
2
  export * from './types/index.js';
3
3
  export { buildWidgetUrl, createExternalUrlResource, createRawHtmlResource, createRemoteDomResource, createUIResourceFromDefinition, type UrlConfig } from './adapters/mcp-ui-adapter.js';
4
- export type { InputDefinition, PromptDefinition, PromptHandler, ResourceDefinition, ResourceHandler, ServerConfig, ToolDefinition, ToolHandler, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, WidgetProps, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, } from './types/index.js';
4
+ export type { InputDefinition, PromptDefinition, PromptCallback, ResourceDefinition, ReadResourceCallback, ReadResourceTemplateCallback, ServerConfig, ToolDefinition, ToolCallback, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, WidgetProps, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, } from './types/index.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AAExB,cAAc,kBAAkB,CAAA;AAGhC,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAA;AAErC,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,EAEX,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAA;AAExB,cAAc,kBAAkB,CAAA;AAGhC,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,KAAK,SAAS,EACf,MAAM,8BAA8B,CAAA;AAErC,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,cAAc,EACd,YAAY,EAEZ,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,kBAAkB,CAAA"}