mcp-use 0.1.20 → 0.3.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.
Files changed (140) hide show
  1. package/dist/chunk-2HFIPY7C.js +429 -0
  2. package/dist/chunk-4DEFXVWT.js +680 -0
  3. package/dist/chunk-JXLQRAW2.js +532 -0
  4. package/dist/chunk-SHUYVCID.js +6 -0
  5. package/dist/chunk-YUSC6R6V.js +299 -0
  6. package/dist/index.cjs +5762 -0
  7. package/dist/index.d.ts +7 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3767 -22
  10. package/dist/langfuse-YA2S23SM.js +13 -0
  11. package/dist/src/agents/remote.d.ts.map +1 -1
  12. package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
  13. package/dist/src/auth/browser-provider.d.ts +52 -0
  14. package/dist/src/auth/browser-provider.d.ts.map +1 -0
  15. package/dist/src/auth/callback.d.ts +6 -0
  16. package/dist/src/auth/callback.d.ts.map +1 -0
  17. package/dist/src/auth/index.d.ts +7 -0
  18. package/dist/src/auth/index.d.ts.map +1 -0
  19. package/dist/src/auth/types.d.ts +18 -0
  20. package/dist/src/auth/types.d.ts.map +1 -0
  21. package/dist/src/browser.cjs +323 -0
  22. package/dist/src/browser.d.ts +8 -0
  23. package/dist/src/browser.d.ts.map +1 -0
  24. package/dist/src/browser.js +9 -0
  25. package/dist/src/client/base.d.ts +32 -0
  26. package/dist/src/client/base.d.ts.map +1 -0
  27. package/dist/src/client.d.ts +19 -16
  28. package/dist/src/client.d.ts.map +1 -1
  29. package/dist/src/logging.d.ts +1 -1
  30. package/dist/src/logging.d.ts.map +1 -1
  31. package/dist/src/oauth-helper.d.ts +125 -0
  32. package/dist/src/oauth-helper.d.ts.map +1 -0
  33. package/dist/src/react/index.cjs +986 -0
  34. package/dist/src/react/index.d.ts +9 -0
  35. package/dist/src/react/index.d.ts.map +1 -0
  36. package/dist/src/react/index.js +11 -0
  37. package/dist/src/react/types.d.ts +139 -0
  38. package/dist/src/react/types.d.ts.map +1 -0
  39. package/dist/src/react/useMcp.d.ts +3 -0
  40. package/dist/src/react/useMcp.d.ts.map +1 -0
  41. package/dist/src/server/index.cjs +566 -0
  42. package/dist/src/server/index.d.ts +3 -0
  43. package/dist/src/server/index.d.ts.map +1 -0
  44. package/dist/src/server/index.js +9 -0
  45. package/dist/src/server/logging.d.ts +16 -0
  46. package/dist/src/server/logging.d.ts.map +1 -0
  47. package/dist/src/server/mcp-server.d.ts +282 -0
  48. package/dist/src/server/mcp-server.d.ts.map +1 -0
  49. package/dist/src/server/types.d.ts +47 -0
  50. package/dist/src/server/types.d.ts.map +1 -0
  51. package/dist/src/utils/assert.d.ts +8 -0
  52. package/dist/src/utils/assert.d.ts.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -0
  54. package/package.json +72 -40
  55. package/dist/examples/add_server_tool.d.ts +0 -8
  56. package/dist/examples/add_server_tool.d.ts.map +0 -1
  57. package/dist/examples/add_server_tool.js +0 -79
  58. package/dist/examples/ai_sdk_example.d.ts +0 -23
  59. package/dist/examples/ai_sdk_example.d.ts.map +0 -1
  60. package/dist/examples/ai_sdk_example.js +0 -213
  61. package/dist/examples/airbnb_use.d.ts +0 -10
  62. package/dist/examples/airbnb_use.d.ts.map +0 -1
  63. package/dist/examples/airbnb_use.js +0 -43
  64. package/dist/examples/blender_use.d.ts +0 -15
  65. package/dist/examples/blender_use.d.ts.map +0 -1
  66. package/dist/examples/blender_use.js +0 -39
  67. package/dist/examples/browser_use.d.ts +0 -10
  68. package/dist/examples/browser_use.d.ts.map +0 -1
  69. package/dist/examples/browser_use.js +0 -46
  70. package/dist/examples/chat_example.d.ts +0 -10
  71. package/dist/examples/chat_example.d.ts.map +0 -1
  72. package/dist/examples/chat_example.js +0 -86
  73. package/dist/examples/filesystem_use.d.ts +0 -11
  74. package/dist/examples/filesystem_use.d.ts.map +0 -1
  75. package/dist/examples/filesystem_use.js +0 -43
  76. package/dist/examples/http_example.d.ts +0 -18
  77. package/dist/examples/http_example.d.ts.map +0 -1
  78. package/dist/examples/http_example.js +0 -37
  79. package/dist/examples/mcp_everything.d.ts +0 -6
  80. package/dist/examples/mcp_everything.d.ts.map +0 -1
  81. package/dist/examples/mcp_everything.js +0 -25
  82. package/dist/examples/multi_server_example.d.ts +0 -10
  83. package/dist/examples/multi_server_example.d.ts.map +0 -1
  84. package/dist/examples/multi_server_example.js +0 -51
  85. package/dist/examples/observability.d.ts +0 -6
  86. package/dist/examples/observability.d.ts.map +0 -1
  87. package/dist/examples/observability.js +0 -50
  88. package/dist/examples/stream_example.d.ts +0 -12
  89. package/dist/examples/stream_example.d.ts.map +0 -1
  90. package/dist/examples/stream_example.js +0 -198
  91. package/dist/examples/structured_output.d.ts +0 -9
  92. package/dist/examples/structured_output.d.ts.map +0 -1
  93. package/dist/examples/structured_output.js +0 -95
  94. package/dist/src/adapters/base.js +0 -124
  95. package/dist/src/adapters/index.js +0 -2
  96. package/dist/src/adapters/langchain_adapter.js +0 -49
  97. package/dist/src/agents/base.js +0 -9
  98. package/dist/src/agents/index.js +0 -3
  99. package/dist/src/agents/mcp_agent.js +0 -1002
  100. package/dist/src/agents/prompts/system_prompt_builder.js +0 -40
  101. package/dist/src/agents/prompts/templates.js +0 -39
  102. package/dist/src/agents/remote.js +0 -264
  103. package/dist/src/agents/utils/ai_sdk.js +0 -62
  104. package/dist/src/agents/utils/index.js +0 -1
  105. package/dist/src/client.js +0 -133
  106. package/dist/src/config.js +0 -34
  107. package/dist/src/connectors/base.js +0 -143
  108. package/dist/src/connectors/http.js +0 -150
  109. package/dist/src/connectors/index.js +0 -4
  110. package/dist/src/connectors/stdio.js +0 -68
  111. package/dist/src/connectors/websocket.js +0 -157
  112. package/dist/src/logging.js +0 -217
  113. package/dist/src/managers/index.js +0 -2
  114. package/dist/src/managers/server_manager.js +0 -106
  115. package/dist/src/managers/tools/acquire_active_mcp_server.js +0 -17
  116. package/dist/src/managers/tools/add_server_from_config.js +0 -40
  117. package/dist/src/managers/tools/base.js +0 -17
  118. package/dist/src/managers/tools/connect_mcp_server.js +0 -46
  119. package/dist/src/managers/tools/index.js +0 -5
  120. package/dist/src/managers/tools/list_mcp_servers.js +0 -33
  121. package/dist/src/managers/tools/release_mcp_server_connection.js +0 -19
  122. package/dist/src/observability/index.js +0 -12
  123. package/dist/src/observability/langfuse.js +0 -211
  124. package/dist/src/observability/manager.js +0 -199
  125. package/dist/src/observability/types.js +0 -4
  126. package/dist/src/session.js +0 -23
  127. package/dist/src/task_managers/base.js +0 -127
  128. package/dist/src/task_managers/index.js +0 -5
  129. package/dist/src/task_managers/sse.js +0 -43
  130. package/dist/src/task_managers/stdio.js +0 -51
  131. package/dist/src/task_managers/streamable_http.js +0 -50
  132. package/dist/src/task_managers/websocket.js +0 -67
  133. package/dist/src/telemetry/events.js +0 -44
  134. package/dist/src/telemetry/index.js +0 -8
  135. package/dist/src/telemetry/telemetry.js +0 -324
  136. package/dist/src/telemetry/utils.js +0 -39
  137. package/dist/tests/ai_sdk_compatibility.test.js +0 -214
  138. package/dist/tests/stream_events.test.js +0 -307
  139. package/dist/tests/stream_events_simple.test.js +0 -179
  140. package/dist/vitest.config.js +0 -21
@@ -0,0 +1,566 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/server/index.ts
32
+ var server_exports = {};
33
+ __export(server_exports, {
34
+ McpServer: () => McpServer,
35
+ createMCPServer: () => createMCPServer
36
+ });
37
+ module.exports = __toCommonJS(server_exports);
38
+
39
+ // src/server/mcp-server.ts
40
+ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
41
+ var import_zod = require("zod");
42
+ var import_express = __toESM(require("express"), 1);
43
+ var import_node_fs = require("fs");
44
+ var import_node_path = require("path");
45
+
46
+ // src/server/logging.ts
47
+ function requestLogger(req, res, next) {
48
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().substring(11, 23);
49
+ const method = req.method;
50
+ const url = req.url;
51
+ const originalEnd = res.end.bind(res);
52
+ res.end = function(chunk, encoding, cb) {
53
+ const statusCode = res.statusCode;
54
+ let statusColor = "";
55
+ if (statusCode >= 200 && statusCode < 300) {
56
+ statusColor = "\x1B[32m";
57
+ } else if (statusCode >= 300 && statusCode < 400) {
58
+ statusColor = "\x1B[33m";
59
+ } else if (statusCode >= 400 && statusCode < 500) {
60
+ statusColor = "\x1B[31m";
61
+ } else if (statusCode >= 500) {
62
+ statusColor = "\x1B[35m";
63
+ }
64
+ let logMessage = `[${timestamp}] ${method} \x1B[1m${url}\x1B[0m`;
65
+ if (method === "POST" && url === "/mcp" && req.body?.method) {
66
+ logMessage += ` \x1B[1m[${req.body.method}]\x1B[0m`;
67
+ }
68
+ logMessage += ` ${statusColor}${statusCode}\x1B[0m`;
69
+ console.log(logMessage);
70
+ return originalEnd(chunk, encoding, cb);
71
+ };
72
+ next();
73
+ }
74
+ __name(requestLogger, "requestLogger");
75
+
76
+ // src/server/mcp-server.ts
77
+ var McpServer = class {
78
+ static {
79
+ __name(this, "McpServer");
80
+ }
81
+ server;
82
+ config;
83
+ app;
84
+ mcpMounted = false;
85
+ inspectorMounted = false;
86
+ serverPort;
87
+ /**
88
+ * Creates a new MCP server instance with Express integration
89
+ *
90
+ * Initializes the server with the provided configuration, sets up CORS headers,
91
+ * configures widget serving routes, and creates a proxy that allows direct
92
+ * access to Express methods while preserving MCP server functionality.
93
+ *
94
+ * @param config - Server configuration including name, version, and description
95
+ * @returns A proxied McpServer instance that supports both MCP and Express methods
96
+ */
97
+ constructor(config) {
98
+ this.config = config;
99
+ this.server = new import_mcp.McpServer({
100
+ name: config.name,
101
+ version: config.version
102
+ });
103
+ this.app = (0, import_express.default)();
104
+ this.app.use((req, res, next) => {
105
+ res.header("Access-Control-Allow-Origin", "*");
106
+ res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
107
+ res.header("Access-Control-Allow-Headers", "Content-Type");
108
+ next();
109
+ });
110
+ this.app.use(requestLogger);
111
+ this.setupWidgetRoutes();
112
+ return new Proxy(this, {
113
+ get(target, prop) {
114
+ if (prop in target) {
115
+ return target[prop];
116
+ }
117
+ const value = target.app[prop];
118
+ return typeof value === "function" ? value.bind(target.app) : value;
119
+ }
120
+ });
121
+ }
122
+ /**
123
+ * Define a static resource that can be accessed by clients
124
+ *
125
+ * Registers a resource with the MCP server that clients can access via HTTP.
126
+ * Resources are static content like files, data, or pre-computed results that
127
+ * can be retrieved by clients without requiring parameters.
128
+ *
129
+ * @param resourceDefinition - Configuration object containing resource metadata and handler function
130
+ * @param resourceDefinition.name - Unique identifier for the resource
131
+ * @param resourceDefinition.uri - URI pattern for accessing the resource
132
+ * @param resourceDefinition.resource - Resource metadata (mime type, description, etc.)
133
+ * @param resourceDefinition.fn - Async function that returns the resource content
134
+ * @returns The server instance for method chaining
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * server.resource({
139
+ * name: 'config',
140
+ * uri: 'config://app-settings',
141
+ * resource: { mimeType: 'application/json' },
142
+ * fn: async () => ({ theme: 'dark', language: 'en' })
143
+ * })
144
+ * ```
145
+ */
146
+ resource(resourceDefinition) {
147
+ this.server.resource(
148
+ resourceDefinition.name,
149
+ resourceDefinition.uri,
150
+ resourceDefinition.resource,
151
+ async () => {
152
+ return await resourceDefinition.fn();
153
+ }
154
+ );
155
+ return this;
156
+ }
157
+ /**
158
+ * Define a dynamic resource template with parameters
159
+ */
160
+ // TODO implement, for some freaky reason this give errors
161
+ // resourceTemplate(resourceTemplateDefinition: ResourceTemplateDefinition): this {
162
+ // this.server.resource(
163
+ // resourceTemplateDefinition.name,
164
+ // resourceTemplateDefinition.resourceTemplate,
165
+ // async (uri, params) => {
166
+ // return await resourceTemplateDefinition.fn(uri, params)
167
+ // },
168
+ // )
169
+ // return this
170
+ // }
171
+ /**
172
+ * Define a tool that can be called by clients
173
+ *
174
+ * Registers a tool with the MCP server that clients can invoke with parameters.
175
+ * Tools are functions that perform actions, computations, or operations and
176
+ * return results. They accept structured input parameters and return structured output.
177
+ *
178
+ * @param toolDefinition - Configuration object containing tool metadata and handler function
179
+ * @param toolDefinition.name - Unique identifier for the tool
180
+ * @param toolDefinition.description - Human-readable description of what the tool does
181
+ * @param toolDefinition.inputs - Array of input parameter definitions with types and validation
182
+ * @param toolDefinition.fn - Async function that executes the tool logic with provided parameters
183
+ * @returns The server instance for method chaining
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * server.tool({
188
+ * name: 'calculate',
189
+ * description: 'Performs mathematical calculations',
190
+ * inputs: [
191
+ * { name: 'expression', type: 'string', required: true },
192
+ * { name: 'precision', type: 'number', required: false }
193
+ * ],
194
+ * fn: async ({ expression, precision = 2 }) => {
195
+ * const result = eval(expression)
196
+ * return { result: Number(result.toFixed(precision)) }
197
+ * }
198
+ * })
199
+ * ```
200
+ */
201
+ tool(toolDefinition) {
202
+ const inputSchema = this.createToolInputSchema(toolDefinition.inputs || []);
203
+ this.server.tool(
204
+ toolDefinition.name,
205
+ toolDefinition.description ?? "",
206
+ inputSchema,
207
+ async (params) => {
208
+ return await toolDefinition.fn(params);
209
+ }
210
+ );
211
+ return this;
212
+ }
213
+ /**
214
+ * Define a prompt template
215
+ *
216
+ * Registers a prompt template with the MCP server that clients can use to generate
217
+ * structured prompts for AI models. Prompt templates accept parameters and return
218
+ * formatted text that can be used as input to language models or other AI systems.
219
+ *
220
+ * @param promptDefinition - Configuration object containing prompt metadata and handler function
221
+ * @param promptDefinition.name - Unique identifier for the prompt template
222
+ * @param promptDefinition.description - Human-readable description of the prompt's purpose
223
+ * @param promptDefinition.args - Array of argument definitions with types and validation
224
+ * @param promptDefinition.fn - Async function that generates the prompt from provided arguments
225
+ * @returns The server instance for method chaining
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * server.prompt({
230
+ * name: 'code-review',
231
+ * description: 'Generates a code review prompt',
232
+ * args: [
233
+ * { name: 'language', type: 'string', required: true },
234
+ * { name: 'focus', type: 'string', required: false }
235
+ * ],
236
+ * fn: async ({ language, focus = 'general' }) => {
237
+ * return {
238
+ * messages: [{
239
+ * role: 'user',
240
+ * content: `Please review this ${language} code with focus on ${focus}...`
241
+ * }]
242
+ * }
243
+ * }
244
+ * })
245
+ * ```
246
+ */
247
+ prompt(promptDefinition) {
248
+ const argsSchema = this.createPromptArgsSchema(promptDefinition.args || []);
249
+ this.server.prompt(
250
+ promptDefinition.name,
251
+ promptDefinition.description ?? "",
252
+ argsSchema,
253
+ async (params) => {
254
+ return await promptDefinition.fn(params);
255
+ }
256
+ );
257
+ return this;
258
+ }
259
+ /**
260
+ * Mount MCP server endpoints at /mcp
261
+ *
262
+ * Sets up the HTTP transport layer for the MCP server, creating endpoints for
263
+ * Server-Sent Events (SSE) streaming, POST message handling, and DELETE session cleanup.
264
+ * Uses stateless mode for session management, making it suitable for stateless deployments.
265
+ *
266
+ * This method is called automatically when the server starts listening and ensures
267
+ * that MCP clients can communicate with the server over HTTP.
268
+ *
269
+ * @private
270
+ * @returns Promise that resolves when MCP endpoints are successfully mounted
271
+ *
272
+ * @example
273
+ * Endpoints created:
274
+ * - GET /mcp - SSE streaming endpoint for real-time communication
275
+ * - POST /mcp - Message handling endpoint for MCP protocol messages
276
+ * - DELETE /mcp - Session cleanup endpoint
277
+ */
278
+ async mountMcp() {
279
+ if (this.mcpMounted) return;
280
+ const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
281
+ const httpTransport = new StreamableHTTPServerTransport({
282
+ sessionIdGenerator: void 0
283
+ // Stateless mode
284
+ });
285
+ await this.server.connect(httpTransport);
286
+ const endpoint = "/mcp";
287
+ this.app.get(endpoint, async (req, res) => {
288
+ await httpTransport.handleRequest(req, res);
289
+ });
290
+ this.app.post(endpoint, import_express.default.json(), async (req, res) => {
291
+ await httpTransport.handleRequest(req, res, req.body);
292
+ });
293
+ this.app.delete(endpoint, async (req, res) => {
294
+ await httpTransport.handleRequest(req, res);
295
+ });
296
+ this.mcpMounted = true;
297
+ console.log(`[MCP] Server mounted at ${endpoint}`);
298
+ }
299
+ /**
300
+ * Start the Express server with MCP endpoints
301
+ *
302
+ * Initiates the server startup process by mounting MCP endpoints, configuring
303
+ * the inspector UI (if available), and starting the Express server to listen
304
+ * for incoming connections. This is the main entry point for running the server.
305
+ *
306
+ * The server will be accessible at the specified port with MCP endpoints at /mcp
307
+ * and inspector UI at /inspector (if the inspector package is installed).
308
+ *
309
+ * @param port - Port number to listen on (defaults to 3001 if not specified)
310
+ * @returns Promise that resolves when the server is successfully listening
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * await server.listen(8080)
315
+ * // Server now running at http://localhost:8080
316
+ * // MCP endpoints: http://localhost:8080/mcp
317
+ * // Inspector UI: http://localhost:8080/inspector
318
+ * ```
319
+ */
320
+ async listen(port) {
321
+ await this.mountMcp();
322
+ this.serverPort = port || 3001;
323
+ this.mountInspector();
324
+ this.app.listen(this.serverPort, () => {
325
+ console.log(`[SERVER] Listening on http://localhost:${this.serverPort}`);
326
+ console.log(`[MCP] Endpoints: http://localhost:${this.serverPort}/mcp`);
327
+ });
328
+ }
329
+ /**
330
+ * Mount MCP Inspector UI at /inspector
331
+ *
332
+ * Dynamically loads and mounts the MCP Inspector UI package if available, providing
333
+ * a web-based interface for testing and debugging MCP servers. The inspector
334
+ * automatically connects to the local MCP server endpoints.
335
+ *
336
+ * This method gracefully handles cases where the inspector package is not installed,
337
+ * allowing the server to function without the inspector in production environments.
338
+ *
339
+ * @private
340
+ * @returns void
341
+ *
342
+ * @example
343
+ * If @mcp-use/inspector is installed:
344
+ * - Inspector UI available at http://localhost:PORT/inspector
345
+ * - Automatically connects to http://localhost:PORT/mcp
346
+ *
347
+ * If not installed:
348
+ * - Server continues to function normally
349
+ * - No inspector UI available
350
+ */
351
+ mountInspector() {
352
+ if (this.inspectorMounted) return;
353
+ import("@mcp-use/inspector").then(({ mountInspector }) => {
354
+ const mcpServerUrl = `http://localhost:${this.serverPort}/mcp`;
355
+ mountInspector(this.app, "/inspector", mcpServerUrl);
356
+ this.inspectorMounted = true;
357
+ console.log(`[INSPECTOR] UI available at http://localhost:${this.serverPort}/inspector`);
358
+ }).catch(() => {
359
+ });
360
+ }
361
+ /**
362
+ * Setup default widget serving routes
363
+ *
364
+ * Configures Express routes to serve MCP UI widgets and their static assets.
365
+ * Widgets are served from the dist/resources/mcp-use/widgets directory and can
366
+ * be accessed via HTTP endpoints for embedding in web applications.
367
+ *
368
+ * Routes created:
369
+ * - GET /mcp-use/widgets/:widget - Serves widget's index.html
370
+ * - GET /mcp-use/widgets/:widget/assets/* - Serves widget-specific assets
371
+ * - GET /mcp-use/widgets/assets/* - Fallback asset serving with auto-discovery
372
+ *
373
+ * @private
374
+ * @returns void
375
+ *
376
+ * @example
377
+ * Widget routes:
378
+ * - http://localhost:3001/mcp-use/widgets/kanban-board
379
+ * - http://localhost:3001/mcp-use/widgets/todo-list/assets/style.css
380
+ * - http://localhost:3001/mcp-use/widgets/assets/script.js (auto-discovered)
381
+ */
382
+ setupWidgetRoutes() {
383
+ this.app.get("/mcp-use/widgets/:widget/assets/*", (req, res, next) => {
384
+ const widget = req.params.widget;
385
+ const assetFile = req.params[0];
386
+ const assetPath = (0, import_node_path.join)(process.cwd(), "dist", "resources", "mcp-use", "widgets", widget, "assets", assetFile);
387
+ res.sendFile(assetPath, (err) => err ? next() : void 0);
388
+ });
389
+ this.app.get("/mcp-use/widgets/assets/*", (req, res, next) => {
390
+ const assetFile = req.params[0];
391
+ const widgetsDir = (0, import_node_path.join)(process.cwd(), "dist", "resources", "mcp-use", "widgets");
392
+ try {
393
+ const widgets = (0, import_node_fs.readdirSync)(widgetsDir);
394
+ for (const widget of widgets) {
395
+ const assetPath = (0, import_node_path.join)(widgetsDir, widget, "assets", assetFile);
396
+ if ((0, import_node_fs.existsSync)(assetPath)) {
397
+ return res.sendFile(assetPath);
398
+ }
399
+ }
400
+ next();
401
+ } catch {
402
+ next();
403
+ }
404
+ });
405
+ this.app.get("/mcp-use/widgets/:widget", (req, res, next) => {
406
+ const filePath = (0, import_node_path.join)(process.cwd(), "dist", "resources", "mcp-use", "widgets", req.params.widget, "index.html");
407
+ res.sendFile(filePath, (err) => err ? next() : void 0);
408
+ });
409
+ }
410
+ /**
411
+ * Create input schema for resource templates
412
+ *
413
+ * Parses a URI template string to extract parameter names and generates a Zod
414
+ * validation schema for those parameters. Used internally for validating resource
415
+ * template parameters before processing requests.
416
+ *
417
+ * @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
418
+ * @returns Object mapping parameter names to Zod string schemas
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * const schema = this.createInputSchema("/users/{id}/posts/{postId}")
423
+ * // Returns: { id: z.string(), postId: z.string() }
424
+ * ```
425
+ */
426
+ createInputSchema(uriTemplate) {
427
+ const params = this.extractTemplateParams(uriTemplate);
428
+ const schema = {};
429
+ params.forEach((param) => {
430
+ schema[param] = import_zod.z.string();
431
+ });
432
+ return schema;
433
+ }
434
+ /**
435
+ * Create input schema for tools
436
+ *
437
+ * Converts tool input definitions into Zod validation schemas for runtime validation.
438
+ * Supports common data types (string, number, boolean, object, array) and optional
439
+ * parameters. Used internally when registering tools with the MCP server.
440
+ *
441
+ * @param inputs - Array of input parameter definitions with name, type, and optional flag
442
+ * @returns Object mapping parameter names to Zod validation schemas
443
+ *
444
+ * @example
445
+ * ```typescript
446
+ * const schema = this.createToolInputSchema([
447
+ * { name: 'query', type: 'string', required: true },
448
+ * { name: 'limit', type: 'number', required: false }
449
+ * ])
450
+ * // Returns: { query: z.string(), limit: z.number().optional() }
451
+ * ```
452
+ */
453
+ createToolInputSchema(inputs) {
454
+ const schema = {};
455
+ inputs.forEach((input) => {
456
+ let zodType;
457
+ switch (input.type) {
458
+ case "string":
459
+ zodType = import_zod.z.string();
460
+ break;
461
+ case "number":
462
+ zodType = import_zod.z.number();
463
+ break;
464
+ case "boolean":
465
+ zodType = import_zod.z.boolean();
466
+ break;
467
+ case "object":
468
+ zodType = import_zod.z.object({});
469
+ break;
470
+ case "array":
471
+ zodType = import_zod.z.array(import_zod.z.any());
472
+ break;
473
+ default:
474
+ zodType = import_zod.z.any();
475
+ }
476
+ if (!input.required) {
477
+ zodType = zodType.optional();
478
+ }
479
+ schema[input.name] = zodType;
480
+ });
481
+ return schema;
482
+ }
483
+ /**
484
+ * Create arguments schema for prompts
485
+ *
486
+ * Converts prompt argument definitions into Zod validation schemas for runtime validation.
487
+ * Supports common data types (string, number, boolean, object, array) and optional
488
+ * parameters. Used internally when registering prompt templates with the MCP server.
489
+ *
490
+ * @param inputs - Array of argument definitions with name, type, and optional flag
491
+ * @returns Object mapping argument names to Zod validation schemas
492
+ *
493
+ * @example
494
+ * ```typescript
495
+ * const schema = this.createPromptArgsSchema([
496
+ * { name: 'topic', type: 'string', required: true },
497
+ * { name: 'style', type: 'string', required: false }
498
+ * ])
499
+ * // Returns: { topic: z.string(), style: z.string().optional() }
500
+ * ```
501
+ */
502
+ createPromptArgsSchema(inputs) {
503
+ const schema = {};
504
+ inputs.forEach((input) => {
505
+ let zodType;
506
+ switch (input.type) {
507
+ case "string":
508
+ zodType = import_zod.z.string();
509
+ break;
510
+ case "number":
511
+ zodType = import_zod.z.number();
512
+ break;
513
+ case "boolean":
514
+ zodType = import_zod.z.boolean();
515
+ break;
516
+ case "object":
517
+ zodType = import_zod.z.object({});
518
+ break;
519
+ case "array":
520
+ zodType = import_zod.z.array(import_zod.z.any());
521
+ break;
522
+ default:
523
+ zodType = import_zod.z.any();
524
+ }
525
+ if (!input.required) {
526
+ zodType = zodType.optional();
527
+ }
528
+ schema[input.name] = zodType;
529
+ });
530
+ return schema;
531
+ }
532
+ /**
533
+ * Extract parameter names from URI template
534
+ *
535
+ * Parses a URI template string to extract parameter names enclosed in curly braces.
536
+ * Used internally to identify dynamic parameters in resource templates and generate
537
+ * appropriate validation schemas.
538
+ *
539
+ * @param uriTemplate - URI template string with parameter placeholders (e.g., "/users/{id}/posts/{postId}")
540
+ * @returns Array of parameter names found in the template
541
+ *
542
+ * @example
543
+ * ```typescript
544
+ * const params = this.extractTemplateParams("/users/{id}/posts/{postId}")
545
+ * // Returns: ["id", "postId"]
546
+ * ```
547
+ */
548
+ extractTemplateParams(uriTemplate) {
549
+ const matches = uriTemplate.match(/\{([^}]+)\}/g);
550
+ return matches ? matches.map((match) => match.slice(1, -1)) : [];
551
+ }
552
+ };
553
+ function createMCPServer(name, config = {}) {
554
+ const instance = new McpServer({
555
+ name,
556
+ version: config.version || "1.0.0",
557
+ description: config.description
558
+ });
559
+ return instance;
560
+ }
561
+ __name(createMCPServer, "createMCPServer");
562
+ // Annotate the CommonJS export names for ESM import in node:
563
+ 0 && (module.exports = {
564
+ McpServer,
565
+ createMCPServer
566
+ });
@@ -0,0 +1,3 @@
1
+ export { createMCPServer, McpServer } from './mcp-server.js';
2
+ export type { InputDefinition, PromptDefinition, PromptHandler, ResourceDefinition, ResourceHandler, ServerConfig, ToolDefinition, ToolHandler, } from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC5D,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,YAAY,CAAA"}
@@ -0,0 +1,9 @@
1
+ import {
2
+ McpServer,
3
+ createMCPServer
4
+ } from "../../chunk-JXLQRAW2.js";
5
+ import "../../chunk-SHUYVCID.js";
6
+ export {
7
+ McpServer,
8
+ createMCPServer
9
+ };
@@ -0,0 +1,16 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ /**
3
+ * Request logging middleware with timestamp, colored status codes, and MCP method info
4
+ *
5
+ * Logs all HTTP requests with:
6
+ * - Timestamp in HH:MM:SS.mmm format
7
+ * - HTTP method and endpoint in bold
8
+ * - MCP method name in brackets for POST requests to /mcp
9
+ * - Color-coded status codes (green 2xx, yellow 3xx, red 4xx, magenta 5xx)
10
+ *
11
+ * @param req - Express request object
12
+ * @param res - Express response object
13
+ * @param next - Express next function
14
+ */
15
+ export declare function requestLogger(req: Request, res: Response, next: NextFunction): void;
16
+ //# sourceMappingURL=logging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/server/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAkCnF"}