mcp-use 1.1.5 → 1.1.6-canary.1
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.
|
@@ -44,6 +44,7 @@ module.exports = __toCommonJS(server_exports);
|
|
|
44
44
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
45
45
|
var import_zod = require("zod");
|
|
46
46
|
var import_express = __toESM(require("express"), 1);
|
|
47
|
+
var import_cors = __toESM(require("cors"), 1);
|
|
47
48
|
var import_node_fs = require("fs");
|
|
48
49
|
var import_node_path = require("path");
|
|
49
50
|
|
|
@@ -202,11 +203,11 @@ var McpServer = class {
|
|
|
202
203
|
serverPort;
|
|
203
204
|
/**
|
|
204
205
|
* Creates a new MCP server instance with Express integration
|
|
205
|
-
*
|
|
206
|
+
*
|
|
206
207
|
* Initializes the server with the provided configuration, sets up CORS headers,
|
|
207
208
|
* configures widget serving routes, and creates a proxy that allows direct
|
|
208
209
|
* access to Express methods while preserving MCP server functionality.
|
|
209
|
-
*
|
|
210
|
+
*
|
|
210
211
|
* @param config - Server configuration including name, version, and description
|
|
211
212
|
* @returns A proxied McpServer instance that supports both MCP and Express methods
|
|
212
213
|
*/
|
|
@@ -218,12 +219,11 @@ var McpServer = class {
|
|
|
218
219
|
});
|
|
219
220
|
this.app = (0, import_express.default)();
|
|
220
221
|
this.app.use(import_express.default.json());
|
|
221
|
-
this.app.use((
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
});
|
|
222
|
+
this.app.use((0, import_cors.default)({
|
|
223
|
+
origin: "*",
|
|
224
|
+
methods: ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
225
|
+
allowedHeaders: ["Content-Type", "Accept", "Authorization", "mcp-protocol-version", "mcp-session-id", "X-Proxy-Token", "X-Target-URL"]
|
|
226
|
+
}));
|
|
227
227
|
this.app.use(requestLogger);
|
|
228
228
|
this.setupWidgetRoutes();
|
|
229
229
|
return new Proxy(this, {
|
|
@@ -238,11 +238,11 @@ var McpServer = class {
|
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* Define a static resource that can be accessed by clients
|
|
241
|
-
*
|
|
241
|
+
*
|
|
242
242
|
* Registers a resource with the MCP server that clients can access via HTTP.
|
|
243
243
|
* Resources are static content like files, data, or pre-computed results that
|
|
244
244
|
* can be retrieved by clients without requiring parameters.
|
|
245
|
-
*
|
|
245
|
+
*
|
|
246
246
|
* @param resourceDefinition - Configuration object containing resource metadata and handler function
|
|
247
247
|
* @param resourceDefinition.name - Unique identifier for the resource
|
|
248
248
|
* @param resourceDefinition.uri - URI pattern for accessing the resource
|
|
@@ -252,7 +252,7 @@ var McpServer = class {
|
|
|
252
252
|
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
|
253
253
|
* @param resourceDefinition.readCallback - Async callback function that returns the resource content
|
|
254
254
|
* @returns The server instance for method chaining
|
|
255
|
-
*
|
|
255
|
+
*
|
|
256
256
|
* @example
|
|
257
257
|
* ```typescript
|
|
258
258
|
* server.resource({
|
|
@@ -294,17 +294,17 @@ var McpServer = class {
|
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
296
296
|
* Define a dynamic resource template with parameters
|
|
297
|
-
*
|
|
297
|
+
*
|
|
298
298
|
* Registers a parameterized resource template with the MCP server. Templates use URI
|
|
299
299
|
* patterns with placeholders that can be filled in at request time, allowing dynamic
|
|
300
300
|
* resource generation based on parameters.
|
|
301
|
-
*
|
|
301
|
+
*
|
|
302
302
|
* @param resourceTemplateDefinition - Configuration object for the resource template
|
|
303
303
|
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
|
304
304
|
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
|
305
305
|
* @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
|
|
306
306
|
* @returns The server instance for method chaining
|
|
307
|
-
*
|
|
307
|
+
*
|
|
308
308
|
* @example
|
|
309
309
|
* ```typescript
|
|
310
310
|
* server.resourceTemplate({
|
|
@@ -366,13 +366,13 @@ var McpServer = class {
|
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
368
|
* Define a tool that can be called by clients
|
|
369
|
-
*
|
|
369
|
+
*
|
|
370
370
|
* Registers a tool with the MCP server that clients can invoke with parameters.
|
|
371
371
|
* Tools are functions that perform actions, computations, or operations and
|
|
372
372
|
* return results. They accept structured input parameters and return structured output.
|
|
373
|
-
*
|
|
373
|
+
*
|
|
374
374
|
* Supports Apps SDK metadata for ChatGPT integration via the _meta field.
|
|
375
|
-
*
|
|
375
|
+
*
|
|
376
376
|
* @param toolDefinition - Configuration object containing tool metadata and handler function
|
|
377
377
|
* @param toolDefinition.name - Unique identifier for the tool
|
|
378
378
|
* @param toolDefinition.description - Human-readable description of what the tool does
|
|
@@ -380,7 +380,7 @@ var McpServer = class {
|
|
|
380
380
|
* @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
|
|
381
381
|
* @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
|
|
382
382
|
* @returns The server instance for method chaining
|
|
383
|
-
*
|
|
383
|
+
*
|
|
384
384
|
* @example
|
|
385
385
|
* ```typescript
|
|
386
386
|
* server.tool({
|
|
@@ -421,18 +421,18 @@ var McpServer = class {
|
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
423
423
|
* Define a prompt template
|
|
424
|
-
*
|
|
424
|
+
*
|
|
425
425
|
* Registers a prompt template with the MCP server that clients can use to generate
|
|
426
426
|
* structured prompts for AI models. Prompt templates accept parameters and return
|
|
427
427
|
* formatted text that can be used as input to language models or other AI systems.
|
|
428
|
-
*
|
|
428
|
+
*
|
|
429
429
|
* @param promptDefinition - Configuration object containing prompt metadata and handler function
|
|
430
430
|
* @param promptDefinition.name - Unique identifier for the prompt template
|
|
431
431
|
* @param promptDefinition.description - Human-readable description of the prompt's purpose
|
|
432
432
|
* @param promptDefinition.args - Array of argument definitions with types and validation
|
|
433
433
|
* @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
|
|
434
434
|
* @returns The server instance for method chaining
|
|
435
|
-
*
|
|
435
|
+
*
|
|
436
436
|
* @example
|
|
437
437
|
* ```typescript
|
|
438
438
|
* server.prompt({
|
|
@@ -510,7 +510,7 @@ var McpServer = class {
|
|
|
510
510
|
* },
|
|
511
511
|
* size: ['900px', '600px']
|
|
512
512
|
* })
|
|
513
|
-
*
|
|
513
|
+
*
|
|
514
514
|
* // Apps SDK widget
|
|
515
515
|
* server.uiResource({
|
|
516
516
|
* type: 'appsSdk',
|
|
@@ -720,18 +720,18 @@ var McpServer = class {
|
|
|
720
720
|
}
|
|
721
721
|
/**
|
|
722
722
|
* Mount MCP server endpoints at /mcp
|
|
723
|
-
*
|
|
723
|
+
*
|
|
724
724
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
|
725
725
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
|
726
726
|
* Each request gets its own transport instance to prevent state conflicts between
|
|
727
727
|
* concurrent client connections.
|
|
728
|
-
*
|
|
728
|
+
*
|
|
729
729
|
* This method is called automatically when the server starts listening and ensures
|
|
730
730
|
* that MCP clients can communicate with the server over HTTP.
|
|
731
|
-
*
|
|
731
|
+
*
|
|
732
732
|
* @private
|
|
733
733
|
* @returns Promise that resolves when MCP endpoints are successfully mounted
|
|
734
|
-
*
|
|
734
|
+
*
|
|
735
735
|
* @example
|
|
736
736
|
* Endpoints created:
|
|
737
737
|
* - GET /mcp - SSE streaming endpoint for real-time communication
|
|
@@ -780,17 +780,17 @@ var McpServer = class {
|
|
|
780
780
|
}
|
|
781
781
|
/**
|
|
782
782
|
* Start the Express server with MCP endpoints
|
|
783
|
-
*
|
|
783
|
+
*
|
|
784
784
|
* Initiates the server startup process by mounting MCP endpoints, configuring
|
|
785
785
|
* the inspector UI (if available), and starting the Express server to listen
|
|
786
786
|
* for incoming connections. This is the main entry point for running the server.
|
|
787
|
-
*
|
|
787
|
+
*
|
|
788
788
|
* The server will be accessible at the specified port with MCP endpoints at /mcp
|
|
789
789
|
* and inspector UI at /inspector (if the inspector package is installed).
|
|
790
|
-
*
|
|
790
|
+
*
|
|
791
791
|
* @param port - Port number to listen on (defaults to 3001 if not specified)
|
|
792
792
|
* @returns Promise that resolves when the server is successfully listening
|
|
793
|
-
*
|
|
793
|
+
*
|
|
794
794
|
* @example
|
|
795
795
|
* ```typescript
|
|
796
796
|
* await server.listen(8080)
|
|
@@ -810,22 +810,22 @@ var McpServer = class {
|
|
|
810
810
|
}
|
|
811
811
|
/**
|
|
812
812
|
* Mount MCP Inspector UI at /inspector
|
|
813
|
-
*
|
|
813
|
+
*
|
|
814
814
|
* Dynamically loads and mounts the MCP Inspector UI package if available, providing
|
|
815
815
|
* a web-based interface for testing and debugging MCP servers. The inspector
|
|
816
816
|
* automatically connects to the local MCP server endpoints.
|
|
817
|
-
*
|
|
817
|
+
*
|
|
818
818
|
* This method gracefully handles cases where the inspector package is not installed,
|
|
819
819
|
* allowing the server to function without the inspector in production environments.
|
|
820
|
-
*
|
|
820
|
+
*
|
|
821
821
|
* @private
|
|
822
822
|
* @returns void
|
|
823
|
-
*
|
|
823
|
+
*
|
|
824
824
|
* @example
|
|
825
825
|
* If @mcp-use/inspector is installed:
|
|
826
826
|
* - Inspector UI available at http://localhost:PORT/inspector
|
|
827
827
|
* - Automatically connects to http://localhost:PORT/mcp
|
|
828
|
-
*
|
|
828
|
+
*
|
|
829
829
|
* If not installed:
|
|
830
830
|
* - Server continues to function normally
|
|
831
831
|
* - No inspector UI available
|
|
@@ -841,19 +841,19 @@ var McpServer = class {
|
|
|
841
841
|
}
|
|
842
842
|
/**
|
|
843
843
|
* Setup default widget serving routes
|
|
844
|
-
*
|
|
844
|
+
*
|
|
845
845
|
* Configures Express routes to serve MCP UI widgets and their static assets.
|
|
846
846
|
* Widgets are served from the dist/resources/mcp-use/widgets directory and can
|
|
847
847
|
* be accessed via HTTP endpoints for embedding in web applications.
|
|
848
|
-
*
|
|
848
|
+
*
|
|
849
849
|
* Routes created:
|
|
850
850
|
* - GET /mcp-use/widgets/:widget - Serves widget's index.html
|
|
851
851
|
* - GET /mcp-use/widgets/:widget/assets/* - Serves widget-specific assets
|
|
852
852
|
* - GET /mcp-use/widgets/assets/* - Fallback asset serving with auto-discovery
|
|
853
|
-
*
|
|
853
|
+
*
|
|
854
854
|
* @private
|
|
855
855
|
* @returns void
|
|
856
|
-
*
|
|
856
|
+
*
|
|
857
857
|
* @example
|
|
858
858
|
* Widget routes:
|
|
859
859
|
* - http://localhost:3001/mcp-use/widgets/kanban-board
|
|
@@ -890,14 +890,14 @@ var McpServer = class {
|
|
|
890
890
|
}
|
|
891
891
|
/**
|
|
892
892
|
* Create input schema for resource templates
|
|
893
|
-
*
|
|
893
|
+
*
|
|
894
894
|
* Parses a URI template string to extract parameter names and generates a Zod
|
|
895
895
|
* validation schema for those parameters. Used internally for validating resource
|
|
896
896
|
* template parameters before processing requests.
|
|
897
|
-
*
|
|
897
|
+
*
|
|
898
898
|
* @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
|
|
899
899
|
* @returns Object mapping parameter names to Zod string schemas
|
|
900
|
-
*
|
|
900
|
+
*
|
|
901
901
|
* @example
|
|
902
902
|
* ```typescript
|
|
903
903
|
* const schema = this.createInputSchema("/users/{id}/posts/{postId}")
|
|
@@ -914,14 +914,14 @@ var McpServer = class {
|
|
|
914
914
|
}
|
|
915
915
|
/**
|
|
916
916
|
* Create input schema for tools
|
|
917
|
-
*
|
|
917
|
+
*
|
|
918
918
|
* Converts tool input definitions into Zod validation schemas for runtime validation.
|
|
919
919
|
* Supports common data types (string, number, boolean, object, array) and optional
|
|
920
920
|
* parameters. Used internally when registering tools with the MCP server.
|
|
921
|
-
*
|
|
921
|
+
*
|
|
922
922
|
* @param inputs - Array of input parameter definitions with name, type, and optional flag
|
|
923
923
|
* @returns Object mapping parameter names to Zod validation schemas
|
|
924
|
-
*
|
|
924
|
+
*
|
|
925
925
|
* @example
|
|
926
926
|
* ```typescript
|
|
927
927
|
* const schema = this.createToolInputSchema([
|
|
@@ -966,14 +966,14 @@ var McpServer = class {
|
|
|
966
966
|
}
|
|
967
967
|
/**
|
|
968
968
|
* Create arguments schema for prompts
|
|
969
|
-
*
|
|
969
|
+
*
|
|
970
970
|
* Converts prompt argument definitions into Zod validation schemas for runtime validation.
|
|
971
971
|
* Supports common data types (string, number, boolean, object, array) and optional
|
|
972
972
|
* parameters. Used internally when registering prompt templates with the MCP server.
|
|
973
|
-
*
|
|
973
|
+
*
|
|
974
974
|
* @param inputs - Array of argument definitions with name, type, and optional flag
|
|
975
975
|
* @returns Object mapping argument names to Zod validation schemas
|
|
976
|
-
*
|
|
976
|
+
*
|
|
977
977
|
* @example
|
|
978
978
|
* ```typescript
|
|
979
979
|
* const schema = this.createPromptArgsSchema([
|
|
@@ -1015,14 +1015,14 @@ var McpServer = class {
|
|
|
1015
1015
|
}
|
|
1016
1016
|
/**
|
|
1017
1017
|
* Extract parameter names from URI template
|
|
1018
|
-
*
|
|
1018
|
+
*
|
|
1019
1019
|
* Parses a URI template string to extract parameter names enclosed in curly braces.
|
|
1020
1020
|
* Used internally to identify dynamic parameters in resource templates and generate
|
|
1021
1021
|
* appropriate validation schemas.
|
|
1022
|
-
*
|
|
1022
|
+
*
|
|
1023
1023
|
* @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
|
|
1024
1024
|
* @returns Array of parameter names found in the template
|
|
1025
|
-
*
|
|
1025
|
+
*
|
|
1026
1026
|
* @example
|
|
1027
1027
|
* ```typescript
|
|
1028
1028
|
* const params = this.extractTemplateParams("/users/{id}/posts/{postId}")
|
|
@@ -1035,14 +1035,14 @@ var McpServer = class {
|
|
|
1035
1035
|
}
|
|
1036
1036
|
/**
|
|
1037
1037
|
* Parse parameter values from a URI based on a template
|
|
1038
|
-
*
|
|
1038
|
+
*
|
|
1039
1039
|
* Extracts parameter values from an actual URI by matching it against a URI template.
|
|
1040
1040
|
* The template contains placeholders like {param} which are extracted as key-value pairs.
|
|
1041
|
-
*
|
|
1041
|
+
*
|
|
1042
1042
|
* @param template - URI template with placeholders (e.g., "user://{userId}/posts/{postId}")
|
|
1043
1043
|
* @param uri - Actual URI to parse (e.g., "user://123/posts/456")
|
|
1044
1044
|
* @returns Object mapping parameter names to their values
|
|
1045
|
-
*
|
|
1045
|
+
*
|
|
1046
1046
|
* @example
|
|
1047
1047
|
* ```typescript
|
|
1048
1048
|
* const params = this.parseTemplateUri("user://{userId}/posts/{postId}", "user://123/posts/456")
|
package/dist/src/server/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import { McpServer as OfficialMcpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import express from "express";
|
|
9
|
+
import cors from "cors";
|
|
9
10
|
import { existsSync, readdirSync } from "fs";
|
|
10
11
|
import { join } from "path";
|
|
11
12
|
|
|
@@ -164,11 +165,11 @@ var McpServer = class {
|
|
|
164
165
|
serverPort;
|
|
165
166
|
/**
|
|
166
167
|
* Creates a new MCP server instance with Express integration
|
|
167
|
-
*
|
|
168
|
+
*
|
|
168
169
|
* Initializes the server with the provided configuration, sets up CORS headers,
|
|
169
170
|
* configures widget serving routes, and creates a proxy that allows direct
|
|
170
171
|
* access to Express methods while preserving MCP server functionality.
|
|
171
|
-
*
|
|
172
|
+
*
|
|
172
173
|
* @param config - Server configuration including name, version, and description
|
|
173
174
|
* @returns A proxied McpServer instance that supports both MCP and Express methods
|
|
174
175
|
*/
|
|
@@ -180,12 +181,11 @@ var McpServer = class {
|
|
|
180
181
|
});
|
|
181
182
|
this.app = express();
|
|
182
183
|
this.app.use(express.json());
|
|
183
|
-
this.app.use((
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
});
|
|
184
|
+
this.app.use(cors({
|
|
185
|
+
origin: "*",
|
|
186
|
+
methods: ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
187
|
+
allowedHeaders: ["Content-Type", "Accept", "Authorization", "mcp-protocol-version", "mcp-session-id", "X-Proxy-Token", "X-Target-URL"]
|
|
188
|
+
}));
|
|
189
189
|
this.app.use(requestLogger);
|
|
190
190
|
this.setupWidgetRoutes();
|
|
191
191
|
return new Proxy(this, {
|
|
@@ -200,11 +200,11 @@ var McpServer = class {
|
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* Define a static resource that can be accessed by clients
|
|
203
|
-
*
|
|
203
|
+
*
|
|
204
204
|
* Registers a resource with the MCP server that clients can access via HTTP.
|
|
205
205
|
* Resources are static content like files, data, or pre-computed results that
|
|
206
206
|
* can be retrieved by clients without requiring parameters.
|
|
207
|
-
*
|
|
207
|
+
*
|
|
208
208
|
* @param resourceDefinition - Configuration object containing resource metadata and handler function
|
|
209
209
|
* @param resourceDefinition.name - Unique identifier for the resource
|
|
210
210
|
* @param resourceDefinition.uri - URI pattern for accessing the resource
|
|
@@ -214,7 +214,7 @@ var McpServer = class {
|
|
|
214
214
|
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
|
215
215
|
* @param resourceDefinition.readCallback - Async callback function that returns the resource content
|
|
216
216
|
* @returns The server instance for method chaining
|
|
217
|
-
*
|
|
217
|
+
*
|
|
218
218
|
* @example
|
|
219
219
|
* ```typescript
|
|
220
220
|
* server.resource({
|
|
@@ -256,17 +256,17 @@ var McpServer = class {
|
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Define a dynamic resource template with parameters
|
|
259
|
-
*
|
|
259
|
+
*
|
|
260
260
|
* Registers a parameterized resource template with the MCP server. Templates use URI
|
|
261
261
|
* patterns with placeholders that can be filled in at request time, allowing dynamic
|
|
262
262
|
* resource generation based on parameters.
|
|
263
|
-
*
|
|
263
|
+
*
|
|
264
264
|
* @param resourceTemplateDefinition - Configuration object for the resource template
|
|
265
265
|
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
|
266
266
|
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
|
267
267
|
* @param resourceTemplateDefinition.readCallback - Async callback function that generates resource content from URI and params
|
|
268
268
|
* @returns The server instance for method chaining
|
|
269
|
-
*
|
|
269
|
+
*
|
|
270
270
|
* @example
|
|
271
271
|
* ```typescript
|
|
272
272
|
* server.resourceTemplate({
|
|
@@ -328,13 +328,13 @@ var McpServer = class {
|
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
330
330
|
* Define a tool that can be called by clients
|
|
331
|
-
*
|
|
331
|
+
*
|
|
332
332
|
* Registers a tool with the MCP server that clients can invoke with parameters.
|
|
333
333
|
* Tools are functions that perform actions, computations, or operations and
|
|
334
334
|
* return results. They accept structured input parameters and return structured output.
|
|
335
|
-
*
|
|
335
|
+
*
|
|
336
336
|
* Supports Apps SDK metadata for ChatGPT integration via the _meta field.
|
|
337
|
-
*
|
|
337
|
+
*
|
|
338
338
|
* @param toolDefinition - Configuration object containing tool metadata and handler function
|
|
339
339
|
* @param toolDefinition.name - Unique identifier for the tool
|
|
340
340
|
* @param toolDefinition.description - Human-readable description of what the tool does
|
|
@@ -342,7 +342,7 @@ var McpServer = class {
|
|
|
342
342
|
* @param toolDefinition.cb - Async callback function that executes the tool logic with provided parameters
|
|
343
343
|
* @param toolDefinition._meta - Optional metadata for the tool (e.g. Apps SDK metadata)
|
|
344
344
|
* @returns The server instance for method chaining
|
|
345
|
-
*
|
|
345
|
+
*
|
|
346
346
|
* @example
|
|
347
347
|
* ```typescript
|
|
348
348
|
* server.tool({
|
|
@@ -383,18 +383,18 @@ var McpServer = class {
|
|
|
383
383
|
}
|
|
384
384
|
/**
|
|
385
385
|
* Define a prompt template
|
|
386
|
-
*
|
|
386
|
+
*
|
|
387
387
|
* Registers a prompt template with the MCP server that clients can use to generate
|
|
388
388
|
* structured prompts for AI models. Prompt templates accept parameters and return
|
|
389
389
|
* formatted text that can be used as input to language models or other AI systems.
|
|
390
|
-
*
|
|
390
|
+
*
|
|
391
391
|
* @param promptDefinition - Configuration object containing prompt metadata and handler function
|
|
392
392
|
* @param promptDefinition.name - Unique identifier for the prompt template
|
|
393
393
|
* @param promptDefinition.description - Human-readable description of the prompt's purpose
|
|
394
394
|
* @param promptDefinition.args - Array of argument definitions with types and validation
|
|
395
395
|
* @param promptDefinition.cb - Async callback function that generates the prompt from provided arguments
|
|
396
396
|
* @returns The server instance for method chaining
|
|
397
|
-
*
|
|
397
|
+
*
|
|
398
398
|
* @example
|
|
399
399
|
* ```typescript
|
|
400
400
|
* server.prompt({
|
|
@@ -472,7 +472,7 @@ var McpServer = class {
|
|
|
472
472
|
* },
|
|
473
473
|
* size: ['900px', '600px']
|
|
474
474
|
* })
|
|
475
|
-
*
|
|
475
|
+
*
|
|
476
476
|
* // Apps SDK widget
|
|
477
477
|
* server.uiResource({
|
|
478
478
|
* type: 'appsSdk',
|
|
@@ -682,18 +682,18 @@ var McpServer = class {
|
|
|
682
682
|
}
|
|
683
683
|
/**
|
|
684
684
|
* Mount MCP server endpoints at /mcp
|
|
685
|
-
*
|
|
685
|
+
*
|
|
686
686
|
* Sets up the HTTP transport layer for the MCP server, creating endpoints for
|
|
687
687
|
* Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
|
|
688
688
|
* Each request gets its own transport instance to prevent state conflicts between
|
|
689
689
|
* concurrent client connections.
|
|
690
|
-
*
|
|
690
|
+
*
|
|
691
691
|
* This method is called automatically when the server starts listening and ensures
|
|
692
692
|
* that MCP clients can communicate with the server over HTTP.
|
|
693
|
-
*
|
|
693
|
+
*
|
|
694
694
|
* @private
|
|
695
695
|
* @returns Promise that resolves when MCP endpoints are successfully mounted
|
|
696
|
-
*
|
|
696
|
+
*
|
|
697
697
|
* @example
|
|
698
698
|
* Endpoints created:
|
|
699
699
|
* - GET /mcp - SSE streaming endpoint for real-time communication
|
|
@@ -742,17 +742,17 @@ var McpServer = class {
|
|
|
742
742
|
}
|
|
743
743
|
/**
|
|
744
744
|
* Start the Express server with MCP endpoints
|
|
745
|
-
*
|
|
745
|
+
*
|
|
746
746
|
* Initiates the server startup process by mounting MCP endpoints, configuring
|
|
747
747
|
* the inspector UI (if available), and starting the Express server to listen
|
|
748
748
|
* for incoming connections. This is the main entry point for running the server.
|
|
749
|
-
*
|
|
749
|
+
*
|
|
750
750
|
* The server will be accessible at the specified port with MCP endpoints at /mcp
|
|
751
751
|
* and inspector UI at /inspector (if the inspector package is installed).
|
|
752
|
-
*
|
|
752
|
+
*
|
|
753
753
|
* @param port - Port number to listen on (defaults to 3001 if not specified)
|
|
754
754
|
* @returns Promise that resolves when the server is successfully listening
|
|
755
|
-
*
|
|
755
|
+
*
|
|
756
756
|
* @example
|
|
757
757
|
* ```typescript
|
|
758
758
|
* await server.listen(8080)
|
|
@@ -772,22 +772,22 @@ var McpServer = class {
|
|
|
772
772
|
}
|
|
773
773
|
/**
|
|
774
774
|
* Mount MCP Inspector UI at /inspector
|
|
775
|
-
*
|
|
775
|
+
*
|
|
776
776
|
* Dynamically loads and mounts the MCP Inspector UI package if available, providing
|
|
777
777
|
* a web-based interface for testing and debugging MCP servers. The inspector
|
|
778
778
|
* automatically connects to the local MCP server endpoints.
|
|
779
|
-
*
|
|
779
|
+
*
|
|
780
780
|
* This method gracefully handles cases where the inspector package is not installed,
|
|
781
781
|
* allowing the server to function without the inspector in production environments.
|
|
782
|
-
*
|
|
782
|
+
*
|
|
783
783
|
* @private
|
|
784
784
|
* @returns void
|
|
785
|
-
*
|
|
785
|
+
*
|
|
786
786
|
* @example
|
|
787
787
|
* If @mcp-use/inspector is installed:
|
|
788
788
|
* - Inspector UI available at http://localhost:PORT/inspector
|
|
789
789
|
* - Automatically connects to http://localhost:PORT/mcp
|
|
790
|
-
*
|
|
790
|
+
*
|
|
791
791
|
* If not installed:
|
|
792
792
|
* - Server continues to function normally
|
|
793
793
|
* - No inspector UI available
|
|
@@ -803,19 +803,19 @@ var McpServer = class {
|
|
|
803
803
|
}
|
|
804
804
|
/**
|
|
805
805
|
* Setup default widget serving routes
|
|
806
|
-
*
|
|
806
|
+
*
|
|
807
807
|
* Configures Express routes to serve MCP UI widgets and their static assets.
|
|
808
808
|
* Widgets are served from the dist/resources/mcp-use/widgets directory and can
|
|
809
809
|
* be accessed via HTTP endpoints for embedding in web applications.
|
|
810
|
-
*
|
|
810
|
+
*
|
|
811
811
|
* Routes created:
|
|
812
812
|
* - GET /mcp-use/widgets/:widget - Serves widget's index.html
|
|
813
813
|
* - GET /mcp-use/widgets/:widget/assets/* - Serves widget-specific assets
|
|
814
814
|
* - GET /mcp-use/widgets/assets/* - Fallback asset serving with auto-discovery
|
|
815
|
-
*
|
|
815
|
+
*
|
|
816
816
|
* @private
|
|
817
817
|
* @returns void
|
|
818
|
-
*
|
|
818
|
+
*
|
|
819
819
|
* @example
|
|
820
820
|
* Widget routes:
|
|
821
821
|
* - http://localhost:3001/mcp-use/widgets/kanban-board
|
|
@@ -852,14 +852,14 @@ var McpServer = class {
|
|
|
852
852
|
}
|
|
853
853
|
/**
|
|
854
854
|
* Create input schema for resource templates
|
|
855
|
-
*
|
|
855
|
+
*
|
|
856
856
|
* Parses a URI template string to extract parameter names and generates a Zod
|
|
857
857
|
* validation schema for those parameters. Used internally for validating resource
|
|
858
858
|
* template parameters before processing requests.
|
|
859
|
-
*
|
|
859
|
+
*
|
|
860
860
|
* @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
|
|
861
861
|
* @returns Object mapping parameter names to Zod string schemas
|
|
862
|
-
*
|
|
862
|
+
*
|
|
863
863
|
* @example
|
|
864
864
|
* ```typescript
|
|
865
865
|
* const schema = this.createInputSchema("/users/{id}/posts/{postId}")
|
|
@@ -876,14 +876,14 @@ var McpServer = class {
|
|
|
876
876
|
}
|
|
877
877
|
/**
|
|
878
878
|
* Create input schema for tools
|
|
879
|
-
*
|
|
879
|
+
*
|
|
880
880
|
* Converts tool input definitions into Zod validation schemas for runtime validation.
|
|
881
881
|
* Supports common data types (string, number, boolean, object, array) and optional
|
|
882
882
|
* parameters. Used internally when registering tools with the MCP server.
|
|
883
|
-
*
|
|
883
|
+
*
|
|
884
884
|
* @param inputs - Array of input parameter definitions with name, type, and optional flag
|
|
885
885
|
* @returns Object mapping parameter names to Zod validation schemas
|
|
886
|
-
*
|
|
886
|
+
*
|
|
887
887
|
* @example
|
|
888
888
|
* ```typescript
|
|
889
889
|
* const schema = this.createToolInputSchema([
|
|
@@ -928,14 +928,14 @@ var McpServer = class {
|
|
|
928
928
|
}
|
|
929
929
|
/**
|
|
930
930
|
* Create arguments schema for prompts
|
|
931
|
-
*
|
|
931
|
+
*
|
|
932
932
|
* Converts prompt argument definitions into Zod validation schemas for runtime validation.
|
|
933
933
|
* Supports common data types (string, number, boolean, object, array) and optional
|
|
934
934
|
* parameters. Used internally when registering prompt templates with the MCP server.
|
|
935
|
-
*
|
|
935
|
+
*
|
|
936
936
|
* @param inputs - Array of argument definitions with name, type, and optional flag
|
|
937
937
|
* @returns Object mapping argument names to Zod validation schemas
|
|
938
|
-
*
|
|
938
|
+
*
|
|
939
939
|
* @example
|
|
940
940
|
* ```typescript
|
|
941
941
|
* const schema = this.createPromptArgsSchema([
|
|
@@ -977,14 +977,14 @@ var McpServer = class {
|
|
|
977
977
|
}
|
|
978
978
|
/**
|
|
979
979
|
* Extract parameter names from URI template
|
|
980
|
-
*
|
|
980
|
+
*
|
|
981
981
|
* Parses a URI template string to extract parameter names enclosed in curly braces.
|
|
982
982
|
* Used internally to identify dynamic parameters in resource templates and generate
|
|
983
983
|
* appropriate validation schemas.
|
|
984
|
-
*
|
|
984
|
+
*
|
|
985
985
|
* @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
|
|
986
986
|
* @returns Array of parameter names found in the template
|
|
987
|
-
*
|
|
987
|
+
*
|
|
988
988
|
* @example
|
|
989
989
|
* ```typescript
|
|
990
990
|
* const params = this.extractTemplateParams("/users/{id}/posts/{postId}")
|
|
@@ -997,14 +997,14 @@ var McpServer = class {
|
|
|
997
997
|
}
|
|
998
998
|
/**
|
|
999
999
|
* Parse parameter values from a URI based on a template
|
|
1000
|
-
*
|
|
1000
|
+
*
|
|
1001
1001
|
* Extracts parameter values from an actual URI by matching it against a URI template.
|
|
1002
1002
|
* The template contains placeholders like {param} which are extracted as key-value pairs.
|
|
1003
|
-
*
|
|
1003
|
+
*
|
|
1004
1004
|
* @param template - URI template with placeholders (e.g., "user://{userId}/posts/{postId}")
|
|
1005
1005
|
* @param uri - Actual URI to parse (e.g., "user://123/posts/456")
|
|
1006
1006
|
* @returns Object mapping parameter names to their values
|
|
1007
|
-
*
|
|
1007
|
+
*
|
|
1008
1008
|
* @example
|
|
1009
1009
|
* ```typescript
|
|
1010
1010
|
* const params = this.parseTemplateUri("user://{userId}/posts/{postId}", "user://123/posts/456")
|
|
@@ -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,EACd,oBAAoB,EAIrB,MAAM,kBAAkB,CAAA;AAGzB,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;
|
|
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;AAQ/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;IAoChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,IAAI;IAkBtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,gBAAgB,CAAC,0BAA0B,EAAE,0BAA0B,GAAG,IAAI;IA4C9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAmB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI;IAgBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+DG;IACH,UAAU,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI;IAgIlD;;;;;;;;;;;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;IAoBtB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,iBAAiB;IAsCzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,qBAAqB;IAwC7B;;;;;;;;;;;;;;;;;;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"}
|