mcp-use 1.0.6 → 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.
- package/dist/{chunk-CWWNPIJZ.js → chunk-56ZYVEAJ.js} +17 -8
- package/dist/index.cjs +15 -6
- package/dist/index.js +3 -3
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/react/index.cjs +13 -4
- package/dist/src/react/index.js +1 -1
- package/dist/src/react/types.d.ts +5 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +54 -4
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
- package/dist/src/server/index.cjs +175 -42
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +175 -42
- package/dist/src/server/mcp-server.d.ts +46 -13
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +3 -3
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +5 -3
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +95 -9
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +10 -3
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/tests/stream_events.test.d.ts +10 -0
- package/dist/tests/stream_events.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/src/server/index.js
CHANGED
|
@@ -57,44 +57,91 @@ function buildWidgetUrl(widget, props, config) {
|
|
|
57
57
|
return url.toString();
|
|
58
58
|
}
|
|
59
59
|
__name(buildWidgetUrl, "buildWidgetUrl");
|
|
60
|
-
function createExternalUrlResource(uri, iframeUrl, encoding = "text") {
|
|
60
|
+
function createExternalUrlResource(uri, iframeUrl, encoding = "text", adapters, metadata) {
|
|
61
61
|
return createUIResource({
|
|
62
62
|
uri,
|
|
63
63
|
content: { type: "externalUrl", iframeUrl },
|
|
64
|
-
encoding
|
|
64
|
+
encoding,
|
|
65
|
+
adapters,
|
|
66
|
+
metadata
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
69
|
__name(createExternalUrlResource, "createExternalUrlResource");
|
|
68
|
-
function createRawHtmlResource(uri, htmlString, encoding = "text") {
|
|
70
|
+
function createRawHtmlResource(uri, htmlString, encoding = "text", adapters, metadata) {
|
|
69
71
|
return createUIResource({
|
|
70
72
|
uri,
|
|
71
73
|
content: { type: "rawHtml", htmlString },
|
|
72
|
-
encoding
|
|
74
|
+
encoding,
|
|
75
|
+
adapters,
|
|
76
|
+
metadata
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
__name(createRawHtmlResource, "createRawHtmlResource");
|
|
76
|
-
function createRemoteDomResource(uri, script, framework = "react", encoding = "text") {
|
|
80
|
+
function createRemoteDomResource(uri, script, framework = "react", encoding = "text", adapters, metadata) {
|
|
77
81
|
return createUIResource({
|
|
78
82
|
uri,
|
|
79
83
|
content: { type: "remoteDom", script, framework },
|
|
80
|
-
encoding
|
|
84
|
+
encoding,
|
|
85
|
+
adapters,
|
|
86
|
+
metadata
|
|
81
87
|
});
|
|
82
88
|
}
|
|
83
89
|
__name(createRemoteDomResource, "createRemoteDomResource");
|
|
90
|
+
function createAppsSdkResource(uri, htmlTemplate, metadata) {
|
|
91
|
+
const resource = {
|
|
92
|
+
uri,
|
|
93
|
+
mimeType: "text/html+skybridge",
|
|
94
|
+
text: htmlTemplate
|
|
95
|
+
};
|
|
96
|
+
if (metadata && Object.keys(metadata).length > 0) {
|
|
97
|
+
resource._meta = metadata;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
type: "resource",
|
|
101
|
+
resource
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
__name(createAppsSdkResource, "createAppsSdkResource");
|
|
84
105
|
function createUIResourceFromDefinition(definition, params, config) {
|
|
85
|
-
const uri = `ui://widget/${definition.name}`;
|
|
106
|
+
const uri = definition.type === "appsSdk" ? `ui://widget/${definition.name}.html` : `ui://widget/${definition.name}`;
|
|
86
107
|
const encoding = definition.encoding || "text";
|
|
87
108
|
switch (definition.type) {
|
|
88
109
|
case "externalUrl": {
|
|
89
110
|
const widgetUrl = buildWidgetUrl(definition.widget, params, config);
|
|
90
|
-
return createExternalUrlResource(
|
|
111
|
+
return createExternalUrlResource(
|
|
112
|
+
uri,
|
|
113
|
+
widgetUrl,
|
|
114
|
+
encoding,
|
|
115
|
+
definition.adapters,
|
|
116
|
+
definition.appsSdkMetadata
|
|
117
|
+
);
|
|
91
118
|
}
|
|
92
119
|
case "rawHtml": {
|
|
93
|
-
return createRawHtmlResource(
|
|
120
|
+
return createRawHtmlResource(
|
|
121
|
+
uri,
|
|
122
|
+
definition.htmlContent,
|
|
123
|
+
encoding,
|
|
124
|
+
definition.adapters,
|
|
125
|
+
definition.appsSdkMetadata
|
|
126
|
+
);
|
|
94
127
|
}
|
|
95
128
|
case "remoteDom": {
|
|
96
129
|
const framework = definition.framework || "react";
|
|
97
|
-
return createRemoteDomResource(
|
|
130
|
+
return createRemoteDomResource(
|
|
131
|
+
uri,
|
|
132
|
+
definition.script,
|
|
133
|
+
framework,
|
|
134
|
+
encoding,
|
|
135
|
+
definition.adapters,
|
|
136
|
+
definition.appsSdkMetadata
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
case "appsSdk": {
|
|
140
|
+
return createAppsSdkResource(
|
|
141
|
+
uri,
|
|
142
|
+
definition.htmlTemplate,
|
|
143
|
+
definition.appsSdkMetadata
|
|
144
|
+
);
|
|
98
145
|
}
|
|
99
146
|
default: {
|
|
100
147
|
const _exhaustive = definition;
|
|
@@ -165,7 +212,7 @@ var McpServer = class {
|
|
|
165
212
|
* @param resourceDefinition.description - Optional description of the resource
|
|
166
213
|
* @param resourceDefinition.mimeType - MIME type of the resource content
|
|
167
214
|
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
|
168
|
-
* @param resourceDefinition.
|
|
215
|
+
* @param resourceDefinition.readCallback - Async callback function that returns the resource content
|
|
169
216
|
* @returns The server instance for method chaining
|
|
170
217
|
*
|
|
171
218
|
* @example
|
|
@@ -180,7 +227,7 @@ var McpServer = class {
|
|
|
180
227
|
* audience: ['user'],
|
|
181
228
|
* priority: 0.8
|
|
182
229
|
* },
|
|
183
|
-
*
|
|
230
|
+
* readCallback: async () => ({
|
|
184
231
|
* contents: [{
|
|
185
232
|
* uri: 'config://app-settings',
|
|
186
233
|
* mimeType: 'application/json',
|
|
@@ -191,7 +238,7 @@ var McpServer = class {
|
|
|
191
238
|
* ```
|
|
192
239
|
*/
|
|
193
240
|
resource(resourceDefinition) {
|
|
194
|
-
this.server.
|
|
241
|
+
this.server.registerResource(
|
|
195
242
|
resourceDefinition.name,
|
|
196
243
|
resourceDefinition.uri,
|
|
197
244
|
{
|
|
@@ -202,7 +249,7 @@ var McpServer = class {
|
|
|
202
249
|
annotations: resourceDefinition.annotations
|
|
203
250
|
},
|
|
204
251
|
async () => {
|
|
205
|
-
return await resourceDefinition.
|
|
252
|
+
return await resourceDefinition.readCallback();
|
|
206
253
|
}
|
|
207
254
|
);
|
|
208
255
|
return this;
|
|
@@ -217,7 +264,7 @@ var McpServer = class {
|
|
|
217
264
|
* @param resourceTemplateDefinition - Configuration object for the resource template
|
|
218
265
|
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
|
219
266
|
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
|
220
|
-
* @param resourceTemplateDefinition.
|
|
267
|
+
* @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
|
|
221
268
|
* @returns The server instance for method chaining
|
|
222
269
|
*
|
|
223
270
|
* @example
|
|
@@ -229,7 +276,7 @@ var McpServer = class {
|
|
|
229
276
|
* name: 'User Profile',
|
|
230
277
|
* mimeType: 'application/json'
|
|
231
278
|
* },
|
|
232
|
-
*
|
|
279
|
+
* readCallback: async (uri, params) => ({
|
|
233
280
|
* contents: [{
|
|
234
281
|
* uri: uri.toString(),
|
|
235
282
|
* mimeType: 'application/json',
|
|
@@ -265,7 +312,7 @@ var McpServer = class {
|
|
|
265
312
|
if (resourceTemplateDefinition.annotations) {
|
|
266
313
|
metadata.annotations = resourceTemplateDefinition.annotations;
|
|
267
314
|
}
|
|
268
|
-
this.server.
|
|
315
|
+
this.server.registerResource(
|
|
269
316
|
resourceTemplateDefinition.name,
|
|
270
317
|
template,
|
|
271
318
|
metadata,
|
|
@@ -274,7 +321,7 @@ var McpServer = class {
|
|
|
274
321
|
resourceTemplateDefinition.resourceTemplate.uriTemplate,
|
|
275
322
|
uri.toString()
|
|
276
323
|
);
|
|
277
|
-
return await resourceTemplateDefinition.
|
|
324
|
+
return await resourceTemplateDefinition.readCallback(uri, params);
|
|
278
325
|
}
|
|
279
326
|
);
|
|
280
327
|
return this;
|
|
@@ -286,11 +333,14 @@ var McpServer = class {
|
|
|
286
333
|
* Tools are functions that perform actions, computations, or operations and
|
|
287
334
|
* return results. They accept structured input parameters and return structured output.
|
|
288
335
|
*
|
|
336
|
+
* Supports Apps SDK metadata for ChatGPT integration via the _meta field.
|
|
337
|
+
*
|
|
289
338
|
* @param toolDefinition - Configuration object containing tool metadata and handler function
|
|
290
339
|
* @param toolDefinition.name - Unique identifier for the tool
|
|
291
340
|
* @param toolDefinition.description - Human-readable description of what the tool does
|
|
292
341
|
* @param toolDefinition.inputs - Array of input parameter definitions with types and validation
|
|
293
|
-
* @param toolDefinition.
|
|
342
|
+
* @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
|
|
343
|
+
* @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
|
|
294
344
|
* @returns The server instance for method chaining
|
|
295
345
|
*
|
|
296
346
|
* @example
|
|
@@ -302,21 +352,31 @@ var McpServer = class {
|
|
|
302
352
|
* { name: 'expression', type: 'string', required: true },
|
|
303
353
|
* { name: 'precision', type: 'number', required: false }
|
|
304
354
|
* ],
|
|
305
|
-
*
|
|
355
|
+
* cb: async ({ expression, precision = 2 }) => {
|
|
306
356
|
* const result = eval(expression)
|
|
307
357
|
* return { result: Number(result.toFixed(precision)) }
|
|
358
|
+
* },
|
|
359
|
+
* _meta: {
|
|
360
|
+
* 'openai/outputTemplate': 'ui://widgets/calculator',
|
|
361
|
+
* 'openai/toolInvocation/invoking': 'Calculating...',
|
|
362
|
+
* 'openai/toolInvocation/invoked': 'Calculation complete'
|
|
308
363
|
* }
|
|
309
364
|
* })
|
|
310
365
|
* ```
|
|
311
366
|
*/
|
|
312
367
|
tool(toolDefinition) {
|
|
313
368
|
const inputSchema = this.createToolInputSchema(toolDefinition.inputs || []);
|
|
314
|
-
this.server.
|
|
369
|
+
this.server.registerTool(
|
|
315
370
|
toolDefinition.name,
|
|
316
|
-
|
|
317
|
-
|
|
371
|
+
{
|
|
372
|
+
title: toolDefinition.title,
|
|
373
|
+
description: toolDefinition.description ?? "",
|
|
374
|
+
inputSchema,
|
|
375
|
+
annotations: toolDefinition.annotations,
|
|
376
|
+
_meta: toolDefinition._meta
|
|
377
|
+
},
|
|
318
378
|
async (params) => {
|
|
319
|
-
return await toolDefinition.
|
|
379
|
+
return await toolDefinition.cb(params);
|
|
320
380
|
}
|
|
321
381
|
);
|
|
322
382
|
return this;
|
|
@@ -332,7 +392,7 @@ var McpServer = class {
|
|
|
332
392
|
* @param promptDefinition.name - Unique identifier for the prompt template
|
|
333
393
|
* @param promptDefinition.description - Human-readable description of the prompt's purpose
|
|
334
394
|
* @param promptDefinition.args - Array of argument definitions with types and validation
|
|
335
|
-
* @param promptDefinition.
|
|
395
|
+
* @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
|
|
336
396
|
* @returns The server instance for method chaining
|
|
337
397
|
*
|
|
338
398
|
* @example
|
|
@@ -344,7 +404,7 @@ var McpServer = class {
|
|
|
344
404
|
* { name: 'language', type: 'string', required: true },
|
|
345
405
|
* { name: 'focus', type: 'string', required: false }
|
|
346
406
|
* ],
|
|
347
|
-
*
|
|
407
|
+
* cb: async ({ language, focus = 'general' }) => {
|
|
348
408
|
* return {
|
|
349
409
|
* messages: [{
|
|
350
410
|
* role: 'user',
|
|
@@ -357,12 +417,15 @@ var McpServer = class {
|
|
|
357
417
|
*/
|
|
358
418
|
prompt(promptDefinition) {
|
|
359
419
|
const argsSchema = this.createPromptArgsSchema(promptDefinition.args || []);
|
|
360
|
-
this.server.
|
|
420
|
+
this.server.registerPrompt(
|
|
361
421
|
promptDefinition.name,
|
|
362
|
-
|
|
363
|
-
|
|
422
|
+
{
|
|
423
|
+
title: promptDefinition.title,
|
|
424
|
+
description: promptDefinition.description ?? "",
|
|
425
|
+
argsSchema
|
|
426
|
+
},
|
|
364
427
|
async (params) => {
|
|
365
|
-
return await promptDefinition.
|
|
428
|
+
return await promptDefinition.cb(params);
|
|
366
429
|
}
|
|
367
430
|
);
|
|
368
431
|
return this;
|
|
@@ -374,19 +437,28 @@ var McpServer = class {
|
|
|
374
437
|
* either as tools (with parameters) or as resources (static access). The tool
|
|
375
438
|
* allows dynamic parameter passing while the resource provides discoverable access.
|
|
376
439
|
*
|
|
440
|
+
* Supports multiple UI resource types:
|
|
441
|
+
* - externalUrl: Legacy MCP-UI iframe-based widgets
|
|
442
|
+
* - rawHtml: Legacy MCP-UI raw HTML content
|
|
443
|
+
* - remoteDom: Legacy MCP-UI Remote DOM scripting
|
|
444
|
+
* - appsSdk: OpenAI Apps SDK compatible widgets (text/html+skybridge)
|
|
445
|
+
*
|
|
377
446
|
* @param definition - Configuration for the UI widget
|
|
378
447
|
* @param definition.name - Unique identifier for the resource
|
|
379
|
-
* @param definition.
|
|
448
|
+
* @param definition.type - Type of UI resource (externalUrl, rawHtml, remoteDom, appsSdk)
|
|
380
449
|
* @param definition.title - Human-readable title for the widget
|
|
381
450
|
* @param definition.description - Description of the widget's functionality
|
|
382
451
|
* @param definition.props - Widget properties configuration with types and defaults
|
|
383
452
|
* @param definition.size - Preferred iframe size [width, height] (e.g., ['800px', '600px'])
|
|
384
453
|
* @param definition.annotations - Resource annotations for discovery
|
|
454
|
+
* @param definition.appsSdkMetadata - Apps SDK specific metadata (CSP, widget description, etc.)
|
|
385
455
|
* @returns The server instance for method chaining
|
|
386
456
|
*
|
|
387
457
|
* @example
|
|
388
458
|
* ```typescript
|
|
459
|
+
* // Legacy MCP-UI widget
|
|
389
460
|
* server.uiResource({
|
|
461
|
+
* type: 'externalUrl',
|
|
390
462
|
* name: 'kanban-board',
|
|
391
463
|
* widget: 'kanban-board',
|
|
392
464
|
* title: 'Kanban Board',
|
|
@@ -396,18 +468,41 @@ var McpServer = class {
|
|
|
396
468
|
* type: 'array',
|
|
397
469
|
* description: 'Initial tasks to display',
|
|
398
470
|
* required: false
|
|
399
|
-
* },
|
|
400
|
-
* theme: {
|
|
401
|
-
* type: 'string',
|
|
402
|
-
* default: 'light'
|
|
403
471
|
* }
|
|
404
472
|
* },
|
|
405
473
|
* size: ['900px', '600px']
|
|
406
474
|
* })
|
|
475
|
+
*
|
|
476
|
+
* // Apps SDK widget
|
|
477
|
+
* server.uiResource({
|
|
478
|
+
* type: 'appsSdk',
|
|
479
|
+
* name: 'kanban-board',
|
|
480
|
+
* title: 'Kanban Board',
|
|
481
|
+
* description: 'Interactive task management board',
|
|
482
|
+
* htmlTemplate: `
|
|
483
|
+
* <div id="kanban-root"></div>
|
|
484
|
+
* <style>${kanbanCSS}</style>
|
|
485
|
+
* <script type="module">${kanbanJS}</script>
|
|
486
|
+
* `,
|
|
487
|
+
* appsSdkMetadata: {
|
|
488
|
+
* 'openai/widgetDescription': 'Displays an interactive kanban board',
|
|
489
|
+
* 'openai/widgetCSP': {
|
|
490
|
+
* connect_domains: [],
|
|
491
|
+
* resource_domains: ['https://cdn.example.com']
|
|
492
|
+
* }
|
|
493
|
+
* }
|
|
494
|
+
* })
|
|
407
495
|
* ```
|
|
408
496
|
*/
|
|
409
497
|
uiResource(definition) {
|
|
410
|
-
|
|
498
|
+
let toolName;
|
|
499
|
+
if (definition.type === "appsSdk") {
|
|
500
|
+
toolName = definition.name;
|
|
501
|
+
} else if (definition.type === "externalUrl") {
|
|
502
|
+
toolName = `ui_${definition.widget}`;
|
|
503
|
+
} else {
|
|
504
|
+
toolName = `ui_${definition.name}`;
|
|
505
|
+
}
|
|
411
506
|
const displayName = definition.title || definition.name;
|
|
412
507
|
let resourceUri;
|
|
413
508
|
let mimeType;
|
|
@@ -424,8 +519,12 @@ var McpServer = class {
|
|
|
424
519
|
resourceUri = `ui://widget/${definition.name}`;
|
|
425
520
|
mimeType = "application/vnd.mcp-ui.remote-dom+javascript";
|
|
426
521
|
break;
|
|
522
|
+
case "appsSdk":
|
|
523
|
+
resourceUri = `ui://widget/${definition.name}.html`;
|
|
524
|
+
mimeType = "text/html+skybridge";
|
|
525
|
+
break;
|
|
427
526
|
default:
|
|
428
|
-
throw new Error(`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom`);
|
|
527
|
+
throw new Error(`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom, appsSdk`);
|
|
429
528
|
}
|
|
430
529
|
this.resource({
|
|
431
530
|
name: definition.name,
|
|
@@ -434,20 +533,51 @@ var McpServer = class {
|
|
|
434
533
|
description: definition.description,
|
|
435
534
|
mimeType,
|
|
436
535
|
annotations: definition.annotations,
|
|
437
|
-
|
|
536
|
+
readCallback: /* @__PURE__ */ __name(async () => {
|
|
438
537
|
const params = definition.type === "externalUrl" ? this.applyDefaultProps(definition.props) : {};
|
|
439
538
|
const uiResource = this.createWidgetUIResource(definition, params);
|
|
440
539
|
return {
|
|
441
540
|
contents: [uiResource.resource]
|
|
442
541
|
};
|
|
443
|
-
}, "
|
|
542
|
+
}, "readCallback")
|
|
444
543
|
});
|
|
544
|
+
const toolMetadata = {};
|
|
545
|
+
if (definition.type === "appsSdk" && definition.appsSdkMetadata) {
|
|
546
|
+
toolMetadata["openai/outputTemplate"] = resourceUri;
|
|
547
|
+
const toolMetadataFields = [
|
|
548
|
+
"openai/toolInvocation/invoking",
|
|
549
|
+
"openai/toolInvocation/invoked",
|
|
550
|
+
"openai/widgetAccessible",
|
|
551
|
+
"openai/resultCanProduceWidget"
|
|
552
|
+
];
|
|
553
|
+
for (const field of toolMetadataFields) {
|
|
554
|
+
if (definition.appsSdkMetadata[field] !== void 0) {
|
|
555
|
+
toolMetadata[field] = definition.appsSdkMetadata[field];
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
445
559
|
this.tool({
|
|
446
560
|
name: toolName,
|
|
447
|
-
|
|
561
|
+
title: definition.title,
|
|
562
|
+
// For Apps SDK, use title as description to match OpenAI's pizzaz reference implementation
|
|
563
|
+
description: definition.type === "appsSdk" && definition.title ? definition.title : definition.description || `Display ${displayName}`,
|
|
448
564
|
inputs: this.convertPropsToInputs(definition.props),
|
|
449
|
-
|
|
565
|
+
_meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0,
|
|
566
|
+
cb: /* @__PURE__ */ __name(async (params) => {
|
|
450
567
|
const uiResource = this.createWidgetUIResource(definition, params);
|
|
568
|
+
if (definition.type === "appsSdk") {
|
|
569
|
+
return {
|
|
570
|
+
_meta: toolMetadata,
|
|
571
|
+
content: [
|
|
572
|
+
{
|
|
573
|
+
type: "text",
|
|
574
|
+
text: `Displaying ${displayName}`
|
|
575
|
+
}
|
|
576
|
+
],
|
|
577
|
+
// structuredContent will be injected as window.openai.toolOutput by Apps SDK
|
|
578
|
+
structuredContent: params
|
|
579
|
+
};
|
|
580
|
+
}
|
|
451
581
|
return {
|
|
452
582
|
content: [
|
|
453
583
|
{
|
|
@@ -458,7 +588,7 @@ var McpServer = class {
|
|
|
458
588
|
uiResource
|
|
459
589
|
]
|
|
460
590
|
};
|
|
461
|
-
}, "
|
|
591
|
+
}, "cb")
|
|
462
592
|
});
|
|
463
593
|
return this;
|
|
464
594
|
}
|
|
@@ -787,6 +917,9 @@ var McpServer = class {
|
|
|
787
917
|
default:
|
|
788
918
|
zodType = z.any();
|
|
789
919
|
}
|
|
920
|
+
if (input.description) {
|
|
921
|
+
zodType = zodType.describe(input.description);
|
|
922
|
+
}
|
|
790
923
|
if (!input.required) {
|
|
791
924
|
zodType = zodType.optional();
|
|
792
925
|
}
|
|
@@ -32,7 +32,7 @@ export declare class McpServer {
|
|
|
32
32
|
* @param resourceDefinition.description - Optional description of the resource
|
|
33
33
|
* @param resourceDefinition.mimeType - MIME type of the resource content
|
|
34
34
|
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
|
35
|
-
* @param resourceDefinition.
|
|
35
|
+
* @param resourceDefinition.readCallback - Async callback function that returns the resource content
|
|
36
36
|
* @returns The server instance for method chaining
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
@@ -47,7 +47,7 @@ export declare class McpServer {
|
|
|
47
47
|
* audience: ['user'],
|
|
48
48
|
* priority: 0.8
|
|
49
49
|
* },
|
|
50
|
-
*
|
|
50
|
+
* readCallback: async () => ({
|
|
51
51
|
* contents: [{
|
|
52
52
|
* uri: 'config://app-settings',
|
|
53
53
|
* mimeType: 'application/json',
|
|
@@ -68,7 +68,7 @@ export declare class McpServer {
|
|
|
68
68
|
* @param resourceTemplateDefinition - Configuration object for the resource template
|
|
69
69
|
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
|
70
70
|
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
|
71
|
-
* @param resourceTemplateDefinition.
|
|
71
|
+
* @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
|
|
72
72
|
* @returns The server instance for method chaining
|
|
73
73
|
*
|
|
74
74
|
* @example
|
|
@@ -80,7 +80,7 @@ export declare class McpServer {
|
|
|
80
80
|
* name: 'User Profile',
|
|
81
81
|
* mimeType: 'application/json'
|
|
82
82
|
* },
|
|
83
|
-
*
|
|
83
|
+
* readCallback: async (uri, params) => ({
|
|
84
84
|
* contents: [{
|
|
85
85
|
* uri: uri.toString(),
|
|
86
86
|
* mimeType: 'application/json',
|
|
@@ -98,11 +98,14 @@ export declare class McpServer {
|
|
|
98
98
|
* Tools are functions that perform actions, computations, or operations and
|
|
99
99
|
* return results. They accept structured input parameters and return structured output.
|
|
100
100
|
*
|
|
101
|
+
* Supports Apps SDK metadata for ChatGPT integration via the _meta field.
|
|
102
|
+
*
|
|
101
103
|
* @param toolDefinition - Configuration object containing tool metadata and handler function
|
|
102
104
|
* @param toolDefinition.name - Unique identifier for the tool
|
|
103
105
|
* @param toolDefinition.description - Human-readable description of what the tool does
|
|
104
106
|
* @param toolDefinition.inputs - Array of input parameter definitions with types and validation
|
|
105
|
-
* @param toolDefinition.
|
|
107
|
+
* @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
|
|
108
|
+
* @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
|
|
106
109
|
* @returns The server instance for method chaining
|
|
107
110
|
*
|
|
108
111
|
* @example
|
|
@@ -114,9 +117,14 @@ export declare class McpServer {
|
|
|
114
117
|
* { name: 'expression', type: 'string', required: true },
|
|
115
118
|
* { name: 'precision', type: 'number', required: false }
|
|
116
119
|
* ],
|
|
117
|
-
*
|
|
120
|
+
* cb: async ({ expression, precision = 2 }) => {
|
|
118
121
|
* const result = eval(expression)
|
|
119
122
|
* return { result: Number(result.toFixed(precision)) }
|
|
123
|
+
* },
|
|
124
|
+
* _meta: {
|
|
125
|
+
* 'openai/outputTemplate': 'ui://widgets/calculator',
|
|
126
|
+
* 'openai/toolInvocation/invoking': 'Calculating...',
|
|
127
|
+
* 'openai/toolInvocation/invoked': 'Calculation complete'
|
|
120
128
|
* }
|
|
121
129
|
* })
|
|
122
130
|
* ```
|
|
@@ -133,7 +141,7 @@ export declare class McpServer {
|
|
|
133
141
|
* @param promptDefinition.name - Unique identifier for the prompt template
|
|
134
142
|
* @param promptDefinition.description - Human-readable description of the prompt's purpose
|
|
135
143
|
* @param promptDefinition.args - Array of argument definitions with types and validation
|
|
136
|
-
* @param promptDefinition.
|
|
144
|
+
* @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
|
|
137
145
|
* @returns The server instance for method chaining
|
|
138
146
|
*
|
|
139
147
|
* @example
|
|
@@ -145,7 +153,7 @@ export declare class McpServer {
|
|
|
145
153
|
* { name: 'language', type: 'string', required: true },
|
|
146
154
|
* { name: 'focus', type: 'string', required: false }
|
|
147
155
|
* ],
|
|
148
|
-
*
|
|
156
|
+
* cb: async ({ language, focus = 'general' }) => {
|
|
149
157
|
* return {
|
|
150
158
|
* messages: [{
|
|
151
159
|
* role: 'user',
|
|
@@ -164,19 +172,28 @@ export declare class McpServer {
|
|
|
164
172
|
* either as tools (with parameters) or as resources (static access). The tool
|
|
165
173
|
* allows dynamic parameter passing while the resource provides discoverable access.
|
|
166
174
|
*
|
|
175
|
+
* Supports multiple UI resource types:
|
|
176
|
+
* - externalUrl: Legacy MCP-UI iframe-based widgets
|
|
177
|
+
* - rawHtml: Legacy MCP-UI raw HTML content
|
|
178
|
+
* - remoteDom: Legacy MCP-UI Remote DOM scripting
|
|
179
|
+
* - appsSdk: OpenAI Apps SDK compatible widgets (text/html+skybridge)
|
|
180
|
+
*
|
|
167
181
|
* @param definition - Configuration for the UI widget
|
|
168
182
|
* @param definition.name - Unique identifier for the resource
|
|
169
|
-
* @param definition.
|
|
183
|
+
* @param definition.type - Type of UI resource (externalUrl, rawHtml, remoteDom, appsSdk)
|
|
170
184
|
* @param definition.title - Human-readable title for the widget
|
|
171
185
|
* @param definition.description - Description of the widget's functionality
|
|
172
186
|
* @param definition.props - Widget properties configuration with types and defaults
|
|
173
187
|
* @param definition.size - Preferred iframe size [width, height] (e.g., ['800px', '600px'])
|
|
174
188
|
* @param definition.annotations - Resource annotations for discovery
|
|
189
|
+
* @param definition.appsSdkMetadata - Apps SDK specific metadata (CSP, widget description, etc.)
|
|
175
190
|
* @returns The server instance for method chaining
|
|
176
191
|
*
|
|
177
192
|
* @example
|
|
178
193
|
* ```typescript
|
|
194
|
+
* // Legacy MCP-UI widget
|
|
179
195
|
* server.uiResource({
|
|
196
|
+
* type: 'externalUrl',
|
|
180
197
|
* name: 'kanban-board',
|
|
181
198
|
* widget: 'kanban-board',
|
|
182
199
|
* title: 'Kanban Board',
|
|
@@ -186,14 +203,30 @@ export declare class McpServer {
|
|
|
186
203
|
* type: 'array',
|
|
187
204
|
* description: 'Initial tasks to display',
|
|
188
205
|
* required: false
|
|
189
|
-
* },
|
|
190
|
-
* theme: {
|
|
191
|
-
* type: 'string',
|
|
192
|
-
* default: 'light'
|
|
193
206
|
* }
|
|
194
207
|
* },
|
|
195
208
|
* size: ['900px', '600px']
|
|
196
209
|
* })
|
|
210
|
+
*
|
|
211
|
+
* // Apps SDK widget
|
|
212
|
+
* server.uiResource({
|
|
213
|
+
* type: 'appsSdk',
|
|
214
|
+
* name: 'kanban-board',
|
|
215
|
+
* title: 'Kanban Board',
|
|
216
|
+
* description: 'Interactive task management board',
|
|
217
|
+
* htmlTemplate: `
|
|
218
|
+
* <div id="kanban-root"></div>
|
|
219
|
+
* <style>${kanbanCSS}</style>
|
|
220
|
+
* <script type="module">${kanbanJS}</script>
|
|
221
|
+
* `,
|
|
222
|
+
* appsSdkMetadata: {
|
|
223
|
+
* 'openai/widgetDescription': 'Displays an interactive kanban board',
|
|
224
|
+
* 'openai/widgetCSP': {
|
|
225
|
+
* connect_domains: [],
|
|
226
|
+
* resource_domains: ['https://cdn.example.com']
|
|
227
|
+
* }
|
|
228
|
+
* }
|
|
229
|
+
* })
|
|
197
230
|
* ```
|
|
198
231
|
*/
|
|
199
232
|
uiResource(definition: UIResourceDefinition): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EAC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,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,OAAO,CAAA;AAExE;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,iBAAiB,CAOnG"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Centralized type exports for MCP server
|
|
3
3
|
*/
|
|
4
4
|
export { ServerConfig, InputDefinition, ResourceAnnotations } from './common.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
5
|
+
export { ReadResourceCallback, ReadResourceTemplateCallback, ResourceTemplateConfig, ResourceTemplateDefinition, ResourceDefinition, UIResourceContent, WidgetProps, UIEncoding, RemoteDomFramework, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, AppsSdkUIResource, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, AppsSdkMetadata, AppsSdkToolMetadata } from './resource.js';
|
|
6
|
+
export { ToolCallback, ToolDefinition } from './tool.js';
|
|
7
|
+
export { PromptCallback, PromptDefinition } from './prompt.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACpB,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACpB,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,0BAA0B,EAC1B,kBAAkB,EAElB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,sBAAsB,EAEtB,eAAe,EACf,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,YAAY,EACZ,cAAc,EACf,MAAM,WAAW,CAAA;AAGlB,OAAO,EACL,cAAc,EACd,gBAAgB,EACjB,MAAM,aAAa,CAAA"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import type { InputDefinition } from './common.js';
|
|
3
|
-
export type
|
|
3
|
+
export type PromptCallback = (params: Record<string, any>) => Promise<GetPromptResult>;
|
|
4
4
|
export interface PromptDefinition {
|
|
5
5
|
/** Unique identifier for the prompt */
|
|
6
6
|
name: string;
|
|
7
|
+
/** Human-readable title for the prompt */
|
|
8
|
+
title?: string;
|
|
7
9
|
/** Description of what the prompt does */
|
|
8
10
|
description?: string;
|
|
9
11
|
/** Argument definitions */
|
|
10
12
|
args?: InputDefinition[];
|
|
11
|
-
/** Async function that generates the prompt */
|
|
12
|
-
|
|
13
|
+
/** Async callback function that generates the prompt */
|
|
14
|
+
cb: PromptCallback;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/server/types/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/server/types/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;AAEtF,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,eAAe,EAAE,CAAA;IACxB,wDAAwD;IACxD,EAAE,EAAE,cAAc,CAAA;CACnB"}
|