mcp-use 1.0.3 → 1.0.5
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/README.md +98 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +66 -0
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -0
- package/dist/src/server/index.cjs +292 -14
- package/dist/src/server/index.d.ts +4 -2
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +286 -13
- package/dist/src/server/mcp-server.d.ts +91 -2
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +27 -0
- package/dist/src/server/types/common.d.ts.map +1 -0
- package/dist/src/server/types/index.d.ts +8 -0
- package/dist/src/server/types/index.d.ts.map +1 -0
- package/dist/src/server/types/prompt.d.ts +14 -0
- package/dist/src/server/types/prompt.d.ts.map +1 -0
- package/dist/src/server/types/resource.d.ts +155 -0
- package/dist/src/server/types/resource.d.ts.map +1 -0
- package/dist/src/server/types/tool.d.ts +14 -0
- package/dist/src/server/types/tool.d.ts.map +1 -0
- package/dist/src/server/types.d.ts +3 -76
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/tests/helpers/widget-generators.d.ts +24 -0
- package/dist/tests/helpers/widget-generators.d.ts.map +1 -0
- package/dist/tests/mcp-ui-adapter.test.d.ts +8 -0
- package/dist/tests/mcp-ui-adapter.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/src/server/index.js
CHANGED
@@ -39,6 +39,71 @@ function requestLogger(req, res, next) {
|
|
39
39
|
}
|
40
40
|
__name(requestLogger, "requestLogger");
|
41
41
|
|
42
|
+
// src/server/adapters/mcp-ui-adapter.ts
|
43
|
+
import { createUIResource } from "@mcp-ui/server";
|
44
|
+
function buildWidgetUrl(widget, props, config) {
|
45
|
+
const url = new URL(
|
46
|
+
`/mcp-use/widgets/${widget}`,
|
47
|
+
`${config.baseUrl}:${config.port}`
|
48
|
+
);
|
49
|
+
if (props) {
|
50
|
+
Object.entries(props).forEach(([key, value]) => {
|
51
|
+
if (value !== void 0 && value !== null) {
|
52
|
+
const stringValue = typeof value === "object" ? JSON.stringify(value) : String(value);
|
53
|
+
url.searchParams.set(key, stringValue);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
return url.toString();
|
58
|
+
}
|
59
|
+
__name(buildWidgetUrl, "buildWidgetUrl");
|
60
|
+
function createExternalUrlResource(uri, iframeUrl, encoding = "text") {
|
61
|
+
return createUIResource({
|
62
|
+
uri,
|
63
|
+
content: { type: "externalUrl", iframeUrl },
|
64
|
+
encoding
|
65
|
+
});
|
66
|
+
}
|
67
|
+
__name(createExternalUrlResource, "createExternalUrlResource");
|
68
|
+
function createRawHtmlResource(uri, htmlString, encoding = "text") {
|
69
|
+
return createUIResource({
|
70
|
+
uri,
|
71
|
+
content: { type: "rawHtml", htmlString },
|
72
|
+
encoding
|
73
|
+
});
|
74
|
+
}
|
75
|
+
__name(createRawHtmlResource, "createRawHtmlResource");
|
76
|
+
function createRemoteDomResource(uri, script, framework = "react", encoding = "text") {
|
77
|
+
return createUIResource({
|
78
|
+
uri,
|
79
|
+
content: { type: "remoteDom", script, framework },
|
80
|
+
encoding
|
81
|
+
});
|
82
|
+
}
|
83
|
+
__name(createRemoteDomResource, "createRemoteDomResource");
|
84
|
+
function createUIResourceFromDefinition(definition, params, config) {
|
85
|
+
const uri = `ui://widget/${definition.name}`;
|
86
|
+
const encoding = definition.encoding || "text";
|
87
|
+
switch (definition.type) {
|
88
|
+
case "externalUrl": {
|
89
|
+
const widgetUrl = buildWidgetUrl(definition.widget, params, config);
|
90
|
+
return createExternalUrlResource(uri, widgetUrl, encoding);
|
91
|
+
}
|
92
|
+
case "rawHtml": {
|
93
|
+
return createRawHtmlResource(uri, definition.htmlContent, encoding);
|
94
|
+
}
|
95
|
+
case "remoteDom": {
|
96
|
+
const framework = definition.framework || "react";
|
97
|
+
return createRemoteDomResource(uri, definition.script, framework, encoding);
|
98
|
+
}
|
99
|
+
default: {
|
100
|
+
const _exhaustive = definition;
|
101
|
+
throw new Error(`Unknown UI resource type: ${_exhaustive.type}`);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
__name(createUIResourceFromDefinition, "createUIResourceFromDefinition");
|
106
|
+
|
42
107
|
// src/server/mcp-server.ts
|
43
108
|
var McpServer = class {
|
44
109
|
static {
|
@@ -71,7 +136,7 @@ var McpServer = class {
|
|
71
136
|
this.app.use((req, res, next) => {
|
72
137
|
res.header("Access-Control-Allow-Origin", "*");
|
73
138
|
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
74
|
-
res.header("Access-Control-Allow-Headers", "Content-Type");
|
139
|
+
res.header("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization, mcp-protocol-version, mcp-session-id, X-Proxy-Token, X-Target-URL");
|
75
140
|
next();
|
76
141
|
});
|
77
142
|
this.app.use(requestLogger);
|
@@ -302,12 +367,196 @@ var McpServer = class {
|
|
302
367
|
);
|
303
368
|
return this;
|
304
369
|
}
|
370
|
+
/**
|
371
|
+
* Register a UI widget as both a tool and a resource
|
372
|
+
*
|
373
|
+
* Creates a unified interface for MCP-UI compatible widgets that can be accessed
|
374
|
+
* either as tools (with parameters) or as resources (static access). The tool
|
375
|
+
* allows dynamic parameter passing while the resource provides discoverable access.
|
376
|
+
*
|
377
|
+
* @param definition - Configuration for the UI widget
|
378
|
+
* @param definition.name - Unique identifier for the resource
|
379
|
+
* @param definition.widget - Widget name (matches directory in dist/resources/mcp-use/widgets)
|
380
|
+
* @param definition.title - Human-readable title for the widget
|
381
|
+
* @param definition.description - Description of the widget's functionality
|
382
|
+
* @param definition.props - Widget properties configuration with types and defaults
|
383
|
+
* @param definition.size - Preferred iframe size [width, height] (e.g., ['800px', '600px'])
|
384
|
+
* @param definition.annotations - Resource annotations for discovery
|
385
|
+
* @returns The server instance for method chaining
|
386
|
+
*
|
387
|
+
* @example
|
388
|
+
* ```typescript
|
389
|
+
* server.uiResource({
|
390
|
+
* name: 'kanban-board',
|
391
|
+
* widget: 'kanban-board',
|
392
|
+
* title: 'Kanban Board',
|
393
|
+
* description: 'Interactive task management board',
|
394
|
+
* props: {
|
395
|
+
* initialTasks: {
|
396
|
+
* type: 'array',
|
397
|
+
* description: 'Initial tasks to display',
|
398
|
+
* required: false
|
399
|
+
* },
|
400
|
+
* theme: {
|
401
|
+
* type: 'string',
|
402
|
+
* default: 'light'
|
403
|
+
* }
|
404
|
+
* },
|
405
|
+
* size: ['900px', '600px']
|
406
|
+
* })
|
407
|
+
* ```
|
408
|
+
*/
|
409
|
+
uiResource(definition) {
|
410
|
+
const toolName = definition.type === "externalUrl" ? `ui_${definition.widget}` : `ui_${definition.name}`;
|
411
|
+
const displayName = definition.title || definition.name;
|
412
|
+
let resourceUri;
|
413
|
+
let mimeType;
|
414
|
+
switch (definition.type) {
|
415
|
+
case "externalUrl":
|
416
|
+
resourceUri = `ui://widget/${definition.widget}`;
|
417
|
+
mimeType = "text/uri-list";
|
418
|
+
break;
|
419
|
+
case "rawHtml":
|
420
|
+
resourceUri = `ui://widget/${definition.name}`;
|
421
|
+
mimeType = "text/html";
|
422
|
+
break;
|
423
|
+
case "remoteDom":
|
424
|
+
resourceUri = `ui://widget/${definition.name}`;
|
425
|
+
mimeType = "application/vnd.mcp-ui.remote-dom+javascript";
|
426
|
+
break;
|
427
|
+
default:
|
428
|
+
throw new Error(`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom`);
|
429
|
+
}
|
430
|
+
this.resource({
|
431
|
+
name: definition.name,
|
432
|
+
uri: resourceUri,
|
433
|
+
title: definition.title,
|
434
|
+
description: definition.description,
|
435
|
+
mimeType,
|
436
|
+
annotations: definition.annotations,
|
437
|
+
fn: /* @__PURE__ */ __name(async () => {
|
438
|
+
const params = definition.type === "externalUrl" ? this.applyDefaultProps(definition.props) : {};
|
439
|
+
const uiResource = this.createWidgetUIResource(definition, params);
|
440
|
+
return {
|
441
|
+
contents: [uiResource.resource]
|
442
|
+
};
|
443
|
+
}, "fn")
|
444
|
+
});
|
445
|
+
this.tool({
|
446
|
+
name: toolName,
|
447
|
+
description: definition.description || `Display ${displayName}`,
|
448
|
+
inputs: this.convertPropsToInputs(definition.props),
|
449
|
+
fn: /* @__PURE__ */ __name(async (params) => {
|
450
|
+
const uiResource = this.createWidgetUIResource(definition, params);
|
451
|
+
return {
|
452
|
+
content: [
|
453
|
+
{
|
454
|
+
type: "text",
|
455
|
+
text: `Displaying ${displayName}`,
|
456
|
+
description: `Show MCP-UI widget for ${displayName}`
|
457
|
+
},
|
458
|
+
uiResource
|
459
|
+
]
|
460
|
+
};
|
461
|
+
}, "fn")
|
462
|
+
});
|
463
|
+
return this;
|
464
|
+
}
|
465
|
+
/**
|
466
|
+
* Create a UIResource object for a widget with the given parameters
|
467
|
+
*
|
468
|
+
* This method is shared between tool and resource handlers to avoid duplication.
|
469
|
+
* It creates a consistent UIResource structure that can be rendered by MCP-UI
|
470
|
+
* compatible clients.
|
471
|
+
*
|
472
|
+
* @private
|
473
|
+
* @param definition - UIResource definition
|
474
|
+
* @param params - Parameters to pass to the widget via URL
|
475
|
+
* @returns UIResource object compatible with MCP-UI
|
476
|
+
*/
|
477
|
+
createWidgetUIResource(definition, params) {
|
478
|
+
const urlConfig = {
|
479
|
+
baseUrl: "http://localhost",
|
480
|
+
port: this.serverPort || 3001
|
481
|
+
};
|
482
|
+
return createUIResourceFromDefinition(definition, params, urlConfig);
|
483
|
+
}
|
484
|
+
/**
|
485
|
+
* Build a complete URL for a widget including query parameters
|
486
|
+
*
|
487
|
+
* Constructs the full URL to access a widget's iframe, encoding any provided
|
488
|
+
* parameters as query string parameters. Complex objects are JSON-stringified
|
489
|
+
* for transmission.
|
490
|
+
*
|
491
|
+
* @private
|
492
|
+
* @param widget - Widget name/identifier
|
493
|
+
* @param params - Parameters to encode in the URL
|
494
|
+
* @returns Complete URL with encoded parameters
|
495
|
+
*/
|
496
|
+
buildWidgetUrl(widget, params) {
|
497
|
+
const baseUrl = `http://localhost:${this.serverPort}/mcp-use/widgets/${widget}`;
|
498
|
+
if (Object.keys(params).length === 0) {
|
499
|
+
return baseUrl;
|
500
|
+
}
|
501
|
+
const queryParams = new URLSearchParams();
|
502
|
+
for (const [key, value] of Object.entries(params)) {
|
503
|
+
if (value !== void 0 && value !== null) {
|
504
|
+
if (typeof value === "object") {
|
505
|
+
queryParams.append(key, JSON.stringify(value));
|
506
|
+
} else {
|
507
|
+
queryParams.append(key, String(value));
|
508
|
+
}
|
509
|
+
}
|
510
|
+
}
|
511
|
+
return `${baseUrl}?${queryParams.toString()}`;
|
512
|
+
}
|
513
|
+
/**
|
514
|
+
* Convert widget props definition to tool input schema
|
515
|
+
*
|
516
|
+
* Transforms the widget props configuration into the format expected by
|
517
|
+
* the tool registration system, mapping types and handling defaults.
|
518
|
+
*
|
519
|
+
* @private
|
520
|
+
* @param props - Widget props configuration
|
521
|
+
* @returns Array of InputDefinition objects for tool registration
|
522
|
+
*/
|
523
|
+
convertPropsToInputs(props) {
|
524
|
+
if (!props) return [];
|
525
|
+
return Object.entries(props).map(([name, prop]) => ({
|
526
|
+
name,
|
527
|
+
type: prop.type,
|
528
|
+
description: prop.description,
|
529
|
+
required: prop.required,
|
530
|
+
default: prop.default
|
531
|
+
}));
|
532
|
+
}
|
533
|
+
/**
|
534
|
+
* Apply default values to widget props
|
535
|
+
*
|
536
|
+
* Extracts default values from the props configuration to use when
|
537
|
+
* the resource is accessed without parameters.
|
538
|
+
*
|
539
|
+
* @private
|
540
|
+
* @param props - Widget props configuration
|
541
|
+
* @returns Object with default values for each prop
|
542
|
+
*/
|
543
|
+
applyDefaultProps(props) {
|
544
|
+
if (!props) return {};
|
545
|
+
const defaults = {};
|
546
|
+
for (const [key, prop] of Object.entries(props)) {
|
547
|
+
if (prop.default !== void 0) {
|
548
|
+
defaults[key] = prop.default;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
return defaults;
|
552
|
+
}
|
305
553
|
/**
|
306
554
|
* Mount MCP server endpoints at /mcp
|
307
555
|
*
|
308
556
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
309
557
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
310
|
-
*
|
558
|
+
* Each request gets its own transport instance to prevent state conflicts between
|
559
|
+
* concurrent client connections.
|
311
560
|
*
|
312
561
|
* This method is called automatically when the server starts listening and ensures
|
313
562
|
* that MCP clients can communicate with the server over HTTP.
|
@@ -324,20 +573,39 @@ var McpServer = class {
|
|
324
573
|
async mountMcp() {
|
325
574
|
if (this.mcpMounted) return;
|
326
575
|
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
327
|
-
const httpTransport = new StreamableHTTPServerTransport({
|
328
|
-
sessionIdGenerator: void 0
|
329
|
-
// Stateless mode
|
330
|
-
});
|
331
|
-
await this.server.connect(httpTransport);
|
332
576
|
const endpoint = "/mcp";
|
333
|
-
this.app.get(endpoint, async (req, res) => {
|
334
|
-
await httpTransport.handleRequest(req, res);
|
335
|
-
});
|
336
577
|
this.app.post(endpoint, express.json(), async (req, res) => {
|
337
|
-
|
578
|
+
const transport = new StreamableHTTPServerTransport({
|
579
|
+
sessionIdGenerator: void 0,
|
580
|
+
enableJsonResponse: true
|
581
|
+
});
|
582
|
+
res.on("close", () => {
|
583
|
+
transport.close();
|
584
|
+
});
|
585
|
+
await this.server.connect(transport);
|
586
|
+
await transport.handleRequest(req, res, req.body);
|
587
|
+
});
|
588
|
+
this.app.get(endpoint, async (req, res) => {
|
589
|
+
const transport = new StreamableHTTPServerTransport({
|
590
|
+
sessionIdGenerator: void 0,
|
591
|
+
enableJsonResponse: true
|
592
|
+
});
|
593
|
+
res.on("close", () => {
|
594
|
+
transport.close();
|
595
|
+
});
|
596
|
+
await this.server.connect(transport);
|
597
|
+
await transport.handleRequest(req, res);
|
338
598
|
});
|
339
599
|
this.app.delete(endpoint, async (req, res) => {
|
340
|
-
|
600
|
+
const transport = new StreamableHTTPServerTransport({
|
601
|
+
sessionIdGenerator: void 0,
|
602
|
+
enableJsonResponse: true
|
603
|
+
});
|
604
|
+
res.on("close", () => {
|
605
|
+
transport.close();
|
606
|
+
});
|
607
|
+
await this.server.connect(transport);
|
608
|
+
await transport.handleRequest(req, res);
|
341
609
|
});
|
342
610
|
this.mcpMounted = true;
|
343
611
|
console.log(`[MCP] Server mounted at ${endpoint}`);
|
@@ -639,5 +907,10 @@ function createMCPServer(name, config = {}) {
|
|
639
907
|
}
|
640
908
|
__name(createMCPServer, "createMCPServer");
|
641
909
|
export {
|
642
|
-
|
910
|
+
buildWidgetUrl,
|
911
|
+
createExternalUrlResource,
|
912
|
+
createMCPServer,
|
913
|
+
createRawHtmlResource,
|
914
|
+
createRemoteDomResource,
|
915
|
+
createUIResourceFromDefinition
|
643
916
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ServerConfig, ToolDefinition } from './types.js';
|
1
|
+
import type { PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ServerConfig, ToolDefinition, UIResourceDefinition } from './types/index.js';
|
2
2
|
import { type Express } from 'express';
|
3
3
|
export declare class McpServer {
|
4
4
|
private server;
|
@@ -157,12 +157,101 @@ export declare class McpServer {
|
|
157
157
|
* ```
|
158
158
|
*/
|
159
159
|
prompt(promptDefinition: PromptDefinition): this;
|
160
|
+
/**
|
161
|
+
* Register a UI widget as both a tool and a resource
|
162
|
+
*
|
163
|
+
* Creates a unified interface for MCP-UI compatible widgets that can be accessed
|
164
|
+
* either as tools (with parameters) or as resources (static access). The tool
|
165
|
+
* allows dynamic parameter passing while the resource provides discoverable access.
|
166
|
+
*
|
167
|
+
* @param definition - Configuration for the UI widget
|
168
|
+
* @param definition.name - Unique identifier for the resource
|
169
|
+
* @param definition.widget - Widget name (matches directory in dist/resources/mcp-use/widgets)
|
170
|
+
* @param definition.title - Human-readable title for the widget
|
171
|
+
* @param definition.description - Description of the widget's functionality
|
172
|
+
* @param definition.props - Widget properties configuration with types and defaults
|
173
|
+
* @param definition.size - Preferred iframe size [width, height] (e.g., ['800px', '600px'])
|
174
|
+
* @param definition.annotations - Resource annotations for discovery
|
175
|
+
* @returns The server instance for method chaining
|
176
|
+
*
|
177
|
+
* @example
|
178
|
+
* ```typescript
|
179
|
+
* server.uiResource({
|
180
|
+
* name: 'kanban-board',
|
181
|
+
* widget: 'kanban-board',
|
182
|
+
* title: 'Kanban Board',
|
183
|
+
* description: 'Interactive task management board',
|
184
|
+
* props: {
|
185
|
+
* initialTasks: {
|
186
|
+
* type: 'array',
|
187
|
+
* description: 'Initial tasks to display',
|
188
|
+
* required: false
|
189
|
+
* },
|
190
|
+
* theme: {
|
191
|
+
* type: 'string',
|
192
|
+
* default: 'light'
|
193
|
+
* }
|
194
|
+
* },
|
195
|
+
* size: ['900px', '600px']
|
196
|
+
* })
|
197
|
+
* ```
|
198
|
+
*/
|
199
|
+
uiResource(definition: UIResourceDefinition): this;
|
200
|
+
/**
|
201
|
+
* Create a UIResource object for a widget with the given parameters
|
202
|
+
*
|
203
|
+
* This method is shared between tool and resource handlers to avoid duplication.
|
204
|
+
* It creates a consistent UIResource structure that can be rendered by MCP-UI
|
205
|
+
* compatible clients.
|
206
|
+
*
|
207
|
+
* @private
|
208
|
+
* @param definition - UIResource definition
|
209
|
+
* @param params - Parameters to pass to the widget via URL
|
210
|
+
* @returns UIResource object compatible with MCP-UI
|
211
|
+
*/
|
212
|
+
private createWidgetUIResource;
|
213
|
+
/**
|
214
|
+
* Build a complete URL for a widget including query parameters
|
215
|
+
*
|
216
|
+
* Constructs the full URL to access a widget's iframe, encoding any provided
|
217
|
+
* parameters as query string parameters. Complex objects are JSON-stringified
|
218
|
+
* for transmission.
|
219
|
+
*
|
220
|
+
* @private
|
221
|
+
* @param widget - Widget name/identifier
|
222
|
+
* @param params - Parameters to encode in the URL
|
223
|
+
* @returns Complete URL with encoded parameters
|
224
|
+
*/
|
225
|
+
private buildWidgetUrl;
|
226
|
+
/**
|
227
|
+
* Convert widget props definition to tool input schema
|
228
|
+
*
|
229
|
+
* Transforms the widget props configuration into the format expected by
|
230
|
+
* the tool registration system, mapping types and handling defaults.
|
231
|
+
*
|
232
|
+
* @private
|
233
|
+
* @param props - Widget props configuration
|
234
|
+
* @returns Array of InputDefinition objects for tool registration
|
235
|
+
*/
|
236
|
+
private convertPropsToInputs;
|
237
|
+
/**
|
238
|
+
* Apply default values to widget props
|
239
|
+
*
|
240
|
+
* Extracts default values from the props configuration to use when
|
241
|
+
* the resource is accessed without parameters.
|
242
|
+
*
|
243
|
+
* @private
|
244
|
+
* @param props - Widget props configuration
|
245
|
+
* @returns Object with default values for each prop
|
246
|
+
*/
|
247
|
+
private applyDefaultProps;
|
160
248
|
/**
|
161
249
|
* Mount MCP server endpoints at /mcp
|
162
250
|
*
|
163
251
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
164
252
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
165
|
-
*
|
253
|
+
* Each request gets its own transport instance to prevent state conflicts between
|
254
|
+
* concurrent client connections.
|
166
255
|
*
|
167
256
|
* This method is called automatically when the server starts listening and ensures
|
168
257
|
* that MCP clients can communicate with the server over HTTP.
|
@@ -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,
|
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,EACd,oBAAoB,EAIrB,MAAM,kBAAkB,CAAA;AAGzB,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAM/C,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,UAAU,CAAC,CAAQ;IAE3B;;;;;;;;;OASG;gBACS,MAAM,EAAE,YAAY;IAsChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,IAAI;IAkBtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,gBAAgB,CAAC,0BAA0B,EAAE,0BAA0B,GAAG,IAAI;IA4C9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAa1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI;IAahD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,UAAU,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI;IAyElD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,cAAc;IAsBtB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;;;;;;;;OASG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;;;;;;;;;;;;;;;;;OAmBG;YACW,QAAQ;IAyDtB;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,cAAc;IAqBtB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,iBAAiB;IAsCzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,qBAAqB;IAmC7B;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,sBAAsB;IAmC9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,gBAAgB;CAyBzB;AAED,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"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* Common type definitions shared across different MCP components
|
3
|
+
*/
|
4
|
+
export interface ServerConfig {
|
5
|
+
name: string;
|
6
|
+
version: string;
|
7
|
+
description?: string;
|
8
|
+
}
|
9
|
+
export interface InputDefinition {
|
10
|
+
name: string;
|
11
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
12
|
+
description?: string;
|
13
|
+
required?: boolean;
|
14
|
+
default?: any;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Annotations provide hints to clients about how to use or display resources
|
18
|
+
*/
|
19
|
+
export interface ResourceAnnotations {
|
20
|
+
/** Intended audience(s) for this resource */
|
21
|
+
audience?: ('user' | 'assistant')[];
|
22
|
+
/** Priority from 0.0 (least important) to 1.0 (most important) */
|
23
|
+
priority?: number;
|
24
|
+
/** ISO 8601 formatted timestamp of last modification */
|
25
|
+
lastModified?: string;
|
26
|
+
}
|
27
|
+
//# sourceMappingURL=common.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/server/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,GAAG,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAA;IACnC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Centralized type exports for MCP server
|
3
|
+
*/
|
4
|
+
export { ServerConfig, InputDefinition, ResourceAnnotations } from './common.js';
|
5
|
+
export { ResourceHandler, ResourceTemplateHandler, ResourceTemplateConfig, ResourceTemplateDefinition, ResourceDefinition, UIResourceContent, WidgetProps, UIEncoding, RemoteDomFramework, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions } from './resource.js';
|
6
|
+
export { ToolHandler, ToolDefinition } from './tool.js';
|
7
|
+
export { PromptHandler, PromptDefinition } from './prompt.js';
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +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,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,kBAAkB,EAElB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,sBAAsB,EACvB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,WAAW,EACX,cAAc,EACf,MAAM,WAAW,CAAA;AAGlB,OAAO,EACL,aAAa,EACb,gBAAgB,EACjB,MAAM,aAAa,CAAA"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
|
2
|
+
import type { InputDefinition } from './common.js';
|
3
|
+
export type PromptHandler = (params: Record<string, any>) => Promise<GetPromptResult>;
|
4
|
+
export interface PromptDefinition {
|
5
|
+
/** Unique identifier for the prompt */
|
6
|
+
name: string;
|
7
|
+
/** Description of what the prompt does */
|
8
|
+
description?: string;
|
9
|
+
/** Argument definitions */
|
10
|
+
args?: InputDefinition[];
|
11
|
+
/** Async function that generates the prompt */
|
12
|
+
fn: PromptHandler;
|
13
|
+
}
|
14
|
+
//# sourceMappingURL=prompt.d.ts.map
|
@@ -0,0 +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,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;AAErF,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,eAAe,EAAE,CAAA;IACxB,+CAA+C;IAC/C,EAAE,EAAE,aAAa,CAAA;CAClB"}
|
@@ -0,0 +1,155 @@
|
|
1
|
+
import type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
2
|
+
import type { ResourceAnnotations } from './common.js';
|
3
|
+
export type UIResourceContent = {
|
4
|
+
type: 'resource';
|
5
|
+
resource: {
|
6
|
+
uri: string;
|
7
|
+
mimeType: string;
|
8
|
+
} & ({
|
9
|
+
text: string;
|
10
|
+
blob?: never;
|
11
|
+
} | {
|
12
|
+
blob: string;
|
13
|
+
text?: never;
|
14
|
+
});
|
15
|
+
};
|
16
|
+
export type ResourceHandler = () => Promise<ReadResourceResult>;
|
17
|
+
export type ResourceTemplateHandler = (uri: URL, params: Record<string, any>) => Promise<ReadResourceResult>;
|
18
|
+
/**
|
19
|
+
* Configuration for a resource template
|
20
|
+
*/
|
21
|
+
export interface ResourceTemplateConfig {
|
22
|
+
/** URI template with {param} placeholders (e.g., "user://{userId}/profile") */
|
23
|
+
uriTemplate: string;
|
24
|
+
/** Name of the resource */
|
25
|
+
name?: string;
|
26
|
+
/** MIME type of the resource content */
|
27
|
+
mimeType?: string;
|
28
|
+
/** Description of the resource */
|
29
|
+
description?: string;
|
30
|
+
}
|
31
|
+
export interface ResourceTemplateDefinition {
|
32
|
+
name: string;
|
33
|
+
resourceTemplate: ResourceTemplateConfig;
|
34
|
+
title?: string;
|
35
|
+
description?: string;
|
36
|
+
annotations?: ResourceAnnotations;
|
37
|
+
fn: ResourceTemplateHandler;
|
38
|
+
}
|
39
|
+
export interface ResourceDefinition {
|
40
|
+
/** Unique identifier for the resource */
|
41
|
+
name: string;
|
42
|
+
/** URI pattern for accessing the resource (e.g., 'config://app-settings') */
|
43
|
+
uri: string;
|
44
|
+
/** Optional title for the resource */
|
45
|
+
title?: string;
|
46
|
+
/** Optional description of the resource */
|
47
|
+
description?: string;
|
48
|
+
/** MIME type of the resource content (required) */
|
49
|
+
mimeType: string;
|
50
|
+
/** Optional annotations for the resource */
|
51
|
+
annotations?: ResourceAnnotations;
|
52
|
+
/** Async function that returns the resource content */
|
53
|
+
fn: ResourceHandler;
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* UIResource-specific types
|
57
|
+
*/
|
58
|
+
export interface WidgetProps {
|
59
|
+
[key: string]: {
|
60
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
61
|
+
required?: boolean;
|
62
|
+
default?: any;
|
63
|
+
description?: string;
|
64
|
+
};
|
65
|
+
}
|
66
|
+
/**
|
67
|
+
* Encoding options for UI resources
|
68
|
+
*/
|
69
|
+
export type UIEncoding = 'text' | 'blob';
|
70
|
+
/**
|
71
|
+
* Framework options for Remote DOM resources
|
72
|
+
*/
|
73
|
+
export type RemoteDomFramework = 'react' | 'webcomponents';
|
74
|
+
/**
|
75
|
+
* Base properties shared by all UI resource types
|
76
|
+
*/
|
77
|
+
interface BaseUIResourceDefinition {
|
78
|
+
/** Unique identifier for the resource */
|
79
|
+
name: string;
|
80
|
+
/** Human-readable title */
|
81
|
+
title?: string;
|
82
|
+
/** Description of what the widget does */
|
83
|
+
description?: string;
|
84
|
+
/** Widget properties/parameters configuration */
|
85
|
+
props?: WidgetProps;
|
86
|
+
/** Preferred frame size [width, height] (e.g., ['800px', '600px']) */
|
87
|
+
size?: [string, string];
|
88
|
+
/** Resource annotations for discovery and presentation */
|
89
|
+
annotations?: ResourceAnnotations;
|
90
|
+
/** Encoding for the resource content (defaults to 'text') */
|
91
|
+
encoding?: UIEncoding;
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* External URL UI resource - serves widget via iframe
|
95
|
+
*/
|
96
|
+
export interface ExternalUrlUIResource extends BaseUIResourceDefinition {
|
97
|
+
type: 'externalUrl';
|
98
|
+
/** Widget identifier (e.g., 'kanban-board', 'chart') */
|
99
|
+
widget: string;
|
100
|
+
}
|
101
|
+
/**
|
102
|
+
* Raw HTML UI resource - direct HTML content
|
103
|
+
*/
|
104
|
+
export interface RawHtmlUIResource extends BaseUIResourceDefinition {
|
105
|
+
type: 'rawHtml';
|
106
|
+
/** HTML content to render */
|
107
|
+
htmlContent: string;
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* Remote DOM UI resource - scripted UI components
|
111
|
+
*/
|
112
|
+
export interface RemoteDomUIResource extends BaseUIResourceDefinition {
|
113
|
+
type: 'remoteDom';
|
114
|
+
/** JavaScript code for remote DOM manipulation */
|
115
|
+
script: string;
|
116
|
+
/** Framework for remote DOM (defaults to 'react') */
|
117
|
+
framework?: RemoteDomFramework;
|
118
|
+
}
|
119
|
+
/**
|
120
|
+
* Discriminated union of all UI resource types
|
121
|
+
*/
|
122
|
+
export type UIResourceDefinition = ExternalUrlUIResource | RawHtmlUIResource | RemoteDomUIResource;
|
123
|
+
export interface WidgetConfig {
|
124
|
+
/** Widget directory name */
|
125
|
+
name: string;
|
126
|
+
/** Absolute path to widget directory */
|
127
|
+
path: string;
|
128
|
+
/** Widget manifest if present */
|
129
|
+
manifest?: WidgetManifest;
|
130
|
+
/** Main component file name */
|
131
|
+
component?: string;
|
132
|
+
}
|
133
|
+
export interface WidgetManifest {
|
134
|
+
name: string;
|
135
|
+
title?: string;
|
136
|
+
description?: string;
|
137
|
+
version?: string;
|
138
|
+
props?: WidgetProps;
|
139
|
+
size?: [string, string];
|
140
|
+
assets?: {
|
141
|
+
main?: string;
|
142
|
+
scripts?: string[];
|
143
|
+
styles?: string[];
|
144
|
+
};
|
145
|
+
}
|
146
|
+
export interface DiscoverWidgetsOptions {
|
147
|
+
/** Path to widgets directory (defaults to dist/resources/mcp-use/widgets) */
|
148
|
+
path?: string;
|
149
|
+
/** Automatically register widgets without manifests */
|
150
|
+
autoRegister?: boolean;
|
151
|
+
/** Filter widgets by name pattern */
|
152
|
+
filter?: string | RegExp;
|
153
|
+
}
|
154
|
+
export {};
|
155
|
+
//# sourceMappingURL=resource.d.ts.map
|