@lovable.dev/mcp-js 0.22.1-rc.9 → 0.22.2-rc.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.
- package/dist/authorize-CumVyk7p.d.cts +27 -0
- package/dist/authorize-D6p4-9_D.d.ts +27 -0
- package/dist/base-DCe0kP79.d.cts +29 -0
- package/dist/base-DCe0kP79.d.ts +29 -0
- package/dist/cli/extract-manifest.cjs +116 -201
- package/dist/cli/extract-manifest.d.cts +1 -1
- package/dist/cli/extract-manifest.d.ts +1 -1
- package/dist/cli/extract-manifest.js +117 -156
- package/dist/content-D5LJAHyM.js +12 -0
- package/dist/content-NCYIGgOb.cjs +17 -0
- package/dist/context-BweeEcoA.cjs +56 -0
- package/dist/context-CIpPzN7P.js +51 -0
- package/dist/cors-CSDhBjFd.cjs +913 -0
- package/dist/cors-rWp_tbLZ.js +830 -0
- package/dist/forwarded--h4efJy-.js +43 -0
- package/dist/forwarded-Pi8Hs5Ps.cjs +48 -0
- package/dist/fs-errors-CWNzOV75.cjs +11 -0
- package/dist/fs-errors-PA2t1TIp.js +6 -0
- package/dist/index.cjs +129 -329
- package/dist/index.d.cts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +118 -177
- package/dist/{io-D4srzRKc.d.ts → io-CfSPxeBN.d.ts} +6 -4
- package/dist/io-DPYvBqET.d.cts +15 -0
- package/dist/list-tools-B4TTPEl1.d.cts +8 -0
- package/dist/list-tools-CFUX-uo-.cjs +57 -0
- package/dist/list-tools-DVJrjtmH.js +46 -0
- package/dist/list-tools-bh6-eqZM.d.ts +8 -0
- package/dist/logger-2OXtfiIW.js +141 -0
- package/dist/logger-BqPOa_E1.cjs +194 -0
- package/dist/mcp-BNcpj8o7.cjs +128 -0
- package/dist/mcp-Bx3bJHzH.js +123 -0
- package/dist/metadata-path-CAkNcfyY.js +12 -0
- package/dist/metadata-path-zd7NSNoa.cjs +17 -0
- package/dist/package-CgwD4Ywz.js +4 -0
- package/dist/package-DzstF8Ih.cjs +9 -0
- package/dist/paths-IS65L6TA.js +7 -0
- package/dist/paths-OP318a6c.cjs +18 -0
- package/dist/protocols/mcp/index.cjs +3 -750
- package/dist/protocols/mcp/index.d.cts +6 -7
- package/dist/protocols/mcp/index.d.ts +6 -7
- package/dist/protocols/mcp/index.js +2 -12
- package/dist/protocols/oauth-metadata.cjs +48 -539
- package/dist/protocols/oauth-metadata.d.cts +5 -6
- package/dist/protocols/oauth-metadata.d.ts +5 -6
- package/dist/protocols/oauth-metadata.js +52 -10
- package/dist/protocols/rest/index.cjs +5 -843
- package/dist/protocols/rest/index.d.cts +7 -10
- package/dist/protocols/rest/index.d.ts +7 -10
- package/dist/protocols/rest/index.js +3 -16
- package/dist/rest-BRshnow2.js +117 -0
- package/dist/rest-C4ZEGSIV.cjs +122 -0
- package/dist/stacks/supabase/index.cjs +76 -1318
- package/dist/stacks/supabase/index.d.cts +29 -30
- package/dist/stacks/supabase/index.d.ts +29 -30
- package/dist/stacks/supabase/index.js +73 -89
- package/dist/stacks/supabase/vite.cjs +258 -287
- package/dist/stacks/supabase/vite.d.cts +24 -24
- package/dist/stacks/supabase/vite.d.ts +24 -24
- package/dist/stacks/supabase/vite.js +252 -252
- package/dist/stacks/tanstack/index.cjs +42 -1272
- package/dist/stacks/tanstack/index.d.cts +8 -9
- package/dist/stacks/tanstack/index.d.ts +8 -9
- package/dist/stacks/tanstack/index.js +36 -41
- package/dist/stacks/tanstack/vite.cjs +223 -312
- package/dist/stacks/tanstack/vite.d.cts +80 -81
- package/dist/stacks/tanstack/vite.d.ts +80 -81
- package/dist/stacks/tanstack/vite.js +216 -282
- package/dist/types-BYdYYTjk.d.cts +321 -0
- package/dist/types-BYdYYTjk.d.ts +321 -0
- package/package.json +4 -4
- package/dist/authorize-BMeXd_Sh.d.ts +0 -25
- package/dist/base-CM-KCpp6.d.ts +0 -28
- package/dist/chunk-5DFH6VN6.js +0 -741
- package/dist/chunk-6DXGZZA4.js +0 -6
- package/dist/chunk-6QFZYYUV.js +0 -11
- package/dist/chunk-AYV4CWAJ.js +0 -141
- package/dist/chunk-H37EB22A.js +0 -125
- package/dist/chunk-K3OSKUCH.js +0 -79
- package/dist/chunk-KUYKBTCQ.js +0 -58
- package/dist/chunk-MA5H6PSF.js +0 -46
- package/dist/chunk-MTJQGT2W.js +0 -6
- package/dist/chunk-UQK5UO6C.js +0 -26
- package/dist/chunk-XQWJN6DC.js +0 -14
- package/dist/chunk-Y3ZFPEQH.js +0 -8
- package/dist/chunk-Z3ICQ7MB.js +0 -114
- package/dist/types-qqrmJ736.d.ts +0 -321
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./types-BYdYYTjk.cjs";
|
|
2
|
+
//#region src/auth/authorize.d.ts
|
|
3
|
+
interface McpRuntimeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Public MCP protocol path. REST companion handlers pass this so OAuth
|
|
6
|
+
* resource/audience checks bind to `/mcp`, not internal `/.mcp/*` RPC URLs.
|
|
7
|
+
*/
|
|
8
|
+
resourcePath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Host-relative path of the SDK-served protected-resource metadata document.
|
|
11
|
+
* The Vite plugin injects it into every emitted handler when it generates the
|
|
12
|
+
* PRM route, so the 401 challenge advertises the same path the route serves.
|
|
13
|
+
* Its presence is the signal that the SDK owns the PRM document, so it is
|
|
14
|
+
* mutually exclusive with `auth.protectedResourceMetadataUrl` (which points at
|
|
15
|
+
* an externally hosted document). Defaults to the well-known path when absent.
|
|
16
|
+
*/
|
|
17
|
+
metadataPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Derive the request origin (and thus the advertised `resource`/metadata URLs)
|
|
20
|
+
* from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters read
|
|
21
|
+
* this before invoking the handler, so the OAuth runtime never sees it; safe
|
|
22
|
+
* only behind a proxy that overwrites the header (see `core/forwarded.ts`).
|
|
23
|
+
*/
|
|
24
|
+
trustForwardedHost?: boolean;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { McpRuntimeOptions as t };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./types-BYdYYTjk.js";
|
|
2
|
+
//#region src/auth/authorize.d.ts
|
|
3
|
+
interface McpRuntimeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Public MCP protocol path. REST companion handlers pass this so OAuth
|
|
6
|
+
* resource/audience checks bind to `/mcp`, not internal `/.mcp/*` RPC URLs.
|
|
7
|
+
*/
|
|
8
|
+
resourcePath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Host-relative path of the SDK-served protected-resource metadata document.
|
|
11
|
+
* The Vite plugin injects it into every emitted handler when it generates the
|
|
12
|
+
* PRM route, so the 401 challenge advertises the same path the route serves.
|
|
13
|
+
* Its presence is the signal that the SDK owns the PRM document, so it is
|
|
14
|
+
* mutually exclusive with `auth.protectedResourceMetadataUrl` (which points at
|
|
15
|
+
* an externally hosted document). Defaults to the well-known path when absent.
|
|
16
|
+
*/
|
|
17
|
+
metadataPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Derive the request origin (and thus the advertised `resource`/metadata URLs)
|
|
20
|
+
* from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters read
|
|
21
|
+
* this before invoking the handler, so the OAuth runtime never sees it; safe
|
|
22
|
+
* only behind a proxy that overwrites the header (see `core/forwarded.ts`).
|
|
23
|
+
*/
|
|
24
|
+
trustForwardedHost?: boolean;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { McpRuntimeOptions as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/metrics/impl/base.d.ts
|
|
2
|
+
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "auth_config_error";
|
|
3
|
+
/** One recorded MCP call. Carries no arguments or response payloads — only the
|
|
4
|
+
* tool name, the JSON-RPC method, the result class, timing, and byte sizes.
|
|
5
|
+
* `errorText` is the sole exception: it is logged locally for debugging and
|
|
6
|
+
* deliberately never included in the OTLP payload (see `emit` / `buildLogsPayload`). */
|
|
7
|
+
interface InvocationRecord {
|
|
8
|
+
/** Tool name for `tools/call`; `null` for list/initialize, transport faults, and auth-config failures. */
|
|
9
|
+
tool: string | null;
|
|
10
|
+
/** JSON-RPC method, e.g. `tools/call`; `authorize` for auth-config failures. */
|
|
11
|
+
method: string;
|
|
12
|
+
outcome: InvocationOutcome;
|
|
13
|
+
durationMs: number;
|
|
14
|
+
reqBytes?: number;
|
|
15
|
+
resBytes?: number;
|
|
16
|
+
/** The app end-user that made the call (the access token `sub`), or
|
|
17
|
+
* `undefined` when the request is unauthenticated. Not a Lovable identity. */
|
|
18
|
+
endUserId?: string;
|
|
19
|
+
/** The `tool_error` message (text content of an `isError` result). Local log
|
|
20
|
+
* only — never sent to the collector, so it stays on-box for the operator. */
|
|
21
|
+
errorText?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A per-request telemetry recorder. `emit` logs the invocation and sends it as a
|
|
24
|
+
* single OTLP POST, awaited so it lands before the request ends. */
|
|
25
|
+
interface MetricsRecorder {
|
|
26
|
+
emit(ev: InvocationRecord): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { MetricsRecorder as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/metrics/impl/base.d.ts
|
|
2
|
+
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "auth_config_error";
|
|
3
|
+
/** One recorded MCP call. Carries no arguments or response payloads — only the
|
|
4
|
+
* tool name, the JSON-RPC method, the result class, timing, and byte sizes.
|
|
5
|
+
* `errorText` is the sole exception: it is logged locally for debugging and
|
|
6
|
+
* deliberately never included in the OTLP payload (see `emit` / `buildLogsPayload`). */
|
|
7
|
+
interface InvocationRecord {
|
|
8
|
+
/** Tool name for `tools/call`; `null` for list/initialize, transport faults, and auth-config failures. */
|
|
9
|
+
tool: string | null;
|
|
10
|
+
/** JSON-RPC method, e.g. `tools/call`; `authorize` for auth-config failures. */
|
|
11
|
+
method: string;
|
|
12
|
+
outcome: InvocationOutcome;
|
|
13
|
+
durationMs: number;
|
|
14
|
+
reqBytes?: number;
|
|
15
|
+
resBytes?: number;
|
|
16
|
+
/** The app end-user that made the call (the access token `sub`), or
|
|
17
|
+
* `undefined` when the request is unauthenticated. Not a Lovable identity. */
|
|
18
|
+
endUserId?: string;
|
|
19
|
+
/** The `tool_error` message (text content of an `isError` result). Local log
|
|
20
|
+
* only — never sent to the collector, so it stays on-box for the operator. */
|
|
21
|
+
errorText?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A per-request telemetry recorder. `emit` logs the invocation and sends it as a
|
|
24
|
+
* single OTLP POST, awaited so it lands before the request ends. */
|
|
25
|
+
interface MetricsRecorder {
|
|
26
|
+
emit(ev: InvocationRecord): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { MetricsRecorder as t };
|
|
@@ -1,219 +1,134 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/core/fs-errors.ts
|
|
11
|
-
function isFileMissing(err) {
|
|
12
|
-
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// package.json
|
|
16
|
-
var version = "0.22.1-rc.9";
|
|
17
|
-
|
|
18
|
-
// src/protocols/rest/list-tools.ts
|
|
19
|
-
var import_zod_compat = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
20
|
-
var import_zod_json_schema_compat = require("@modelcontextprotocol/sdk/server/zod-json-schema-compat.js");
|
|
21
|
-
|
|
22
|
-
// src/core/logger.ts
|
|
23
|
-
var LEVEL_RANK = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
24
|
-
function isLogLevel(value) {
|
|
25
|
-
return typeof value === "string" && value in LEVEL_RANK;
|
|
26
|
-
}
|
|
27
|
-
var LOG_LEVEL_ENV_VAR = "LOVABLE_MCP_LOG_LEVEL";
|
|
28
|
-
function readEnvLevel() {
|
|
29
|
-
try {
|
|
30
|
-
const raw = typeof process !== "undefined" ? process.env?.[LOG_LEVEL_ENV_VAR] : void 0;
|
|
31
|
-
const normalized = raw?.trim().toLowerCase();
|
|
32
|
-
return isLogLevel(normalized) ? normalized : void 0;
|
|
33
|
-
} catch {
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
var currentLevel = readEnvLevel() ?? "debug";
|
|
38
|
-
|
|
39
|
-
// src/auth/verifier.ts
|
|
40
|
-
var import_jose = require("jose");
|
|
41
|
-
|
|
42
|
-
// src/protocols/rest/list-tools.ts
|
|
43
|
-
function shapeToJsonSchema(shape) {
|
|
44
|
-
if (!shape)
|
|
45
|
-
return null;
|
|
46
|
-
try {
|
|
47
|
-
return (0, import_zod_json_schema_compat.toJsonSchemaCompat)((0, import_zod_compat.objectFromShape)(shape));
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function buildMcpListing(mcp) {
|
|
53
|
-
return {
|
|
54
|
-
server: { name: mcp.name, version: mcp.version, title: mcp.title },
|
|
55
|
-
tools: mcp.tools.map((tool) => ({
|
|
56
|
-
name: tool.name,
|
|
57
|
-
title: tool.title,
|
|
58
|
-
description: tool.description,
|
|
59
|
-
annotations: tool.annotations,
|
|
60
|
-
inputSchema: shapeToJsonSchema(tool.inputSchema),
|
|
61
|
-
outputSchema: shapeToJsonSchema(tool.outputSchema)
|
|
62
|
-
}))
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/manifest/extract.ts
|
|
67
|
-
var MANIFEST_VERSION = 1;
|
|
68
|
-
var MANIFEST_RELATIVE_PATH = ".lovable/mcp/manifest.json";
|
|
2
|
+
const require_package = require("../package-DzstF8Ih.cjs");
|
|
3
|
+
const require_list_tools = require("../list-tools-CFUX-uo-.cjs");
|
|
4
|
+
const require_fs_errors = require("../fs-errors-CWNzOV75.cjs");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let vite = require("vite");
|
|
8
|
+
let node_crypto = require("node:crypto");
|
|
9
|
+
const MANIFEST_RELATIVE_PATH = ".lovable/mcp/manifest.json";
|
|
69
10
|
function manifestAuth(auth) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (auth.requiredScopes !== void 0)
|
|
88
|
-
oauth.required_scopes = auth.requiredScopes;
|
|
89
|
-
if (auth.jwksUri !== void 0)
|
|
90
|
-
oauth.jwks_uri = auth.jwksUri;
|
|
91
|
-
if (auth.algorithms !== void 0)
|
|
92
|
-
oauth.algorithms = auth.algorithms;
|
|
93
|
-
if (auth.clockToleranceSeconds !== void 0)
|
|
94
|
-
oauth.clock_tolerance_seconds = auth.clockToleranceSeconds;
|
|
95
|
-
return oauth;
|
|
11
|
+
if (!auth) return { type: "none" };
|
|
12
|
+
const oauth = {
|
|
13
|
+
type: "oauth",
|
|
14
|
+
issuer: auth.issuer
|
|
15
|
+
};
|
|
16
|
+
if (auth.resource !== void 0) oauth.resource = auth.resource;
|
|
17
|
+
if (auth.resourceName !== void 0) oauth.resource_name = auth.resourceName;
|
|
18
|
+
if (auth.resourceDocumentation !== void 0) oauth.resource_documentation = auth.resourceDocumentation;
|
|
19
|
+
if (auth.protectedResourceMetadataUrl !== void 0) oauth.protected_resource_metadata_url = auth.protectedResourceMetadataUrl;
|
|
20
|
+
if (auth.requireOAuthClientClaim !== void 0) oauth.require_oauth_client_claim = auth.requireOAuthClientClaim;
|
|
21
|
+
if (auth.acceptResourceClaim !== void 0) oauth.accept_resource_claim = auth.acceptResourceClaim;
|
|
22
|
+
if (auth.acceptedAudiences !== void 0) oauth.accepted_audiences = auth.acceptedAudiences;
|
|
23
|
+
if (auth.requiredScopes !== void 0) oauth.required_scopes = auth.requiredScopes;
|
|
24
|
+
if (auth.jwksUri !== void 0) oauth.jwks_uri = auth.jwksUri;
|
|
25
|
+
if (auth.algorithms !== void 0) oauth.algorithms = auth.algorithms;
|
|
26
|
+
if (auth.clockToleranceSeconds !== void 0) oauth.clock_tolerance_seconds = auth.clockToleranceSeconds;
|
|
27
|
+
return oauth;
|
|
96
28
|
}
|
|
97
29
|
function isToolShape(tool) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return typeof t.name === "string" && typeof t.title === "string" && typeof t.description === "string";
|
|
30
|
+
if (typeof tool !== "object" || tool === null) return false;
|
|
31
|
+
const t = tool;
|
|
32
|
+
return typeof t.name === "string" && typeof t.title === "string" && typeof t.description === "string";
|
|
102
33
|
}
|
|
103
34
|
function isAuthShape(auth) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const a = auth;
|
|
109
|
-
return a.type === "oauth" && typeof a.issuer === "string" && a.issuer.length > 0;
|
|
35
|
+
if (auth === void 0) return true;
|
|
36
|
+
if (typeof auth !== "object" || auth === null) return false;
|
|
37
|
+
const a = auth;
|
|
38
|
+
return a.type === "oauth" && typeof a.issuer === "string" && a.issuer.length > 0;
|
|
110
39
|
}
|
|
111
40
|
function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
path: urlPath,
|
|
122
|
-
auth: manifestAuth(def.auth),
|
|
123
|
-
mcp: buildMcpListing(def)
|
|
124
|
-
};
|
|
41
|
+
const def = definition;
|
|
42
|
+
if (!(!!def && typeof def === "object" && typeof def.name === "string" && typeof def.title === "string" && typeof def.version === "string" && Array.isArray(def.tools) && def.tools.every(isToolShape) && isAuthShape(def.auth))) throw new Error(`@lovable.dev/mcp-js: ${source} must \`export default defineMcp(...)\` (got ${definition == null ? "no default export" : typeof definition}).`);
|
|
43
|
+
return {
|
|
44
|
+
version: 1,
|
|
45
|
+
sdk_version: require_package.version,
|
|
46
|
+
path: urlPath,
|
|
47
|
+
auth: manifestAuth(def.auth),
|
|
48
|
+
mcp: require_list_tools.buildMcpListing(def)
|
|
49
|
+
};
|
|
125
50
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/manifest/ssr-loader.ts
|
|
53
|
+
async function produceViaSsr(projectRoot, alias, entryAbs, urlPath) {
|
|
54
|
+
const server = await (0, vite.createServer)({
|
|
55
|
+
configFile: false,
|
|
56
|
+
root: projectRoot,
|
|
57
|
+
logLevel: "silent",
|
|
58
|
+
server: {
|
|
59
|
+
middlewareMode: true,
|
|
60
|
+
hmr: false,
|
|
61
|
+
watch: null
|
|
62
|
+
},
|
|
63
|
+
optimizeDeps: { noDiscovery: true },
|
|
64
|
+
resolve: { alias }
|
|
65
|
+
});
|
|
66
|
+
try {
|
|
67
|
+
return manifestFromDefinition((await server.ssrLoadModule(entryAbs)).default, urlPath, entryAbs);
|
|
68
|
+
} finally {
|
|
69
|
+
await server.close();
|
|
70
|
+
}
|
|
144
71
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var DEFAULT_MCP_ENTRY = "src/lib/mcp/index.ts";
|
|
149
|
-
var DEFAULT_MCP_PATH = "/mcp";
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/manifest/io.ts
|
|
74
|
+
const MCP_PLUGIN_NAME_PREFIX = "@lovable.dev/mcp-js";
|
|
150
75
|
function writeManifestIfChanged(file, manifest) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
throw err;
|
|
172
|
-
}
|
|
76
|
+
const content = JSON.stringify(manifest, null, 2) + "\n";
|
|
77
|
+
let existing;
|
|
78
|
+
try {
|
|
79
|
+
existing = (0, node_fs.readFileSync)(file, "utf8");
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (!require_fs_errors.isFileMissing(err)) throw err;
|
|
82
|
+
}
|
|
83
|
+
if (existing === content) return;
|
|
84
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(file), { recursive: true });
|
|
85
|
+
const tmp = `${file}.${(0, node_crypto.randomUUID)()}.tmp`;
|
|
86
|
+
try {
|
|
87
|
+
(0, node_fs.writeFileSync)(tmp, content, "utf8");
|
|
88
|
+
(0, node_fs.renameSync)(tmp, file);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
try {
|
|
91
|
+
(0, node_fs.unlinkSync)(tmp);
|
|
92
|
+
} catch {}
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
173
95
|
}
|
|
174
96
|
function removeManifest(file) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
97
|
+
try {
|
|
98
|
+
(0, node_fs.unlinkSync)(file);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (!require_fs_errors.isFileMissing(err)) throw err;
|
|
101
|
+
}
|
|
181
102
|
}
|
|
182
103
|
async function syncManifest(manifestFile, entryAbs, urlPath, produce) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const manifest = await produce(entryAbs, urlPath);
|
|
196
|
-
writeManifestIfChanged(manifestFile, manifest);
|
|
104
|
+
let entryExists = true;
|
|
105
|
+
try {
|
|
106
|
+
(0, node_fs.lstatSync)(entryAbs);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (!require_fs_errors.isFileMissing(err)) throw err;
|
|
109
|
+
entryExists = false;
|
|
110
|
+
}
|
|
111
|
+
if (!entryExists) {
|
|
112
|
+
removeManifest(manifestFile);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
writeManifestIfChanged(manifestFile, await produce(entryAbs, urlPath));
|
|
197
116
|
}
|
|
198
|
-
async function runExtract(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
entryAbs,
|
|
209
|
-
urlPath,
|
|
210
|
-
(entry, path) => produceViaSsr(projectRoot2, alias, entry, path)
|
|
211
|
-
);
|
|
117
|
+
async function runExtract(projectRoot) {
|
|
118
|
+
const resolved = await (0, vite.resolveConfig)({
|
|
119
|
+
root: projectRoot,
|
|
120
|
+
logLevel: "silent"
|
|
121
|
+
}, "serve");
|
|
122
|
+
const alias = resolved.resolve?.alias ?? [];
|
|
123
|
+
const pluginApi = resolved.plugins.find((p) => typeof p.name === "string" && p.name.startsWith(MCP_PLUGIN_NAME_PREFIX))?.api;
|
|
124
|
+
const entryAbs = pluginApi?.mcpEntry ?? (0, node_path.resolve)(projectRoot, "src/lib/mcp/index.ts");
|
|
125
|
+
const urlPath = pluginApi?.urlPath ?? "/mcp";
|
|
126
|
+
await syncManifest((0, node_path.resolve)(projectRoot, MANIFEST_RELATIVE_PATH), entryAbs, urlPath, (entry, path) => produceViaSsr(projectRoot, alias, entry, path));
|
|
212
127
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
process.exit(1);
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/cli/extract-manifest.ts
|
|
130
|
+
runExtract(process.argv[2] ?? process.cwd()).catch((err) => {
|
|
131
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
132
|
+
process.exit(1);
|
|
219
133
|
});
|
|
134
|
+
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { };
|