mcp-use 1.2.5-dev.5 → 1.3.0-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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-73SH52J2.js → chunk-6EHM3S3M.js} +191 -8
- package/dist/{chunk-37MPZ3D6.js → chunk-TIUSJAAE.js} +12 -0
- package/dist/{chunk-X2HJQBDI.js → chunk-VNEGDXZO.js} +26 -1
- package/dist/index.cjs +226 -6
- package/dist/index.js +3 -3
- package/dist/src/agents/index.cjs +189 -6
- package/dist/src/agents/index.js +1 -1
- package/dist/src/agents/mcp_agent.d.ts +90 -2
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +201 -6
- package/dist/src/browser.js +2 -2
- package/dist/src/connectors/base.d.ts +11 -0
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/react/index.cjs +37 -0
- package/dist/src/react/index.js +2 -2
- package/dist/src/react/types.d.ts +7 -0
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +108 -58
- package/dist/src/server/index.js +108 -58
- package/dist/src/server/mcp-server.d.ts +5 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/package.json +41 -44
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/connectors/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACd,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,aAAa,CAAC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IASvD,6CAA6C;IACvC,OAAO,CACX,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAW,EACzC,OAAO,CAAC,EAAE,cAAc;IAc1B;;OAEG;cACa,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CAkClD"}
|
package/dist/src/react/index.cjs
CHANGED
|
@@ -542,6 +542,7 @@ var BaseConnector = class {
|
|
|
542
542
|
connectionManager = null;
|
|
543
543
|
toolsCache = null;
|
|
544
544
|
capabilitiesCache = null;
|
|
545
|
+
serverInfoCache = null;
|
|
545
546
|
connected = false;
|
|
546
547
|
opts;
|
|
547
548
|
constructor(opts = {}) {
|
|
@@ -576,6 +577,8 @@ var BaseConnector = class {
|
|
|
576
577
|
logger.debug("Caching server capabilities & tools");
|
|
577
578
|
const capabilities = this.client.getServerCapabilities();
|
|
578
579
|
this.capabilitiesCache = capabilities;
|
|
580
|
+
const serverInfo = this.client.getServerVersion();
|
|
581
|
+
this.serverInfoCache = serverInfo || null;
|
|
579
582
|
const listToolsRes = await this.client.listTools(
|
|
580
583
|
void 0,
|
|
581
584
|
defaultRequestOptions
|
|
@@ -583,6 +586,7 @@ var BaseConnector = class {
|
|
|
583
586
|
this.toolsCache = listToolsRes.tools ?? [];
|
|
584
587
|
logger.debug(`Fetched ${this.toolsCache.length} tools from server`);
|
|
585
588
|
logger.debug("Server capabilities:", capabilities);
|
|
589
|
+
logger.debug("Server info:", serverInfo);
|
|
586
590
|
return capabilities;
|
|
587
591
|
}
|
|
588
592
|
/** Lazily expose the cached tools list. */
|
|
@@ -592,6 +596,14 @@ var BaseConnector = class {
|
|
|
592
596
|
}
|
|
593
597
|
return this.toolsCache;
|
|
594
598
|
}
|
|
599
|
+
/** Expose cached server capabilities. */
|
|
600
|
+
get serverCapabilities() {
|
|
601
|
+
return this.capabilitiesCache;
|
|
602
|
+
}
|
|
603
|
+
/** Expose cached server info. */
|
|
604
|
+
get serverInfo() {
|
|
605
|
+
return this.serverInfoCache;
|
|
606
|
+
}
|
|
595
607
|
/** Call a tool on the server. */
|
|
596
608
|
async callTool(name, args, options) {
|
|
597
609
|
if (!this.client) {
|
|
@@ -1619,6 +1631,8 @@ function useMcp(options) {
|
|
|
1619
1631
|
const [resources, setResources] = (0, import_react.useState)([]);
|
|
1620
1632
|
const [resourceTemplates, setResourceTemplates] = (0, import_react.useState)([]);
|
|
1621
1633
|
const [prompts, setPrompts] = (0, import_react.useState)([]);
|
|
1634
|
+
const [serverInfo, setServerInfo] = (0, import_react.useState)();
|
|
1635
|
+
const [capabilities, setCapabilities] = (0, import_react.useState)();
|
|
1622
1636
|
const [error, setError] = (0, import_react.useState)(void 0);
|
|
1623
1637
|
const [log, setLog] = (0, import_react.useState)([]);
|
|
1624
1638
|
const [authUrl, setAuthUrl] = (0, import_react.useState)(void 0);
|
|
@@ -1767,6 +1781,17 @@ function useMcp(options) {
|
|
|
1767
1781
|
const session = await clientRef.current.createSession(serverName);
|
|
1768
1782
|
await session.initialize();
|
|
1769
1783
|
addLog("info", "\u2705 Successfully connected to MCP server");
|
|
1784
|
+
addLog("info", "Server info:", session.connector.serverInfo);
|
|
1785
|
+
addLog(
|
|
1786
|
+
"info",
|
|
1787
|
+
"Server capabilities:",
|
|
1788
|
+
session.connector.serverCapabilities
|
|
1789
|
+
);
|
|
1790
|
+
console.log("[useMcp] Server info:", session.connector.serverInfo);
|
|
1791
|
+
console.log(
|
|
1792
|
+
"[useMcp] Server capabilities:",
|
|
1793
|
+
session.connector.serverCapabilities
|
|
1794
|
+
);
|
|
1770
1795
|
setState("ready");
|
|
1771
1796
|
successfulTransportRef.current = transportTypeParam;
|
|
1772
1797
|
setTools(session.connector.tools || []);
|
|
@@ -1774,6 +1799,16 @@ function useMcp(options) {
|
|
|
1774
1799
|
setResources(resourcesResult.resources || []);
|
|
1775
1800
|
const promptsResult = await session.connector.listPrompts();
|
|
1776
1801
|
setPrompts(promptsResult.prompts || []);
|
|
1802
|
+
const serverInfo2 = session.connector.serverInfo;
|
|
1803
|
+
const capabilities2 = session.connector.serverCapabilities;
|
|
1804
|
+
if (serverInfo2) {
|
|
1805
|
+
console.log("[useMcp] Server info:", serverInfo2);
|
|
1806
|
+
setServerInfo(serverInfo2);
|
|
1807
|
+
}
|
|
1808
|
+
if (capabilities2) {
|
|
1809
|
+
console.log("[useMcp] Server capabilities:", capabilities2);
|
|
1810
|
+
setCapabilities(capabilities2);
|
|
1811
|
+
}
|
|
1777
1812
|
return "success";
|
|
1778
1813
|
} catch (err) {
|
|
1779
1814
|
const errorMessage = err?.message || String(err);
|
|
@@ -2136,6 +2171,8 @@ function useMcp(options) {
|
|
|
2136
2171
|
resources,
|
|
2137
2172
|
resourceTemplates,
|
|
2138
2173
|
prompts,
|
|
2174
|
+
serverInfo,
|
|
2175
|
+
capabilities,
|
|
2139
2176
|
error,
|
|
2140
2177
|
log,
|
|
2141
2178
|
authUrl,
|
package/dist/src/react/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
useWidgetProps,
|
|
5
5
|
useWidgetState,
|
|
6
6
|
useWidgetTheme
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-VNEGDXZO.js";
|
|
8
8
|
import {
|
|
9
9
|
onMcpAuthorization
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-TIUSJAAE.js";
|
|
11
11
|
import "../../chunk-34R6SIER.js";
|
|
12
12
|
import "../../chunk-3GQAWCBQ.js";
|
|
13
13
|
export {
|
|
@@ -52,6 +52,13 @@ export type UseMcpResult = {
|
|
|
52
52
|
resourceTemplates: ResourceTemplate[];
|
|
53
53
|
/** List of prompts available from the connected MCP server */
|
|
54
54
|
prompts: Prompt[];
|
|
55
|
+
/** Server information from the initialize response */
|
|
56
|
+
serverInfo?: {
|
|
57
|
+
name: string;
|
|
58
|
+
version?: string;
|
|
59
|
+
};
|
|
60
|
+
/** Server capabilities from the initialize response */
|
|
61
|
+
capabilities?: Record<string, any>;
|
|
55
62
|
/**
|
|
56
63
|
* The current state of the MCP connection:
|
|
57
64
|
* - 'discovering': Checking server existence and capabilities (including auth requirements).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,6CAA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AAE,CAAC;SAC9D,CAAC,CAAC;KACJ,CAAC,CAAC;IACH,+DAA+D;IAC/D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kDAAkD;IAClD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,+GAA+G;IAC/G,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA+
|
|
1
|
+
{"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA+0B3D"}
|
|
@@ -465,7 +465,7 @@ var McpServer = class {
|
|
|
465
465
|
return new Proxy(this, {
|
|
466
466
|
get(target, prop) {
|
|
467
467
|
if (prop === "use") {
|
|
468
|
-
return (...args) => {
|
|
468
|
+
return async (...args) => {
|
|
469
469
|
const hasPath = typeof args[0] === "string";
|
|
470
470
|
const path = hasPath ? args[0] : "*";
|
|
471
471
|
const handlers = hasPath ? args.slice(1) : args;
|
|
@@ -479,7 +479,7 @@ var McpServer = class {
|
|
|
479
479
|
(h) => h.__isExpressMiddleware
|
|
480
480
|
);
|
|
481
481
|
if (hasExpressMiddleware) {
|
|
482
|
-
Promise.all(
|
|
482
|
+
await Promise.all(
|
|
483
483
|
adaptedHandlers.map(async (h) => {
|
|
484
484
|
if (h.__isExpressMiddleware) {
|
|
485
485
|
const adapted = await adaptConnectMiddleware(
|
|
@@ -499,12 +499,7 @@ var McpServer = class {
|
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
})
|
|
502
|
-
)
|
|
503
|
-
console.error(
|
|
504
|
-
"[MIDDLEWARE] Failed to adapt Express middleware:",
|
|
505
|
-
err
|
|
506
|
-
);
|
|
507
|
-
});
|
|
502
|
+
);
|
|
508
503
|
return target;
|
|
509
504
|
}
|
|
510
505
|
return target.app.use(...args);
|
|
@@ -518,6 +513,13 @@ var McpServer = class {
|
|
|
518
513
|
}
|
|
519
514
|
});
|
|
520
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* Gets the server base URL with fallback to host:port if not configured
|
|
518
|
+
* @returns The complete base URL for the server
|
|
519
|
+
*/
|
|
520
|
+
getServerBaseUrl() {
|
|
521
|
+
return this.serverBaseUrl || `http://${this.serverHost}:${this.serverPort}`;
|
|
522
|
+
}
|
|
521
523
|
/**
|
|
522
524
|
* Define a static resource that can be accessed by clients
|
|
523
525
|
*
|
|
@@ -965,7 +967,18 @@ var McpServer = class {
|
|
|
965
967
|
baseUrl: configBaseUrl,
|
|
966
968
|
port: configPort
|
|
967
969
|
};
|
|
968
|
-
|
|
970
|
+
const uiResource = createUIResourceFromDefinition(
|
|
971
|
+
definition,
|
|
972
|
+
params,
|
|
973
|
+
urlConfig
|
|
974
|
+
);
|
|
975
|
+
if (definition._meta && Object.keys(definition._meta).length > 0) {
|
|
976
|
+
uiResource.resource._meta = {
|
|
977
|
+
...uiResource.resource._meta,
|
|
978
|
+
...definition._meta
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
return uiResource;
|
|
969
982
|
}
|
|
970
983
|
/**
|
|
971
984
|
* Build a complete URL for a widget including query parameters
|
|
@@ -1054,9 +1067,9 @@ var McpServer = class {
|
|
|
1054
1067
|
async readBuildManifest() {
|
|
1055
1068
|
try {
|
|
1056
1069
|
const manifestPath = pathHelpers.join(
|
|
1057
|
-
getCwd(),
|
|
1070
|
+
isDeno ? "." : getCwd(),
|
|
1058
1071
|
"dist",
|
|
1059
|
-
"
|
|
1072
|
+
"mcp-use.json"
|
|
1060
1073
|
);
|
|
1061
1074
|
const content = await fsHelpers.readFileSync(manifestPath, "utf8");
|
|
1062
1075
|
return JSON.parse(content);
|
|
@@ -1206,7 +1219,7 @@ if (container && Component) {
|
|
|
1206
1219
|
"utf8"
|
|
1207
1220
|
);
|
|
1208
1221
|
}
|
|
1209
|
-
const serverOrigin = this.
|
|
1222
|
+
const serverOrigin = this.getServerBaseUrl();
|
|
1210
1223
|
console.log(
|
|
1211
1224
|
`[WIDGETS] Serving ${entries.length} widget(s) with shared Vite dev server and HMR`
|
|
1212
1225
|
);
|
|
@@ -1288,14 +1301,13 @@ if (container && Component) {
|
|
|
1288
1301
|
error
|
|
1289
1302
|
);
|
|
1290
1303
|
}
|
|
1291
|
-
console.log("[WIDGET dev] Metadata:", metadata);
|
|
1292
1304
|
let html = "";
|
|
1293
1305
|
try {
|
|
1294
1306
|
html = await fsHelpers.readFileSync(
|
|
1295
1307
|
pathHelpers.join(tempDir, widget.name, "index.html"),
|
|
1296
1308
|
"utf8"
|
|
1297
1309
|
);
|
|
1298
|
-
const mcpUrl =
|
|
1310
|
+
const mcpUrl = this.getServerBaseUrl();
|
|
1299
1311
|
if (mcpUrl && html) {
|
|
1300
1312
|
const htmlWithoutComments = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
1301
1313
|
const baseTagRegex = /<base\s+[^>]*\/?>/i;
|
|
@@ -1318,18 +1330,19 @@ if (container && Component) {
|
|
|
1318
1330
|
}
|
|
1319
1331
|
}
|
|
1320
1332
|
}
|
|
1333
|
+
const baseUrl = this.getServerBaseUrl();
|
|
1321
1334
|
html = html.replace(
|
|
1322
1335
|
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1323
|
-
`src="${
|
|
1336
|
+
`src="${baseUrl}/mcp-use/widgets/$1"`
|
|
1324
1337
|
);
|
|
1325
1338
|
html = html.replace(
|
|
1326
1339
|
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1327
|
-
`href="${
|
|
1340
|
+
`href="${baseUrl}/mcp-use/widgets/$1"`
|
|
1328
1341
|
);
|
|
1329
1342
|
html = html.replace(
|
|
1330
1343
|
/<head[^>]*>/i,
|
|
1331
1344
|
`<head>
|
|
1332
|
-
<script>window.__getFile = (filename) => { return "${
|
|
1345
|
+
<script>window.__getFile = (filename) => { return "${baseUrl}/mcp-use/widgets/${widget.name}/"+filename }</script>`
|
|
1333
1346
|
);
|
|
1334
1347
|
} catch (error) {
|
|
1335
1348
|
console.error(
|
|
@@ -1396,23 +1409,35 @@ if (container && Component) {
|
|
|
1396
1409
|
async mountWidgetsProduction(options) {
|
|
1397
1410
|
const baseRoute = options?.baseRoute || "/mcp-use/widgets";
|
|
1398
1411
|
const widgetsDir = pathHelpers.join(
|
|
1399
|
-
getCwd(),
|
|
1412
|
+
isDeno ? "." : getCwd(),
|
|
1400
1413
|
"dist",
|
|
1401
1414
|
"resources",
|
|
1402
1415
|
"widgets"
|
|
1403
1416
|
);
|
|
1404
1417
|
console.log("widgetsDir", widgetsDir);
|
|
1405
1418
|
this.setupWidgetRoutes();
|
|
1406
|
-
const manifestPath =
|
|
1419
|
+
const manifestPath = "./dist/mcp-use.json";
|
|
1407
1420
|
let widgets = [];
|
|
1421
|
+
let widgetsMetadata = {};
|
|
1408
1422
|
try {
|
|
1409
|
-
const manifestContent = await fsHelpers.readFileSync(
|
|
1423
|
+
const manifestContent = await fsHelpers.readFileSync(
|
|
1424
|
+
manifestPath,
|
|
1425
|
+
"utf8"
|
|
1426
|
+
);
|
|
1410
1427
|
const manifest = JSON.parse(manifestContent);
|
|
1411
|
-
if (manifest.widgets && Array.isArray(manifest.widgets)) {
|
|
1428
|
+
if (manifest.widgets && typeof manifest.widgets === "object" && !Array.isArray(manifest.widgets)) {
|
|
1429
|
+
widgets = Object.keys(manifest.widgets);
|
|
1430
|
+
widgetsMetadata = manifest.widgets;
|
|
1431
|
+
console.log(
|
|
1432
|
+
`[WIDGETS] Loaded ${widgets.length} widget(s) from manifest`
|
|
1433
|
+
);
|
|
1434
|
+
} else if (manifest.widgets && Array.isArray(manifest.widgets)) {
|
|
1412
1435
|
widgets = manifest.widgets;
|
|
1413
|
-
console.log(
|
|
1436
|
+
console.log(
|
|
1437
|
+
`[WIDGETS] Loaded ${widgets.length} widget(s) from manifest (legacy format)`
|
|
1438
|
+
);
|
|
1414
1439
|
} else {
|
|
1415
|
-
console.log("[WIDGETS] No widgets
|
|
1440
|
+
console.log("[WIDGETS] No widgets found in manifest");
|
|
1416
1441
|
}
|
|
1417
1442
|
} catch (error) {
|
|
1418
1443
|
console.log(
|
|
@@ -1433,9 +1458,7 @@ if (container && Component) {
|
|
|
1433
1458
|
}
|
|
1434
1459
|
}
|
|
1435
1460
|
if (widgets.length === 0) {
|
|
1436
|
-
console.log(
|
|
1437
|
-
"[WIDGETS] No built widgets found"
|
|
1438
|
-
);
|
|
1461
|
+
console.log("[WIDGETS] No built widgets found");
|
|
1439
1462
|
return;
|
|
1440
1463
|
}
|
|
1441
1464
|
console.log(
|
|
@@ -1444,11 +1467,10 @@ if (container && Component) {
|
|
|
1444
1467
|
for (const widgetName of widgets) {
|
|
1445
1468
|
const widgetPath = pathHelpers.join(widgetsDir, widgetName);
|
|
1446
1469
|
const indexPath = pathHelpers.join(widgetPath, "index.html");
|
|
1447
|
-
const metadataPath = pathHelpers.join(widgetPath, "metadata.json");
|
|
1448
1470
|
let html = "";
|
|
1449
1471
|
try {
|
|
1450
1472
|
html = await fsHelpers.readFileSync(indexPath, "utf8");
|
|
1451
|
-
const mcpUrl =
|
|
1473
|
+
const mcpUrl = this.getServerBaseUrl();
|
|
1452
1474
|
if (mcpUrl && html) {
|
|
1453
1475
|
const htmlWithoutComments = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
1454
1476
|
const baseTagRegex = /<base\s+[^>]*\/?>/i;
|
|
@@ -1470,18 +1492,19 @@ if (container && Component) {
|
|
|
1470
1492
|
);
|
|
1471
1493
|
}
|
|
1472
1494
|
}
|
|
1495
|
+
const baseUrl = this.getServerBaseUrl();
|
|
1473
1496
|
html = html.replace(
|
|
1474
1497
|
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1475
|
-
`src="${
|
|
1498
|
+
`src="${baseUrl}/mcp-use/widgets/$1"`
|
|
1476
1499
|
);
|
|
1477
1500
|
html = html.replace(
|
|
1478
1501
|
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1479
|
-
`href="${
|
|
1502
|
+
`href="${baseUrl}/mcp-use/widgets/$1"`
|
|
1480
1503
|
);
|
|
1481
1504
|
html = html.replace(
|
|
1482
1505
|
/<head[^>]*>/i,
|
|
1483
1506
|
`<head>
|
|
1484
|
-
<script>window.__getFile = (filename) => { return "${
|
|
1507
|
+
<script>window.__getFile = (filename) => { return "${baseUrl}/mcp-use/widgets/${widgetName}/"+filename }</script>`
|
|
1485
1508
|
);
|
|
1486
1509
|
}
|
|
1487
1510
|
} catch (error) {
|
|
@@ -1491,25 +1514,14 @@ if (container && Component) {
|
|
|
1491
1514
|
);
|
|
1492
1515
|
continue;
|
|
1493
1516
|
}
|
|
1494
|
-
|
|
1517
|
+
const metadata = widgetsMetadata[widgetName] || {};
|
|
1495
1518
|
let props = {};
|
|
1496
1519
|
let description = `Widget: ${widgetName}`;
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
metadata = JSON.parse(metadataContent);
|
|
1503
|
-
if (metadata.description) {
|
|
1504
|
-
description = metadata.description;
|
|
1505
|
-
}
|
|
1506
|
-
if (metadata.inputs) {
|
|
1507
|
-
props = metadata.inputs;
|
|
1508
|
-
}
|
|
1509
|
-
} catch (error) {
|
|
1510
|
-
console.log(
|
|
1511
|
-
`[WIDGET] No metadata found for ${widgetName}, using defaults`
|
|
1512
|
-
);
|
|
1520
|
+
if (metadata.description) {
|
|
1521
|
+
description = metadata.description;
|
|
1522
|
+
}
|
|
1523
|
+
if (metadata.inputs) {
|
|
1524
|
+
props = metadata.inputs;
|
|
1513
1525
|
}
|
|
1514
1526
|
this.uiResource({
|
|
1515
1527
|
name: widgetName,
|
|
@@ -1787,16 +1799,53 @@ if (container && Component) {
|
|
|
1787
1799
|
await this.mountMcp();
|
|
1788
1800
|
await this.mountInspector();
|
|
1789
1801
|
if (isDeno) {
|
|
1802
|
+
const corsHeaders = {
|
|
1803
|
+
"Access-Control-Allow-Origin": "*",
|
|
1804
|
+
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type"
|
|
1805
|
+
};
|
|
1790
1806
|
globalThis.Deno.serve(
|
|
1791
1807
|
{ port: this.serverPort, hostname: this.serverHost },
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1808
|
+
async (req) => {
|
|
1809
|
+
if (req.method === "OPTIONS") {
|
|
1810
|
+
return new Response("ok", { headers: corsHeaders });
|
|
1811
|
+
}
|
|
1812
|
+
const url = new URL(req.url);
|
|
1813
|
+
const pathname = url.pathname;
|
|
1814
|
+
let newPathname = pathname;
|
|
1815
|
+
const functionsMatch = pathname.match(
|
|
1816
|
+
/^\/functions\/v1\/[^/]+(\/.*)?$/
|
|
1817
|
+
);
|
|
1818
|
+
if (functionsMatch) {
|
|
1819
|
+
newPathname = functionsMatch[1] || "/";
|
|
1820
|
+
} else {
|
|
1821
|
+
const functionNameMatch = pathname.match(/^\/([^/]+)(\/.*)?$/);
|
|
1822
|
+
if (functionNameMatch && functionNameMatch[2]) {
|
|
1823
|
+
newPathname = functionNameMatch[2] || "/";
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
let finalReq = req;
|
|
1827
|
+
if (newPathname !== pathname) {
|
|
1828
|
+
const newUrl = new URL(newPathname + url.search, url.origin);
|
|
1829
|
+
finalReq = new Request(newUrl, {
|
|
1830
|
+
method: req.method,
|
|
1831
|
+
headers: req.headers,
|
|
1832
|
+
body: req.body,
|
|
1833
|
+
redirect: req.redirect
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
const response = await this.app.fetch(finalReq);
|
|
1837
|
+
const newHeaders = new Headers(response.headers);
|
|
1838
|
+
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
1839
|
+
newHeaders.set(key, value);
|
|
1840
|
+
});
|
|
1841
|
+
return new Response(response.body, {
|
|
1842
|
+
status: response.status,
|
|
1843
|
+
statusText: response.statusText,
|
|
1844
|
+
headers: newHeaders
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1799
1847
|
);
|
|
1848
|
+
console.log(`[SERVER] Listening`);
|
|
1800
1849
|
} else {
|
|
1801
1850
|
const { serve } = await import("@hono/node-server");
|
|
1802
1851
|
serve(
|
|
@@ -2030,18 +2079,19 @@ if (container && Component) {
|
|
|
2030
2079
|
);
|
|
2031
2080
|
try {
|
|
2032
2081
|
let html = await fsHelpers.readFileSync(filePath, "utf8");
|
|
2082
|
+
const baseUrl = this.getServerBaseUrl();
|
|
2033
2083
|
html = html.replace(
|
|
2034
2084
|
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
2035
|
-
`src="${
|
|
2085
|
+
`src="${baseUrl}/mcp-use/widgets/$1"`
|
|
2036
2086
|
);
|
|
2037
2087
|
html = html.replace(
|
|
2038
2088
|
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
2039
|
-
`href="${
|
|
2089
|
+
`href="${baseUrl}/mcp-use/widgets/$1"`
|
|
2040
2090
|
);
|
|
2041
2091
|
html = html.replace(
|
|
2042
2092
|
/<head[^>]*>/i,
|
|
2043
2093
|
`<head>
|
|
2044
|
-
<script>window.__getFile = (filename) => { return "${
|
|
2094
|
+
<script>window.__getFile = (filename) => { return "${baseUrl}/mcp-use/widgets/${widget}/"+filename }</script>`
|
|
2045
2095
|
);
|
|
2046
2096
|
return c.html(html);
|
|
2047
2097
|
} catch {
|