mcp-use 2.0.0-beta.6 → 2.0.0-beta.8
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-FC2Z2VFO.js +99 -0
- package/dist/chunk-FC2Z2VFO.js.map +1 -0
- package/dist/chunk-FCGJJVL2.js +739 -0
- package/dist/chunk-FCGJJVL2.js.map +1 -0
- package/dist/chunk-KIZ72TIK.js +38 -0
- package/dist/chunk-KIZ72TIK.js.map +1 -0
- package/dist/{chunk-PMPGMSYA.js → chunk-QUUANIE4.js} +27 -80
- package/dist/chunk-QUUANIE4.js.map +1 -0
- package/dist/chunk-STCR3P5O.js +95 -0
- package/dist/chunk-STCR3P5O.js.map +1 -0
- package/dist/chunk-Z326HADF.js +82 -0
- package/dist/chunk-Z326HADF.js.map +1 -0
- package/dist/commands/build.js +5 -2
- package/dist/commands/build.js.map +1 -1
- package/dist/completable.d.ts +9 -0
- package/dist/completable.d.ts.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/fetch-app.d.ts +26 -0
- package/dist/fetch-app.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -39
- package/dist/index.js.map +1 -1
- package/dist/inspector-shell.d.ts +1 -1
- package/dist/inspector-shell.d.ts.map +1 -1
- package/dist/internal/resource-completion.js +7 -0
- package/dist/internal/resource-completion.js.map +1 -0
- package/dist/landing-handler-VQRYCQOV.js +31 -0
- package/dist/landing-handler-VQRYCQOV.js.map +1 -0
- package/dist/landing-handler.d.ts +22 -0
- package/dist/landing-handler.d.ts.map +1 -0
- package/dist/landing.d.ts +65 -0
- package/dist/landing.d.ts.map +1 -0
- package/dist/landing.js +7 -0
- package/dist/landing.js.map +1 -0
- package/dist/oauth/better-auth.d.ts +29 -0
- package/dist/oauth/better-auth.d.ts.map +1 -0
- package/dist/oauth/better-auth.js +76 -0
- package/dist/oauth/better-auth.js.map +1 -0
- package/dist/oauth/index.js +2 -1
- package/dist/resource-completion.d.ts +12 -0
- package/dist/resource-completion.d.ts.map +1 -0
- package/dist/resources.d.ts +38 -4
- package/dist/resources.d.ts.map +1 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/views/document.d.ts.map +1 -1
- package/dist/views/routes.d.ts.map +1 -1
- package/package.json +10 -2
- package/dist/chunk-PMPGMSYA.js.map +0 -1
- package/dist/chunk-VV2P4ZFZ.js +0 -187
- package/dist/chunk-VV2P4ZFZ.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/views/origin.ts
|
|
2
|
+
function stripTrailingSlashes(value) {
|
|
3
|
+
return value.replace(/\/+$/, "");
|
|
4
|
+
}
|
|
5
|
+
function readEnv(name) {
|
|
6
|
+
if (typeof process === "undefined") {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const value = process.env[name];
|
|
10
|
+
return value !== void 0 && value !== "" ? value : void 0;
|
|
11
|
+
}
|
|
12
|
+
function parseForwardedHeader(header) {
|
|
13
|
+
for (const part of header.split(",")) {
|
|
14
|
+
const params = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const token of part.split(";")) {
|
|
16
|
+
const [key, ...rest] = token.trim().split("=");
|
|
17
|
+
if (key === void 0 || rest.length === 0) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
params.set(key.toLowerCase(), rest.join("=").replace(/^"|"$/g, ""));
|
|
21
|
+
}
|
|
22
|
+
const proto = params.get("proto");
|
|
23
|
+
const host = params.get("host");
|
|
24
|
+
if (proto !== void 0 && host !== void 0) {
|
|
25
|
+
return `${proto}://${host}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function resolveRequestOriginFromHeaders(request) {
|
|
31
|
+
const forwarded = request.headers.get("forwarded");
|
|
32
|
+
if (forwarded !== null) {
|
|
33
|
+
const fromForwarded = parseForwardedHeader(forwarded);
|
|
34
|
+
if (fromForwarded !== void 0) {
|
|
35
|
+
return fromForwarded;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const proto = request.headers.get("x-forwarded-proto");
|
|
39
|
+
const host = request.headers.get("x-forwarded-host");
|
|
40
|
+
if (proto !== null && host !== null) {
|
|
41
|
+
const firstHost = host.split(",")[0]?.trim();
|
|
42
|
+
const firstProto = proto.split(",")[0]?.trim();
|
|
43
|
+
if (firstHost !== void 0 && firstProto !== void 0 && firstHost !== "") {
|
|
44
|
+
return `${firstProto}://${firstHost}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return new URL(request.url).origin;
|
|
48
|
+
}
|
|
49
|
+
function resolveServerOrigin(request) {
|
|
50
|
+
const mcpUrl = readEnv("MCP_URL");
|
|
51
|
+
if (mcpUrl !== void 0) {
|
|
52
|
+
try {
|
|
53
|
+
return new URL(mcpUrl).origin;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return resolveRequestOriginFromHeaders(request);
|
|
58
|
+
}
|
|
59
|
+
function originFromAssetsBase(assetsBase) {
|
|
60
|
+
try {
|
|
61
|
+
return new URL(assetsBase).origin;
|
|
62
|
+
} catch {
|
|
63
|
+
return assetsBase;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function normalizeAssetsBaseUrl(value) {
|
|
67
|
+
return stripTrailingSlashes(value);
|
|
68
|
+
}
|
|
69
|
+
function resolveAssetsBase(request) {
|
|
70
|
+
const assetsUrl = readEnv("MCP_ASSETS_URL");
|
|
71
|
+
if (assetsUrl !== void 0) {
|
|
72
|
+
try {
|
|
73
|
+
return normalizeAssetsBaseUrl(new URL(assetsUrl).href.replace(/\/$/, ""));
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return resolveServerOrigin(request);
|
|
78
|
+
}
|
|
79
|
+
function hasExplicitAssetsBase() {
|
|
80
|
+
const assetsUrl = readEnv("MCP_ASSETS_URL");
|
|
81
|
+
if (assetsUrl === void 0) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
new URL(assetsUrl);
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
resolveServerOrigin,
|
|
94
|
+
originFromAssetsBase,
|
|
95
|
+
normalizeAssetsBaseUrl,
|
|
96
|
+
resolveAssetsBase,
|
|
97
|
+
hasExplicitAssetsBase
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=chunk-FC2Z2VFO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/views/origin.ts"],"sourcesContent":["/**\n * Resolve public origins and asset URL prefixes for view documents and CSP.\n *\n * **Server origin** (`resolveServerOrigin`): MCP endpoint / API base — OAuth\n * resource identity, `connectDomains`, dev HMR websocket host.\n *\n * **Assets base** (`resolveAssetsBase`): prefix for view JS/CSS and\n * `public/` URLs — may include a path (CDN bucket prefix).\n */\n\n/** Strip trailing slashes from a URL prefix. */\nexport function stripTrailingSlashes(value: string): string {\n return value.replace(/\\/+$/, \"\");\n}\n\nfunction readEnv(name: string): string | undefined {\n if (typeof process === \"undefined\") {\n return undefined;\n }\n const value = process.env[name];\n return value !== undefined && value !== \"\" ? value : undefined;\n}\n\nfunction parseForwardedHeader(header: string): string | undefined {\n for (const part of header.split(\",\")) {\n const params = new Map<string, string>();\n for (const token of part.split(\";\")) {\n const [key, ...rest] = token.trim().split(\"=\");\n if (key === undefined || rest.length === 0) {\n continue;\n }\n params.set(key.toLowerCase(), rest.join(\"=\").replace(/^\"|\"$/g, \"\"));\n }\n const proto = params.get(\"proto\");\n const host = params.get(\"host\");\n if (proto !== undefined && host !== undefined) {\n return `${proto}://${host}`;\n }\n }\n return undefined;\n}\n\n/**\n * Resolve origin from forwarded headers or the request URL (no env override).\n */\nexport function resolveRequestOriginFromHeaders(request: Request): string {\n const forwarded = request.headers.get(\"forwarded\");\n if (forwarded !== null) {\n const fromForwarded = parseForwardedHeader(forwarded);\n if (fromForwarded !== undefined) {\n return fromForwarded;\n }\n }\n\n const proto = request.headers.get(\"x-forwarded-proto\");\n const host = request.headers.get(\"x-forwarded-host\");\n if (proto !== null && host !== null) {\n const firstHost = host.split(\",\")[0]?.trim();\n const firstProto = proto.split(\",\")[0]?.trim();\n if (\n firstHost !== undefined &&\n firstProto !== undefined &&\n firstHost !== \"\"\n ) {\n return `${firstProto}://${firstHost}`;\n }\n }\n\n return new URL(request.url).origin;\n}\n\n/**\n * Server public origin — `MCP_URL` when valid, else forwarded/request origin.\n *\n * Uses `.origin` only (path suffix on `MCP_URL` is ignored).\n */\nexport function resolveServerOrigin(request: Request): string {\n const mcpUrl = readEnv(\"MCP_URL\");\n if (mcpUrl !== undefined) {\n try {\n return new URL(mcpUrl).origin;\n } catch {\n // Fall through when MCP_URL is malformed.\n }\n }\n return resolveRequestOriginFromHeaders(request);\n}\n\n/**\n * Extract the origin from an assets URL prefix (origin + optional path).\n */\nexport function originFromAssetsBase(assetsBase: string): string {\n try {\n return new URL(assetsBase).origin;\n } catch {\n return assetsBase;\n }\n}\n\n/**\n * Normalize `MCP_ASSETS_URL` to a URL prefix without trailing slash.\n */\nexport function normalizeAssetsBaseUrl(value: string): string {\n return stripTrailingSlashes(value);\n}\n\n/**\n * Assets URL prefix for view JS/CSS and `public/` — `MCP_ASSETS_URL` when set,\n * else server origin from {@link resolveServerOrigin}.\n */\nexport function resolveAssetsBase(request: Request): string {\n const assetsUrl = readEnv(\"MCP_ASSETS_URL\");\n if (assetsUrl !== undefined) {\n try {\n return normalizeAssetsBaseUrl(new URL(assetsUrl).href.replace(/\\/$/, \"\"));\n } catch {\n // Fall through when MCP_ASSETS_URL is malformed.\n }\n }\n return resolveServerOrigin(request);\n}\n\n/**\n * @deprecated Alias for {@link resolveServerOrigin} — kept for OAuth callers.\n */\nexport function resolveRequestOrigin(request: Request): string {\n return resolveServerOrigin(request);\n}\n\n/**\n * Whether `MCP_ASSETS_URL` is explicitly configured (distinct from server).\n */\nexport function hasExplicitAssetsBase(): boolean {\n const assetsUrl = readEnv(\"MCP_ASSETS_URL\");\n if (assetsUrl === undefined) {\n return false;\n }\n try {\n new URL(assetsUrl);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAWO,SAAS,qBAAqB,OAAuB;AAC1D,SAAO,MAAM,QAAQ,QAAQ,EAAE;AACjC;AAEA,SAAS,QAAQ,MAAkC;AACjD,MAAI,OAAO,YAAY,aAAa;AAClC,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,QAAQ,IAAI,IAAI;AAC9B,SAAO,UAAU,UAAa,UAAU,KAAK,QAAQ;AACvD;AAEA,SAAS,qBAAqB,QAAoC;AAChE,aAAW,QAAQ,OAAO,MAAM,GAAG,GAAG;AACpC,UAAM,SAAS,oBAAI,IAAoB;AACvC,eAAW,SAAS,KAAK,MAAM,GAAG,GAAG;AACnC,YAAM,CAAC,KAAK,GAAG,IAAI,IAAI,MAAM,KAAK,EAAE,MAAM,GAAG;AAC7C,UAAI,QAAQ,UAAa,KAAK,WAAW,GAAG;AAC1C;AAAA,MACF;AACA,aAAO,IAAI,IAAI,YAAY,GAAG,KAAK,KAAK,GAAG,EAAE,QAAQ,UAAU,EAAE,CAAC;AAAA,IACpE;AACA,UAAM,QAAQ,OAAO,IAAI,OAAO;AAChC,UAAM,OAAO,OAAO,IAAI,MAAM;AAC9B,QAAI,UAAU,UAAa,SAAS,QAAW;AAC7C,aAAO,GAAG,KAAK,MAAM,IAAI;AAAA,IAC3B;AAAA,EACF;AACA,SAAO;AACT;AAKO,SAAS,gCAAgC,SAA0B;AACxE,QAAM,YAAY,QAAQ,QAAQ,IAAI,WAAW;AACjD,MAAI,cAAc,MAAM;AACtB,UAAM,gBAAgB,qBAA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