mcp-use 1.2.5-dev.4 → 1.2.5-dev.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/dist/.tsbuildinfo +1 -1
- package/dist/src/server/connect-adapter.d.ts +31 -0
- package/dist/src/server/connect-adapter.d.ts.map +1 -0
- package/dist/src/server/index.cjs +303 -113
- package/dist/src/server/index.d.ts +2 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +303 -113
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts +2 -2
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/src/server/index.js
CHANGED
|
@@ -118,6 +118,149 @@ function createUIResourceFromDefinition(definition, params, config) {
|
|
|
118
118
|
}
|
|
119
119
|
__name(createUIResourceFromDefinition, "createUIResourceFromDefinition");
|
|
120
120
|
|
|
121
|
+
// src/server/connect-adapter.ts
|
|
122
|
+
function isExpressMiddleware(middleware) {
|
|
123
|
+
if (!middleware || typeof middleware !== "function") {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const paramCount = middleware.length;
|
|
127
|
+
if (paramCount === 3 || paramCount === 4) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
if (paramCount === 2) {
|
|
131
|
+
const fnString = middleware.toString();
|
|
132
|
+
const expressPatterns = [
|
|
133
|
+
/\bres\.(send|json|status|end|redirect|render|sendFile|download)\b/,
|
|
134
|
+
/\breq\.(body|params|query|cookies|session)\b/,
|
|
135
|
+
/\breq\.get\s*\(/,
|
|
136
|
+
/\bres\.set\s*\(/
|
|
137
|
+
];
|
|
138
|
+
const hasExpressPattern = expressPatterns.some(
|
|
139
|
+
(pattern) => pattern.test(fnString)
|
|
140
|
+
);
|
|
141
|
+
if (hasExpressPattern) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
__name(isExpressMiddleware, "isExpressMiddleware");
|
|
149
|
+
async function adaptMiddleware(middleware, middlewarePath = "*") {
|
|
150
|
+
if (isExpressMiddleware(middleware)) {
|
|
151
|
+
return adaptConnectMiddleware(middleware, middlewarePath);
|
|
152
|
+
}
|
|
153
|
+
return middleware;
|
|
154
|
+
}
|
|
155
|
+
__name(adaptMiddleware, "adaptMiddleware");
|
|
156
|
+
async function adaptConnectMiddleware(connectMiddleware, middlewarePath) {
|
|
157
|
+
let createRequest;
|
|
158
|
+
let createResponse;
|
|
159
|
+
try {
|
|
160
|
+
const httpMocks = await import("node-mocks-http");
|
|
161
|
+
createRequest = httpMocks.createRequest;
|
|
162
|
+
createResponse = httpMocks.createResponse;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(
|
|
165
|
+
"[WIDGETS] node-mocks-http not available. Install connect and node-mocks-http for Vite middleware support."
|
|
166
|
+
);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
let normalizedPath = middlewarePath;
|
|
170
|
+
if (normalizedPath.endsWith("*")) {
|
|
171
|
+
normalizedPath = normalizedPath.slice(0, -1);
|
|
172
|
+
}
|
|
173
|
+
if (normalizedPath.endsWith("/")) {
|
|
174
|
+
normalizedPath = normalizedPath.slice(0, -1);
|
|
175
|
+
}
|
|
176
|
+
const honoMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
177
|
+
const request = c.req.raw;
|
|
178
|
+
const parsedURL = new URL(request.url, "http://localhost");
|
|
179
|
+
const query = {};
|
|
180
|
+
for (const [key, value] of parsedURL.searchParams.entries()) {
|
|
181
|
+
query[key] = value;
|
|
182
|
+
}
|
|
183
|
+
let middlewarePathname = parsedURL.pathname;
|
|
184
|
+
if (normalizedPath && middlewarePathname.startsWith(normalizedPath)) {
|
|
185
|
+
middlewarePathname = middlewarePathname.substring(normalizedPath.length);
|
|
186
|
+
if (middlewarePathname === "") {
|
|
187
|
+
middlewarePathname = "/";
|
|
188
|
+
} else if (!middlewarePathname.startsWith("/")) {
|
|
189
|
+
middlewarePathname = "/" + middlewarePathname;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const mockRequest = createRequest({
|
|
193
|
+
method: request.method.toUpperCase(),
|
|
194
|
+
url: middlewarePathname + parsedURL.search,
|
|
195
|
+
headers: Object.fromEntries(request.headers.entries()),
|
|
196
|
+
query,
|
|
197
|
+
...request.body && { body: request.body }
|
|
198
|
+
});
|
|
199
|
+
const mockResponse = createResponse();
|
|
200
|
+
let responseResolved = false;
|
|
201
|
+
const res = await new Promise((resolve) => {
|
|
202
|
+
const originalEnd = mockResponse.end.bind(mockResponse);
|
|
203
|
+
mockResponse.end = (...args) => {
|
|
204
|
+
const result = originalEnd(...args);
|
|
205
|
+
if (!responseResolved && mockResponse.writableEnded) {
|
|
206
|
+
responseResolved = true;
|
|
207
|
+
const statusCode = mockResponse.statusCode;
|
|
208
|
+
const noBodyStatuses = [204, 304];
|
|
209
|
+
const responseBody = noBodyStatuses.includes(statusCode) ? null : mockResponse._getData() || mockResponse._getBuffer() || null;
|
|
210
|
+
const connectResponse = new Response(responseBody, {
|
|
211
|
+
status: statusCode,
|
|
212
|
+
statusText: mockResponse.statusMessage,
|
|
213
|
+
headers: mockResponse.getHeaders()
|
|
214
|
+
});
|
|
215
|
+
resolve(connectResponse);
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
};
|
|
219
|
+
connectMiddleware(mockRequest, mockResponse, () => {
|
|
220
|
+
if (!responseResolved && !mockResponse.writableEnded) {
|
|
221
|
+
responseResolved = true;
|
|
222
|
+
const statusCode = mockResponse.statusCode;
|
|
223
|
+
const noBodyStatuses = [204, 304];
|
|
224
|
+
const responseBody = noBodyStatuses.includes(statusCode) ? null : mockResponse._getData() || mockResponse._getBuffer() || null;
|
|
225
|
+
const preparedHeaders = c.newResponse(null, 204, {}).headers;
|
|
226
|
+
for (const key of [...preparedHeaders.keys()]) {
|
|
227
|
+
if (preparedHeaders.has(key)) {
|
|
228
|
+
c.header(key, void 0);
|
|
229
|
+
}
|
|
230
|
+
if (c.res && c.res.headers.has(key)) {
|
|
231
|
+
c.res.headers.delete(key);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const connectHeaders = mockResponse.getHeaders();
|
|
235
|
+
for (const [key, value] of Object.entries(connectHeaders)) {
|
|
236
|
+
if (value !== void 0) {
|
|
237
|
+
c.header(
|
|
238
|
+
key,
|
|
239
|
+
Array.isArray(value) ? value.join(", ") : String(value)
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
c.status(statusCode);
|
|
244
|
+
if (noBodyStatuses.includes(statusCode)) {
|
|
245
|
+
resolve(c.newResponse(null, statusCode));
|
|
246
|
+
} else if (responseBody) {
|
|
247
|
+
resolve(c.body(responseBody));
|
|
248
|
+
} else {
|
|
249
|
+
resolve(void 0);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
if (res) {
|
|
255
|
+
c.res = res;
|
|
256
|
+
return res;
|
|
257
|
+
}
|
|
258
|
+
await next();
|
|
259
|
+
}, "honoMiddleware");
|
|
260
|
+
return honoMiddleware;
|
|
261
|
+
}
|
|
262
|
+
__name(adaptConnectMiddleware, "adaptConnectMiddleware");
|
|
263
|
+
|
|
121
264
|
// src/server/logging.ts
|
|
122
265
|
async function requestLogger(c, next) {
|
|
123
266
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().substring(11, 23);
|
|
@@ -126,7 +269,8 @@ async function requestLogger(c, next) {
|
|
|
126
269
|
let body = null;
|
|
127
270
|
if (method === "POST" && url.includes("/mcp")) {
|
|
128
271
|
try {
|
|
129
|
-
|
|
272
|
+
const clonedRequest = c.req.raw.clone();
|
|
273
|
+
body = await clonedRequest.json().catch(() => null);
|
|
130
274
|
} catch {
|
|
131
275
|
}
|
|
132
276
|
}
|
|
@@ -184,7 +328,10 @@ var fsHelpers = {
|
|
|
184
328
|
}
|
|
185
329
|
const { readFileSync } = await import("fs");
|
|
186
330
|
const buffer = readFileSync(path);
|
|
187
|
-
return buffer.buffer.slice(
|
|
331
|
+
return buffer.buffer.slice(
|
|
332
|
+
buffer.byteOffset,
|
|
333
|
+
buffer.byteOffset + buffer.byteLength
|
|
334
|
+
);
|
|
188
335
|
},
|
|
189
336
|
async existsSync(path) {
|
|
190
337
|
if (isDeno) {
|
|
@@ -279,6 +426,52 @@ var McpServer = class {
|
|
|
279
426
|
this.app.use("*", requestLogger);
|
|
280
427
|
return new Proxy(this, {
|
|
281
428
|
get(target, prop) {
|
|
429
|
+
if (prop === "use") {
|
|
430
|
+
return (...args) => {
|
|
431
|
+
const hasPath = typeof args[0] === "string";
|
|
432
|
+
const path = hasPath ? args[0] : "*";
|
|
433
|
+
const handlers = hasPath ? args.slice(1) : args;
|
|
434
|
+
const adaptedHandlers = handlers.map((handler) => {
|
|
435
|
+
if (isExpressMiddleware(handler)) {
|
|
436
|
+
return { __isExpressMiddleware: true, handler, path };
|
|
437
|
+
}
|
|
438
|
+
return handler;
|
|
439
|
+
});
|
|
440
|
+
const hasExpressMiddleware = adaptedHandlers.some(
|
|
441
|
+
(h) => h.__isExpressMiddleware
|
|
442
|
+
);
|
|
443
|
+
if (hasExpressMiddleware) {
|
|
444
|
+
Promise.all(
|
|
445
|
+
adaptedHandlers.map(async (h) => {
|
|
446
|
+
if (h.__isExpressMiddleware) {
|
|
447
|
+
const adapted = await adaptConnectMiddleware(
|
|
448
|
+
h.handler,
|
|
449
|
+
h.path
|
|
450
|
+
);
|
|
451
|
+
if (hasPath) {
|
|
452
|
+
target.app.use(path, adapted);
|
|
453
|
+
} else {
|
|
454
|
+
target.app.use(adapted);
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
if (hasPath) {
|
|
458
|
+
target.app.use(path, h);
|
|
459
|
+
} else {
|
|
460
|
+
target.app.use(h);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
).catch((err) => {
|
|
465
|
+
console.error(
|
|
466
|
+
"[MIDDLEWARE] Failed to adapt Express middleware:",
|
|
467
|
+
err
|
|
468
|
+
);
|
|
469
|
+
});
|
|
470
|
+
return target;
|
|
471
|
+
}
|
|
472
|
+
return target.app.use(...args);
|
|
473
|
+
};
|
|
474
|
+
}
|
|
282
475
|
if (prop in target) {
|
|
283
476
|
return target[prop];
|
|
284
477
|
}
|
|
@@ -845,13 +1038,11 @@ var McpServer = class {
|
|
|
845
1038
|
* @returns Promise that resolves when all widgets are mounted
|
|
846
1039
|
*/
|
|
847
1040
|
async mountWidgets(options) {
|
|
848
|
-
if (this.isProductionMode()) {
|
|
1041
|
+
if (this.isProductionMode() || isDeno) {
|
|
1042
|
+
console.log("[WIDGETS] Mounting widgets in production mode");
|
|
849
1043
|
await this.mountWidgetsProduction(options);
|
|
850
1044
|
} else {
|
|
851
|
-
|
|
852
|
-
console.log("[WIDGETS] Skipping dev mode widget mounting in Deno runtime (use production build)");
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
1045
|
+
console.log("[WIDGETS] Mounting widgets in development mode");
|
|
855
1046
|
await this.mountWidgetsDev(options);
|
|
856
1047
|
}
|
|
857
1048
|
}
|
|
@@ -902,13 +1093,21 @@ var McpServer = class {
|
|
|
902
1093
|
try {
|
|
903
1094
|
const viteModule = await new Function('return import("vite")')();
|
|
904
1095
|
createServer = viteModule.createServer;
|
|
905
|
-
const reactModule = await new Function(
|
|
1096
|
+
const reactModule = await new Function(
|
|
1097
|
+
'return import("@vitejs/plugin-react")'
|
|
1098
|
+
)();
|
|
906
1099
|
react = reactModule.default;
|
|
907
|
-
const tailwindModule = await new Function(
|
|
1100
|
+
const tailwindModule = await new Function(
|
|
1101
|
+
'return import("@tailwindcss/vite")'
|
|
1102
|
+
)();
|
|
908
1103
|
tailwindcss = tailwindModule.default;
|
|
909
1104
|
} catch (error) {
|
|
910
|
-
console.error(
|
|
911
|
-
|
|
1105
|
+
console.error(
|
|
1106
|
+
"[WIDGETS] Dev dependencies not available. Install vite, @vitejs/plugin-react, and @tailwindcss/vite for widget development."
|
|
1107
|
+
);
|
|
1108
|
+
console.error(
|
|
1109
|
+
"[WIDGETS] For production, use 'mcp-use build' to pre-build widgets."
|
|
1110
|
+
);
|
|
912
1111
|
return;
|
|
913
1112
|
}
|
|
914
1113
|
const widgets = entries.map((entry) => {
|
|
@@ -924,16 +1123,17 @@ var McpServer = class {
|
|
|
924
1123
|
const widgetTempDir = pathHelpers.join(tempDir, widget.name);
|
|
925
1124
|
await fs.mkdir(widgetTempDir, { recursive: true });
|
|
926
1125
|
const resourcesPath = pathHelpers.join(getCwd(), resourcesDir);
|
|
927
|
-
const relativeResourcesPath = pathHelpers.relative(
|
|
928
|
-
widgetTempDir,
|
|
929
|
-
resourcesPath
|
|
930
|
-
).replace(/\\/g, "/");
|
|
1126
|
+
const relativeResourcesPath = pathHelpers.relative(widgetTempDir, resourcesPath).replace(/\\/g, "/");
|
|
931
1127
|
const cssContent = `@import "tailwindcss";
|
|
932
1128
|
|
|
933
1129
|
/* Configure Tailwind to scan the resources directory */
|
|
934
1130
|
@source "${relativeResourcesPath}";
|
|
935
1131
|
`;
|
|
936
|
-
await fs.writeFile(
|
|
1132
|
+
await fs.writeFile(
|
|
1133
|
+
pathHelpers.join(widgetTempDir, "styles.css"),
|
|
1134
|
+
cssContent,
|
|
1135
|
+
"utf8"
|
|
1136
|
+
);
|
|
937
1137
|
const entryContent = `import React from 'react'
|
|
938
1138
|
import { createRoot } from 'react-dom/client'
|
|
939
1139
|
import './styles.css'
|
|
@@ -986,67 +1186,6 @@ if (container && Component) {
|
|
|
986
1186
|
origin: serverOrigin
|
|
987
1187
|
}
|
|
988
1188
|
});
|
|
989
|
-
const adaptExpressMiddleware = /* @__PURE__ */ __name((middleware) => {
|
|
990
|
-
return async (c, next) => {
|
|
991
|
-
const req = c.req.raw;
|
|
992
|
-
let handled = false;
|
|
993
|
-
const responseBody = [];
|
|
994
|
-
let statusCode = 200;
|
|
995
|
-
const headers = {};
|
|
996
|
-
const res = {
|
|
997
|
-
statusCode: 200,
|
|
998
|
-
status: /* @__PURE__ */ __name((code) => {
|
|
999
|
-
statusCode = code;
|
|
1000
|
-
res.statusCode = code;
|
|
1001
|
-
return res;
|
|
1002
|
-
}, "status"),
|
|
1003
|
-
setHeader: /* @__PURE__ */ __name((name, value) => {
|
|
1004
|
-
headers[name] = value;
|
|
1005
|
-
}, "setHeader"),
|
|
1006
|
-
getHeader: /* @__PURE__ */ __name((name) => headers[name], "getHeader"),
|
|
1007
|
-
write: /* @__PURE__ */ __name((chunk) => {
|
|
1008
|
-
responseBody.push(typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk);
|
|
1009
|
-
}, "write"),
|
|
1010
|
-
end: /* @__PURE__ */ __name((chunk) => {
|
|
1011
|
-
if (chunk) {
|
|
1012
|
-
responseBody.push(typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk);
|
|
1013
|
-
}
|
|
1014
|
-
handled = true;
|
|
1015
|
-
}, "end"),
|
|
1016
|
-
on: /* @__PURE__ */ __name(() => {
|
|
1017
|
-
}, "on"),
|
|
1018
|
-
once: /* @__PURE__ */ __name(() => {
|
|
1019
|
-
}, "once"),
|
|
1020
|
-
removeListener: /* @__PURE__ */ __name(() => {
|
|
1021
|
-
}, "removeListener")
|
|
1022
|
-
};
|
|
1023
|
-
const expressReq = {
|
|
1024
|
-
...req,
|
|
1025
|
-
url: new URL(req.url).pathname + new URL(req.url).search,
|
|
1026
|
-
originalUrl: req.url,
|
|
1027
|
-
baseUrl: "",
|
|
1028
|
-
path: new URL(req.url).pathname,
|
|
1029
|
-
query: Object.fromEntries(new URL(req.url).searchParams),
|
|
1030
|
-
params: {},
|
|
1031
|
-
body: {},
|
|
1032
|
-
headers: Object.fromEntries(req.headers.entries())
|
|
1033
|
-
};
|
|
1034
|
-
await new Promise((resolve, reject) => {
|
|
1035
|
-
middleware(expressReq, res, (err) => {
|
|
1036
|
-
if (err) reject(err);
|
|
1037
|
-
else resolve();
|
|
1038
|
-
});
|
|
1039
|
-
});
|
|
1040
|
-
if (handled) {
|
|
1041
|
-
const body = Buffer.concat(responseBody);
|
|
1042
|
-
return new Response(body, {
|
|
1043
|
-
status: statusCode,
|
|
1044
|
-
headers
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
return next();
|
|
1048
|
-
};
|
|
1049
|
-
}, "adaptExpressMiddleware");
|
|
1050
1189
|
this.app.use(`${baseRoute}/*`, async (c, next) => {
|
|
1051
1190
|
const url = new URL(c.req.url);
|
|
1052
1191
|
const pathname = url.pathname;
|
|
@@ -1074,7 +1213,11 @@ if (container && Component) {
|
|
|
1074
1213
|
}
|
|
1075
1214
|
await next();
|
|
1076
1215
|
});
|
|
1077
|
-
|
|
1216
|
+
const viteMiddleware = await adaptConnectMiddleware(
|
|
1217
|
+
viteServer.middlewares,
|
|
1218
|
+
`${baseRoute}/*`
|
|
1219
|
+
);
|
|
1220
|
+
this.app.use(`${baseRoute}/*`, viteMiddleware);
|
|
1078
1221
|
widgets.forEach((widget) => {
|
|
1079
1222
|
console.log(
|
|
1080
1223
|
`[WIDGET] ${widget.name} mounted at ${baseRoute}/${widget.name}`
|
|
@@ -1214,26 +1357,46 @@ if (container && Component) {
|
|
|
1214
1357
|
*/
|
|
1215
1358
|
async mountWidgetsProduction(options) {
|
|
1216
1359
|
const baseRoute = options?.baseRoute || "/mcp-use/widgets";
|
|
1217
|
-
const widgetsDir = pathHelpers.join(
|
|
1218
|
-
|
|
1360
|
+
const widgetsDir = pathHelpers.join(
|
|
1361
|
+
getCwd(),
|
|
1362
|
+
"dist",
|
|
1363
|
+
"resources",
|
|
1364
|
+
"widgets"
|
|
1365
|
+
);
|
|
1366
|
+
console.log("widgetsDir", widgetsDir);
|
|
1367
|
+
this.setupWidgetRoutes();
|
|
1368
|
+
const manifestPath = pathHelpers.join(getCwd(), "dist", ".mcp-use-manifest.json");
|
|
1369
|
+
let widgets = [];
|
|
1370
|
+
try {
|
|
1371
|
+
const manifestContent = await fsHelpers.readFileSync(manifestPath, "utf8");
|
|
1372
|
+
const manifest = JSON.parse(manifestContent);
|
|
1373
|
+
if (manifest.widgets && Array.isArray(manifest.widgets)) {
|
|
1374
|
+
widgets = manifest.widgets;
|
|
1375
|
+
console.log(`[WIDGETS] Loaded ${widgets.length} widget(s) from manifest`);
|
|
1376
|
+
} else {
|
|
1377
|
+
console.log("[WIDGETS] No widgets array found in manifest");
|
|
1378
|
+
}
|
|
1379
|
+
} catch (error) {
|
|
1219
1380
|
console.log(
|
|
1220
|
-
"[WIDGETS]
|
|
1381
|
+
"[WIDGETS] Could not read manifest file, falling back to directory listing:",
|
|
1382
|
+
error
|
|
1221
1383
|
);
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1384
|
+
try {
|
|
1385
|
+
const allEntries = await fsHelpers.readdirSync(widgetsDir);
|
|
1386
|
+
for (const name of allEntries) {
|
|
1387
|
+
const widgetPath = pathHelpers.join(widgetsDir, name);
|
|
1388
|
+
const indexPath = pathHelpers.join(widgetPath, "index.html");
|
|
1389
|
+
if (await fsHelpers.existsSync(indexPath)) {
|
|
1390
|
+
widgets.push(name);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
} catch (dirError) {
|
|
1394
|
+
console.log("[WIDGETS] Directory listing also failed:", dirError);
|
|
1232
1395
|
}
|
|
1233
1396
|
}
|
|
1234
1397
|
if (widgets.length === 0) {
|
|
1235
1398
|
console.log(
|
|
1236
|
-
"[WIDGETS] No built widgets found
|
|
1399
|
+
"[WIDGETS] No built widgets found"
|
|
1237
1400
|
);
|
|
1238
1401
|
return;
|
|
1239
1402
|
}
|
|
@@ -1294,7 +1457,10 @@ if (container && Component) {
|
|
|
1294
1457
|
let props = {};
|
|
1295
1458
|
let description = `Widget: ${widgetName}`;
|
|
1296
1459
|
try {
|
|
1297
|
-
const metadataContent = await fsHelpers.readFileSync(
|
|
1460
|
+
const metadataContent = await fsHelpers.readFileSync(
|
|
1461
|
+
metadataPath,
|
|
1462
|
+
"utf8"
|
|
1463
|
+
);
|
|
1298
1464
|
metadata = JSON.parse(metadataContent);
|
|
1299
1465
|
if (metadata.description) {
|
|
1300
1466
|
description = metadata.description;
|
|
@@ -1462,23 +1628,27 @@ if (container && Component) {
|
|
|
1462
1628
|
}
|
|
1463
1629
|
}, "send")
|
|
1464
1630
|
};
|
|
1465
|
-
return {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1631
|
+
return {
|
|
1632
|
+
expressReq,
|
|
1633
|
+
expressRes,
|
|
1634
|
+
getResponse: /* @__PURE__ */ __name(() => {
|
|
1635
|
+
if (ended) {
|
|
1636
|
+
if (responseBody.length > 0) {
|
|
1637
|
+
const body = isDeno ? Buffer.concat(responseBody) : Buffer.concat(responseBody);
|
|
1638
|
+
return new Response(body, {
|
|
1639
|
+
status: statusCode,
|
|
1640
|
+
headers
|
|
1641
|
+
});
|
|
1642
|
+
} else {
|
|
1643
|
+
return new Response(null, {
|
|
1644
|
+
status: statusCode,
|
|
1645
|
+
headers
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1478
1648
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
}
|
|
1649
|
+
return null;
|
|
1650
|
+
}, "getResponse")
|
|
1651
|
+
};
|
|
1482
1652
|
}, "createExpressLikeObjects");
|
|
1483
1653
|
this.app.post(endpoint, async (c) => {
|
|
1484
1654
|
const { expressReq, expressRes, getResponse } = createExpressLikeObjects(c);
|
|
@@ -1642,19 +1812,26 @@ if (container && Component) {
|
|
|
1642
1812
|
* ```
|
|
1643
1813
|
*/
|
|
1644
1814
|
async getHandler(options) {
|
|
1815
|
+
console.log("[MCP] Mounting widgets");
|
|
1645
1816
|
await this.mountWidgets({
|
|
1646
1817
|
baseRoute: "/mcp-use/widgets",
|
|
1647
1818
|
resourcesDir: "resources"
|
|
1648
1819
|
});
|
|
1820
|
+
console.log("[MCP] Mounted widgets");
|
|
1649
1821
|
await this.mountMcp();
|
|
1822
|
+
console.log("[MCP] Mounted MCP");
|
|
1823
|
+
console.log("[MCP] Mounting inspector");
|
|
1650
1824
|
await this.mountInspector();
|
|
1825
|
+
console.log("[MCP] Mounted inspector");
|
|
1651
1826
|
const fetchHandler = this.app.fetch.bind(this.app);
|
|
1652
1827
|
if (options?.provider === "supabase") {
|
|
1653
1828
|
return async (req) => {
|
|
1654
1829
|
const url = new URL(req.url);
|
|
1655
1830
|
const pathname = url.pathname;
|
|
1656
1831
|
let newPathname = pathname;
|
|
1657
|
-
const functionsMatch = pathname.match(
|
|
1832
|
+
const functionsMatch = pathname.match(
|
|
1833
|
+
/^\/functions\/v1\/[^/]+(\/.*)?$/
|
|
1834
|
+
);
|
|
1658
1835
|
if (functionsMatch) {
|
|
1659
1836
|
newPathname = functionsMatch[1] || "/";
|
|
1660
1837
|
} else {
|
|
@@ -1773,11 +1950,21 @@ if (container && Component) {
|
|
|
1773
1950
|
});
|
|
1774
1951
|
this.app.get("/mcp-use/widgets/assets/*", async (c) => {
|
|
1775
1952
|
const assetFile = c.req.path.split("/assets/")[1];
|
|
1776
|
-
const widgetsDir = pathHelpers.join(
|
|
1953
|
+
const widgetsDir = pathHelpers.join(
|
|
1954
|
+
getCwd(),
|
|
1955
|
+
"dist",
|
|
1956
|
+
"resources",
|
|
1957
|
+
"widgets"
|
|
1958
|
+
);
|
|
1777
1959
|
try {
|
|
1778
1960
|
const widgets = await fsHelpers.readdirSync(widgetsDir);
|
|
1779
1961
|
for (const widget of widgets) {
|
|
1780
|
-
const assetPath = pathHelpers.join(
|
|
1962
|
+
const assetPath = pathHelpers.join(
|
|
1963
|
+
widgetsDir,
|
|
1964
|
+
widget,
|
|
1965
|
+
"assets",
|
|
1966
|
+
assetFile
|
|
1967
|
+
);
|
|
1781
1968
|
if (await fsHelpers.existsSync(assetPath)) {
|
|
1782
1969
|
const content = await fsHelpers.readFile(assetPath);
|
|
1783
1970
|
const ext = assetFile.split(".").pop()?.toLowerCase();
|
|
@@ -2015,10 +2202,13 @@ function createMCPServer(name, config = {}) {
|
|
|
2015
2202
|
}
|
|
2016
2203
|
__name(createMCPServer, "createMCPServer");
|
|
2017
2204
|
export {
|
|
2205
|
+
adaptConnectMiddleware,
|
|
2206
|
+
adaptMiddleware,
|
|
2018
2207
|
buildWidgetUrl,
|
|
2019
2208
|
createExternalUrlResource,
|
|
2020
2209
|
createMCPServer,
|
|
2021
2210
|
createRawHtmlResource,
|
|
2022
2211
|
createRemoteDomResource,
|
|
2023
|
-
createUIResourceFromDefinition
|
|
2212
|
+
createUIResourceFromDefinition,
|
|
2213
|
+
isExpressMiddleware
|
|
2024
2214
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/server/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/server/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CzE"}
|
|
@@ -416,7 +416,7 @@ export declare class McpServer {
|
|
|
416
416
|
* ```
|
|
417
417
|
*/
|
|
418
418
|
getHandler(options?: {
|
|
419
|
-
provider?:
|
|
419
|
+
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
420
420
|
}): Promise<(req: Request) => Promise<Response>>;
|
|
421
421
|
/**
|
|
422
422
|
* Mount MCP Inspector UI at /inspector
|
|
@@ -557,7 +557,7 @@ export declare class McpServer {
|
|
|
557
557
|
}
|
|
558
558
|
export type McpServerInstance = Omit<McpServer, keyof HonoType> & HonoType & {
|
|
559
559
|
getHandler: (options?: {
|
|
560
|
-
provider?:
|
|
560
|
+
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
561
561
|
}) => Promise<(req: Request) => Promise<Response>>;
|
|
562
562
|
};
|
|
563
563
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsB,KAAK,IAAI,IAAI,QAAQ,EAAa,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsB,KAAK,IAAI,IAAI,QAAQ,EAAa,MAAM,MAAM,CAAC;AAY5E,OAAO,KAAK,EAEV,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EAEd,oBAAoB,EAErB,MAAM,kBAAkB,CAAC;AA4G1B,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,UAAU,CA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|
|
1
|
-
{"version":3,"file":"tsup.config.d.ts","sourceRoot":"","sources":["../tsup.config.ts"],"names":[],"mappings":";AAEA,
|
|
1
|
+
{"version":3,"file":"tsup.config.d.ts","sourceRoot":"","sources":["../tsup.config.ts"],"names":[],"mappings":";AAEA,wBAkCG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-use",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.5-dev.
|
|
4
|
+
"version": "1.2.5-dev.5",
|
|
5
5
|
"packageManager": "pnpm@10.6.1",
|
|
6
6
|
"description": "Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents and Clients + MCP Servers with support for MCP-UI.",
|
|
7
7
|
"author": "mcp-use, Inc.",
|
|
@@ -152,7 +152,9 @@
|
|
|
152
152
|
"optionalDependencies": {
|
|
153
153
|
"@tailwindcss/vite": "^4.1.15",
|
|
154
154
|
"@vitejs/plugin-react": "^5.0.4",
|
|
155
|
-
"vite": ">=5.4.21"
|
|
155
|
+
"vite": ">=5.4.21",
|
|
156
|
+
"connect": "^3.7.0",
|
|
157
|
+
"node-mocks-http": "^1.16.2"
|
|
156
158
|
},
|
|
157
159
|
"devDependencies": {
|
|
158
160
|
"@antfu/eslint-config": "^4.13.2",
|