mcp-use 1.2.5-dev.3 → 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 +332 -115
- 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 +332 -115
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts +12 -4
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +47 -42
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);
|
|
@@ -1619,14 +1789,16 @@ if (container && Component) {
|
|
|
1619
1789
|
* Unlike `listen()`, this method does not start a server - it only prepares the
|
|
1620
1790
|
* routes and returns the handler function that can be used with external servers.
|
|
1621
1791
|
*
|
|
1792
|
+
* @param options - Optional configuration for the handler
|
|
1793
|
+
* @param options.provider - Platform provider (e.g., 'supabase') to handle platform-specific path rewriting
|
|
1622
1794
|
* @returns Promise that resolves to the fetch handler function
|
|
1623
1795
|
*
|
|
1624
1796
|
* @example
|
|
1625
1797
|
* ```typescript
|
|
1626
|
-
* // For Supabase Edge Functions
|
|
1798
|
+
* // For Supabase Edge Functions (handles path rewriting automatically)
|
|
1627
1799
|
* const server = createMCPServer('my-server');
|
|
1628
1800
|
* server.tool({ ... });
|
|
1629
|
-
* const handler = await server.getHandler();
|
|
1801
|
+
* const handler = await server.getHandler({ provider: 'supabase' });
|
|
1630
1802
|
* Deno.serve(handler);
|
|
1631
1803
|
* ```
|
|
1632
1804
|
*
|
|
@@ -1639,14 +1811,46 @@ if (container && Component) {
|
|
|
1639
1811
|
* export default { fetch: handler };
|
|
1640
1812
|
* ```
|
|
1641
1813
|
*/
|
|
1642
|
-
async getHandler() {
|
|
1814
|
+
async getHandler(options) {
|
|
1815
|
+
console.log("[MCP] Mounting widgets");
|
|
1643
1816
|
await this.mountWidgets({
|
|
1644
1817
|
baseRoute: "/mcp-use/widgets",
|
|
1645
1818
|
resourcesDir: "resources"
|
|
1646
1819
|
});
|
|
1820
|
+
console.log("[MCP] Mounted widgets");
|
|
1647
1821
|
await this.mountMcp();
|
|
1822
|
+
console.log("[MCP] Mounted MCP");
|
|
1823
|
+
console.log("[MCP] Mounting inspector");
|
|
1648
1824
|
await this.mountInspector();
|
|
1825
|
+
console.log("[MCP] Mounted inspector");
|
|
1649
1826
|
const fetchHandler = this.app.fetch.bind(this.app);
|
|
1827
|
+
if (options?.provider === "supabase") {
|
|
1828
|
+
return async (req) => {
|
|
1829
|
+
const url = new URL(req.url);
|
|
1830
|
+
const pathname = url.pathname;
|
|
1831
|
+
let newPathname = pathname;
|
|
1832
|
+
const functionsMatch = pathname.match(
|
|
1833
|
+
/^\/functions\/v1\/[^/]+(\/.*)?$/
|
|
1834
|
+
);
|
|
1835
|
+
if (functionsMatch) {
|
|
1836
|
+
newPathname = functionsMatch[1] || "/";
|
|
1837
|
+
} else {
|
|
1838
|
+
const functionNameMatch = pathname.match(/^\/([^/]+)(\/.*)?$/);
|
|
1839
|
+
if (functionNameMatch && functionNameMatch[2]) {
|
|
1840
|
+
newPathname = functionNameMatch[2] || "/";
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
const newUrl = new URL(newPathname + url.search, url.origin);
|
|
1844
|
+
const newReq = new Request(newUrl, {
|
|
1845
|
+
method: req.method,
|
|
1846
|
+
headers: req.headers,
|
|
1847
|
+
body: req.body,
|
|
1848
|
+
redirect: req.redirect
|
|
1849
|
+
});
|
|
1850
|
+
const result = await fetchHandler(newReq);
|
|
1851
|
+
return result;
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1650
1854
|
return async (req) => {
|
|
1651
1855
|
const result = await fetchHandler(req);
|
|
1652
1856
|
return result;
|
|
@@ -1746,11 +1950,21 @@ if (container && Component) {
|
|
|
1746
1950
|
});
|
|
1747
1951
|
this.app.get("/mcp-use/widgets/assets/*", async (c) => {
|
|
1748
1952
|
const assetFile = c.req.path.split("/assets/")[1];
|
|
1749
|
-
const widgetsDir = pathHelpers.join(
|
|
1953
|
+
const widgetsDir = pathHelpers.join(
|
|
1954
|
+
getCwd(),
|
|
1955
|
+
"dist",
|
|
1956
|
+
"resources",
|
|
1957
|
+
"widgets"
|
|
1958
|
+
);
|
|
1750
1959
|
try {
|
|
1751
1960
|
const widgets = await fsHelpers.readdirSync(widgetsDir);
|
|
1752
1961
|
for (const widget of widgets) {
|
|
1753
|
-
const assetPath = pathHelpers.join(
|
|
1962
|
+
const assetPath = pathHelpers.join(
|
|
1963
|
+
widgetsDir,
|
|
1964
|
+
widget,
|
|
1965
|
+
"assets",
|
|
1966
|
+
assetFile
|
|
1967
|
+
);
|
|
1754
1968
|
if (await fsHelpers.existsSync(assetPath)) {
|
|
1755
1969
|
const content = await fsHelpers.readFile(assetPath);
|
|
1756
1970
|
const ext = assetFile.split(".").pop()?.toLowerCase();
|
|
@@ -1988,10 +2202,13 @@ function createMCPServer(name, config = {}) {
|
|
|
1988
2202
|
}
|
|
1989
2203
|
__name(createMCPServer, "createMCPServer");
|
|
1990
2204
|
export {
|
|
2205
|
+
adaptConnectMiddleware,
|
|
2206
|
+
adaptMiddleware,
|
|
1991
2207
|
buildWidgetUrl,
|
|
1992
2208
|
createExternalUrlResource,
|
|
1993
2209
|
createMCPServer,
|
|
1994
2210
|
createRawHtmlResource,
|
|
1995
2211
|
createRemoteDomResource,
|
|
1996
|
-
createUIResourceFromDefinition
|
|
2212
|
+
createUIResourceFromDefinition,
|
|
2213
|
+
isExpressMiddleware
|
|
1997
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"}
|
|
@@ -393,14 +393,16 @@ export declare class McpServer {
|
|
|
393
393
|
* Unlike `listen()`, this method does not start a server - it only prepares the
|
|
394
394
|
* routes and returns the handler function that can be used with external servers.
|
|
395
395
|
*
|
|
396
|
+
* @param options - Optional configuration for the handler
|
|
397
|
+
* @param options.provider - Platform provider (e.g., 'supabase') to handle platform-specific path rewriting
|
|
396
398
|
* @returns Promise that resolves to the fetch handler function
|
|
397
399
|
*
|
|
398
400
|
* @example
|
|
399
401
|
* ```typescript
|
|
400
|
-
* // For Supabase Edge Functions
|
|
402
|
+
* // For Supabase Edge Functions (handles path rewriting automatically)
|
|
401
403
|
* const server = createMCPServer('my-server');
|
|
402
404
|
* server.tool({ ... });
|
|
403
|
-
* const handler = await server.getHandler();
|
|
405
|
+
* const handler = await server.getHandler({ provider: 'supabase' });
|
|
404
406
|
* Deno.serve(handler);
|
|
405
407
|
* ```
|
|
406
408
|
*
|
|
@@ -413,7 +415,9 @@ export declare class McpServer {
|
|
|
413
415
|
* export default { fetch: handler };
|
|
414
416
|
* ```
|
|
415
417
|
*/
|
|
416
|
-
getHandler(
|
|
418
|
+
getHandler(options?: {
|
|
419
|
+
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
420
|
+
}): Promise<(req: Request) => Promise<Response>>;
|
|
417
421
|
/**
|
|
418
422
|
* Mount MCP Inspector UI at /inspector
|
|
419
423
|
*
|
|
@@ -551,7 +555,11 @@ export declare class McpServer {
|
|
|
551
555
|
*/
|
|
552
556
|
private parseTemplateUri;
|
|
553
557
|
}
|
|
554
|
-
export type McpServerInstance = Omit<McpServer, keyof HonoType> & HonoType
|
|
558
|
+
export type McpServerInstance = Omit<McpServer, keyof HonoType> & HonoType & {
|
|
559
|
+
getHandler: (options?: {
|
|
560
|
+
provider?: "supabase" | "cloudflare" | "deno-deploy";
|
|
561
|
+
}) => Promise<(req: Request) => Promise<Response>>;
|
|
562
|
+
};
|
|
555
563
|
/**
|
|
556
564
|
* Create a new MCP server instance
|
|
557
565
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.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,sBAAsB;IAqC9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,gBAAgB;CA4BzB;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,QAAQ,CAAC,GAC7D,QAAQ,GAAG;IACT,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE;QACrB,QAAQ,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC;KACtD,KAAK,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;CACpD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,iBAAiB,CASnB"}
|
|
@@ -1 +1 @@
|
|
|
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"}
|