@lovable.dev/mcp-js 3.0.5 → 3.1.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/README.md +61 -1
- package/dist/cli/check-server.cjs +61 -0
- package/dist/cli/check-server.d.cts +1 -0
- package/dist/cli/check-server.d.ts +1 -0
- package/dist/cli/check-server.js +62 -0
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +1 -1
- package/dist/{cors-BGAtyAr_.js → cors-Df2tqbzV.js} +1 -1
- package/dist/{cors-COakIjqg.cjs → cors-YjwGFsid.cjs} +1 -1
- package/dist/diagnostic-ClI2_5MW.js +11 -0
- package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
- package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
- package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
- package/dist/{io-NrWvjpmZ.js → io-BoS6dhC0.js} +13 -2
- package/dist/{io-dULHdKny.cjs → io-D_DKGquD.cjs} +16 -5
- package/dist/{mcp-ChLv-MV0.js → mcp-Bm89K_uU.js} +3 -69
- package/dist/{mcp-DTAMXcRF.cjs → mcp-aNWgpVIF.cjs} +5 -71
- package/dist/{package-D8nhrfTR.js → package-C6IcwY5Z.js} +1 -1
- package/dist/{package-KAnnqE79.cjs → package-Cl7NhnV4.cjs} +1 -1
- package/dist/protocols/mcp/index.cjs +1 -1
- package/dist/protocols/mcp/index.js +1 -1
- package/dist/protocols/oauth-metadata.cjs +1 -1
- package/dist/protocols/oauth-metadata.js +1 -1
- package/dist/stacks/supabase/index.cjs +2 -2
- package/dist/stacks/supabase/index.js +2 -2
- package/dist/stacks/supabase/vite.cjs +7 -8
- package/dist/stacks/supabase/vite.js +2 -3
- package/dist/stacks/tanstack/index.cjs +2 -2
- package/dist/stacks/tanstack/index.js +2 -2
- package/dist/stacks/tanstack/vite.cjs +7 -8
- package/dist/stacks/tanstack/vite.js +1 -2
- package/dist/{supabase-config-CakTU8YF.js → supabase-config-DITfH_bn.js} +6 -2
- package/dist/{supabase-config-Dz7dnUv0.cjs → supabase-config-Dz13d9ze.cjs} +12 -2
- package/dist/testing/index.cjs +46 -0
- package/dist/testing/index.d.cts +10 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +44 -0
- package/dist/testing/server.cjs +197 -0
- package/dist/testing/server.d.cts +31 -0
- package/dist/testing/server.d.ts +31 -0
- package/dist/testing/server.js +195 -0
- package/dist/tool-result-DcNioyiI.js +70 -0
- package/dist/tool-result-rU-PpNNi.cjs +87 -0
- package/package.json +26 -2
- package/dist/fs-errors-CWNzOV75.cjs +0 -11
- package/dist/fs-errors-PA2t1TIp.js +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_logger = require("../logger-C-Hdu57K.cjs");
|
|
3
|
-
const require_cors = require("../cors-
|
|
3
|
+
const require_cors = require("../cors-YjwGFsid.cjs");
|
|
4
4
|
//#region src/protocols/oauth-metadata.ts
|
|
5
5
|
function notFound() {
|
|
6
6
|
return new Response(JSON.stringify({ error: "not found" }), {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as log, r as describeError } from "../logger-CpLgYbCG.js";
|
|
2
|
-
import { a as oauthConfigurationErrorResponse, f as JSON_HEADERS, i as normalizeHttpMethod, l as emitBeforeResponse, m as methodNotAllowed, p as finalizeWireResponse, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors, u as createNoopRecorder } from "../cors-
|
|
2
|
+
import { a as oauthConfigurationErrorResponse, f as JSON_HEADERS, i as normalizeHttpMethod, l as emitBeforeResponse, m as methodNotAllowed, p as finalizeWireResponse, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors, u as createNoopRecorder } from "../cors-Df2tqbzV.js";
|
|
3
3
|
//#region src/protocols/oauth-metadata.ts
|
|
4
4
|
function notFound() {
|
|
5
5
|
return new Response(JSON.stringify({ error: "not found" }), {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_logger = require("../../logger-C-Hdu57K.cjs");
|
|
3
|
-
const require_cors = require("../../cors-
|
|
3
|
+
const require_cors = require("../../cors-YjwGFsid.cjs");
|
|
4
4
|
const require_metadata_path = require("../../metadata-path-zd7NSNoa.cjs");
|
|
5
|
-
const require_mcp = require("../../mcp-
|
|
5
|
+
const require_mcp = require("../../mcp-aNWgpVIF.cjs");
|
|
6
6
|
const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
|
|
7
7
|
const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
|
|
8
8
|
const require_paths = require("../../paths-OP318a6c.cjs");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as trimTrailingSlash } from "../../logger-CpLgYbCG.js";
|
|
2
|
-
import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-
|
|
2
|
+
import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-Df2tqbzV.js";
|
|
3
3
|
import { t as OAUTH_PROTECTED_RESOURCE_METADATA_PATH } from "../../metadata-path-CAkNcfyY.js";
|
|
4
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
4
|
+
import { t as createMcpProtocolHandler } from "../../mcp-Bm89K_uU.js";
|
|
5
5
|
import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
|
|
6
6
|
import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
|
|
7
7
|
import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
|
|
@@ -2,9 +2,8 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_package = require("../../package-
|
|
6
|
-
const
|
|
7
|
-
const require_supabase_config = require("../../supabase-config-Dz7dnUv0.cjs");
|
|
5
|
+
const require_package = require("../../package-Cl7NhnV4.cjs");
|
|
6
|
+
const require_supabase_config = require("../../supabase-config-Dz13d9ze.cjs");
|
|
8
7
|
const require_paths = require("../../paths-OP318a6c.cjs");
|
|
9
8
|
let node_fs = require("node:fs");
|
|
10
9
|
let node_path = require("node:path");
|
|
@@ -17,7 +16,7 @@ function fileExists(path) {
|
|
|
17
16
|
(0, node_fs.lstatSync)(path);
|
|
18
17
|
return true;
|
|
19
18
|
} catch (err) {
|
|
20
|
-
if (
|
|
19
|
+
if (require_supabase_config.isFileMissing(err)) return false;
|
|
21
20
|
throw err;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -37,7 +36,7 @@ function writeIfChanged(file, content, ownershipCheck) {
|
|
|
37
36
|
try {
|
|
38
37
|
existing = (0, node_fs.readFileSync)(file, "utf8");
|
|
39
38
|
} catch (err) {
|
|
40
|
-
if (!
|
|
39
|
+
if (!require_supabase_config.isFileMissing(err)) throw err;
|
|
41
40
|
}
|
|
42
41
|
if (existing !== void 0) {
|
|
43
42
|
if (!ownershipCheck(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored file at ${file}. Delete it or move it first.`);
|
|
@@ -227,7 +226,7 @@ function cleanupOrphans(functionDir, expected, removed) {
|
|
|
227
226
|
try {
|
|
228
227
|
entries = (0, node_fs.readdirSync)(functionDir);
|
|
229
228
|
} catch (err) {
|
|
230
|
-
if (
|
|
229
|
+
if (require_supabase_config.isFileMissing(err)) return;
|
|
231
230
|
throw err;
|
|
232
231
|
}
|
|
233
232
|
for (const entry of entries) {
|
|
@@ -237,14 +236,14 @@ function cleanupOrphans(functionDir, expected, removed) {
|
|
|
237
236
|
try {
|
|
238
237
|
content = (0, node_fs.readFileSync)(full, "utf8");
|
|
239
238
|
} catch (err) {
|
|
240
|
-
if (
|
|
239
|
+
if (require_supabase_config.isFileMissing(err) || err.code === "EISDIR") continue;
|
|
241
240
|
throw err;
|
|
242
241
|
}
|
|
243
242
|
if (hasGeneratedBanner(content) || hasGeneratedJsonMarker(content)) try {
|
|
244
243
|
(0, node_fs.unlinkSync)(full);
|
|
245
244
|
removed.push(full);
|
|
246
245
|
} catch (err) {
|
|
247
|
-
if (!
|
|
246
|
+
if (!require_supabase_config.isFileMissing(err)) throw err;
|
|
248
247
|
}
|
|
249
248
|
}
|
|
250
249
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as version } from "../../package-
|
|
2
|
-
import {
|
|
3
|
-
import { t as readSupabaseProjectRef } from "../../supabase-config-CakTU8YF.js";
|
|
1
|
+
import { t as version } from "../../package-C6IcwY5Z.js";
|
|
2
|
+
import { n as isFileMissing, t as readSupabaseProjectRef } from "../../supabase-config-DITfH_bn.js";
|
|
4
3
|
import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
|
|
5
4
|
import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
5
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_cors = require("../../cors-
|
|
3
|
-
const require_mcp = require("../../mcp-
|
|
2
|
+
const require_cors = require("../../cors-YjwGFsid.cjs");
|
|
3
|
+
const require_mcp = require("../../mcp-aNWgpVIF.cjs");
|
|
4
4
|
const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
|
|
5
5
|
const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
|
|
6
6
|
//#region src/stacks/tanstack/handlers.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createRecorderForRuntime } from "../../cors-
|
|
2
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
1
|
+
import { c as createRecorderForRuntime } from "../../cors-Df2tqbzV.js";
|
|
2
|
+
import { t as createMcpProtocolHandler } from "../../mcp-Bm89K_uU.js";
|
|
3
3
|
import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
|
|
4
4
|
import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
|
|
5
5
|
//#region src/stacks/tanstack/handlers.ts
|
|
@@ -3,8 +3,7 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
require("../../metadata-path-zd7NSNoa.cjs");
|
|
6
|
-
const
|
|
7
|
-
const require_supabase_config = require("../../supabase-config-Dz7dnUv0.cjs");
|
|
6
|
+
const require_supabase_config = require("../../supabase-config-Dz13d9ze.cjs");
|
|
8
7
|
let node_fs = require("node:fs");
|
|
9
8
|
let node_path = require("node:path");
|
|
10
9
|
let vite = require("vite");
|
|
@@ -108,7 +107,7 @@ function writeIfChanged(file, content) {
|
|
|
108
107
|
try {
|
|
109
108
|
existing = (0, node_fs.readFileSync)(file, "utf8");
|
|
110
109
|
} catch (err) {
|
|
111
|
-
if (!
|
|
110
|
+
if (!require_supabase_config.isFileMissing(err)) throw err;
|
|
112
111
|
}
|
|
113
112
|
if (existing !== void 0) {
|
|
114
113
|
if (!hasGeneratedBanner(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored route at ${file}. Delete it or move it first.`);
|
|
@@ -122,7 +121,7 @@ function fileStartsWithBanner(file) {
|
|
|
122
121
|
try {
|
|
123
122
|
return hasGeneratedBanner((0, node_fs.readFileSync)(file, "utf8"));
|
|
124
123
|
} catch (err) {
|
|
125
|
-
if (
|
|
124
|
+
if (require_supabase_config.isFileMissing(err)) return false;
|
|
126
125
|
throw err;
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -133,7 +132,7 @@ function findAdoptedFiles(routesDir) {
|
|
|
133
132
|
try {
|
|
134
133
|
entries = (0, node_fs.readdirSync)(dir);
|
|
135
134
|
} catch (err) {
|
|
136
|
-
if (
|
|
135
|
+
if (require_supabase_config.isFileMissing(err)) return;
|
|
137
136
|
throw err;
|
|
138
137
|
}
|
|
139
138
|
for (const entry of entries) {
|
|
@@ -142,7 +141,7 @@ function findAdoptedFiles(routesDir) {
|
|
|
142
141
|
try {
|
|
143
142
|
stat = (0, node_fs.lstatSync)(full);
|
|
144
143
|
} catch (err) {
|
|
145
|
-
if (
|
|
144
|
+
if (require_supabase_config.isFileMissing(err)) continue;
|
|
146
145
|
throw err;
|
|
147
146
|
}
|
|
148
147
|
if (stat.isDirectory()) visit(full);
|
|
@@ -188,7 +187,7 @@ function mcpPlugin(options = {}) {
|
|
|
188
187
|
try {
|
|
189
188
|
(0, node_fs.lstatSync)(mcpEntry);
|
|
190
189
|
} catch (err) {
|
|
191
|
-
if (!
|
|
190
|
+
if (!require_supabase_config.isFileMissing(err)) throw err;
|
|
192
191
|
mcpEntryExists = false;
|
|
193
192
|
}
|
|
194
193
|
const expected = /* @__PURE__ */ new Set();
|
|
@@ -212,7 +211,7 @@ function mcpPlugin(options = {}) {
|
|
|
212
211
|
for (const file of findAdoptedFiles(routesDir)) if (!expected.has(file)) try {
|
|
213
212
|
(0, node_fs.unlinkSync)(file);
|
|
214
213
|
} catch (err) {
|
|
215
|
-
if (!
|
|
214
|
+
if (!require_supabase_config.isFileMissing(err)) throw err;
|
|
216
215
|
}
|
|
217
216
|
};
|
|
218
217
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "../../metadata-path-CAkNcfyY.js";
|
|
2
|
-
import {
|
|
3
|
-
import { t as readSupabaseProjectRef } from "../../supabase-config-CakTU8YF.js";
|
|
2
|
+
import { n as isFileMissing, t as readSupabaseProjectRef } from "../../supabase-config-DITfH_bn.js";
|
|
4
3
|
import { lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
4
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
6
5
|
import { loadEnv } from "vite";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { t as isFileMissing } from "./fs-errors-PA2t1TIp.js";
|
|
2
1
|
import { readFileSync } from "node:fs";
|
|
3
2
|
import { join } from "node:path";
|
|
3
|
+
//#region src/core/fs-errors.ts
|
|
4
|
+
function isFileMissing(err) {
|
|
5
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
4
8
|
//#region src/core/supabase-config.ts
|
|
5
9
|
const SUPABASE_CONFIG_RELATIVE_PATH = "supabase/config.toml";
|
|
6
10
|
function readSupabaseProjectRef(projectRoot) {
|
|
@@ -23,4 +27,4 @@ function readSupabaseProjectRef(projectRoot) {
|
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
//#endregion
|
|
26
|
-
export { readSupabaseProjectRef as t };
|
|
30
|
+
export { isFileMissing as n, readSupabaseProjectRef as t };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
const require_fs_errors = require("./fs-errors-CWNzOV75.cjs");
|
|
2
1
|
let node_fs = require("node:fs");
|
|
3
2
|
let node_path = require("node:path");
|
|
3
|
+
//#region src/core/fs-errors.ts
|
|
4
|
+
function isFileMissing(err) {
|
|
5
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
4
8
|
//#region src/core/supabase-config.ts
|
|
5
9
|
const SUPABASE_CONFIG_RELATIVE_PATH = "supabase/config.toml";
|
|
6
10
|
function readSupabaseProjectRef(projectRoot) {
|
|
@@ -8,7 +12,7 @@ function readSupabaseProjectRef(projectRoot) {
|
|
|
8
12
|
try {
|
|
9
13
|
content = (0, node_fs.readFileSync)((0, node_path.join)(projectRoot, SUPABASE_CONFIG_RELATIVE_PATH), "utf8");
|
|
10
14
|
} catch (err) {
|
|
11
|
-
if (
|
|
15
|
+
if (isFileMissing(err)) return void 0;
|
|
12
16
|
throw err;
|
|
13
17
|
}
|
|
14
18
|
for (const raw of content.split(/\r?\n/)) {
|
|
@@ -23,6 +27,12 @@ function readSupabaseProjectRef(projectRoot) {
|
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
//#endregion
|
|
30
|
+
Object.defineProperty(exports, "isFileMissing", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function() {
|
|
33
|
+
return isFileMissing;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
26
36
|
Object.defineProperty(exports, "readSupabaseProjectRef", {
|
|
27
37
|
enumerable: true,
|
|
28
38
|
get: function() {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_schema = require("../schema-DNMsvJwE.cjs");
|
|
3
|
+
const require_tool_result = require("../tool-result-rU-PpNNi.cjs");
|
|
4
|
+
const require_diagnostic = require("../diagnostic-ol9IE9Dl.cjs");
|
|
5
|
+
let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
6
|
+
let _modelcontextprotocol_core = require("@modelcontextprotocol/core");
|
|
7
|
+
//#region src/testing/result.ts
|
|
8
|
+
async function assertToolResult(result, expected = {}) {
|
|
9
|
+
const fail = (code, message, basis = "package-guarantee") => {
|
|
10
|
+
throw new require_diagnostic.McpCheckError({
|
|
11
|
+
code,
|
|
12
|
+
message,
|
|
13
|
+
basis
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
let json = false;
|
|
17
|
+
try {
|
|
18
|
+
json = require_tool_result.isJsonValue(result);
|
|
19
|
+
} catch {}
|
|
20
|
+
if (!json) fail("result.json", "Return JSON data without cycles, class instances or non-finite numbers.");
|
|
21
|
+
let parsed;
|
|
22
|
+
let value;
|
|
23
|
+
try {
|
|
24
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) throw new Error();
|
|
25
|
+
value = { ...result };
|
|
26
|
+
if (value.content !== void 0 && !Array.isArray(value.content)) throw new Error();
|
|
27
|
+
parsed = _modelcontextprotocol_core.CallToolResultSchema.safeParse({
|
|
28
|
+
...value,
|
|
29
|
+
content: require_tool_result.normalizeToolContent(value.content)
|
|
30
|
+
});
|
|
31
|
+
} catch {
|
|
32
|
+
return fail("result.shape", "Return a plain MCP result with valid content blocks and object _meta.");
|
|
33
|
+
}
|
|
34
|
+
if (!parsed.success) fail("result.shape", "Return a plain MCP result with valid content blocks and object _meta.");
|
|
35
|
+
if (value.isError === true !== (expected.isError === true)) fail("result.expected-error", expected.isError ? "Expected an error result." : "Expected a successful result.", "app-expectation");
|
|
36
|
+
if (expected.outputSchema && !value.isError) {
|
|
37
|
+
let valid = false;
|
|
38
|
+
try {
|
|
39
|
+
valid = value.structuredContent !== void 0 && (await (0, _modelcontextprotocol_sdk_server_zod_compat_js.safeParseAsync)(require_schema.schemaFromDefinition(expected.outputSchema, false), value.structuredContent)).success;
|
|
40
|
+
} catch {}
|
|
41
|
+
if (!valid) fail("result.output-schema", "Successful structuredContent must be present and match the declared outputSchema.");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.McpCheckError = require_diagnostic.McpCheckError;
|
|
46
|
+
exports.assertToolResult = assertToolResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { w as ZodOutputSchema } from "../types-BX8RawmT.cjs";
|
|
2
|
+
import { n as McpCheckError, t as Diagnostic } from "../diagnostic-DRKjgCsW.cjs";
|
|
3
|
+
//#region src/testing/result.d.ts
|
|
4
|
+
interface ToolResultExpectation {
|
|
5
|
+
outputSchema?: ZodOutputSchema;
|
|
6
|
+
isError?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function assertToolResult(result: unknown, expected?: ToolResultExpectation): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type Diagnostic, McpCheckError, type ToolResultExpectation, assertToolResult };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { w as ZodOutputSchema } from "../types-BX8RawmT.js";
|
|
2
|
+
import { n as McpCheckError, t as Diagnostic } from "../diagnostic-DRKjgCsW.js";
|
|
3
|
+
//#region src/testing/result.d.ts
|
|
4
|
+
interface ToolResultExpectation {
|
|
5
|
+
outputSchema?: ZodOutputSchema;
|
|
6
|
+
isError?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function assertToolResult(result: unknown, expected?: ToolResultExpectation): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type Diagnostic, McpCheckError, type ToolResultExpectation, assertToolResult };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { n as schemaFromDefinition } from "../schema-JK_1KkOa.js";
|
|
2
|
+
import { n as isJsonValue, r as normalizeToolContent } from "../tool-result-DcNioyiI.js";
|
|
3
|
+
import { t as McpCheckError } from "../diagnostic-ClI2_5MW.js";
|
|
4
|
+
import { safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
5
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/core";
|
|
6
|
+
//#region src/testing/result.ts
|
|
7
|
+
async function assertToolResult(result, expected = {}) {
|
|
8
|
+
const fail = (code, message, basis = "package-guarantee") => {
|
|
9
|
+
throw new McpCheckError({
|
|
10
|
+
code,
|
|
11
|
+
message,
|
|
12
|
+
basis
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
let json = false;
|
|
16
|
+
try {
|
|
17
|
+
json = isJsonValue(result);
|
|
18
|
+
} catch {}
|
|
19
|
+
if (!json) fail("result.json", "Return JSON data without cycles, class instances or non-finite numbers.");
|
|
20
|
+
let parsed;
|
|
21
|
+
let value;
|
|
22
|
+
try {
|
|
23
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) throw new Error();
|
|
24
|
+
value = { ...result };
|
|
25
|
+
if (value.content !== void 0 && !Array.isArray(value.content)) throw new Error();
|
|
26
|
+
parsed = CallToolResultSchema.safeParse({
|
|
27
|
+
...value,
|
|
28
|
+
content: normalizeToolContent(value.content)
|
|
29
|
+
});
|
|
30
|
+
} catch {
|
|
31
|
+
return fail("result.shape", "Return a plain MCP result with valid content blocks and object _meta.");
|
|
32
|
+
}
|
|
33
|
+
if (!parsed.success) fail("result.shape", "Return a plain MCP result with valid content blocks and object _meta.");
|
|
34
|
+
if (value.isError === true !== (expected.isError === true)) fail("result.expected-error", expected.isError ? "Expected an error result." : "Expected a successful result.", "app-expectation");
|
|
35
|
+
if (expected.outputSchema && !value.isError) {
|
|
36
|
+
let valid = false;
|
|
37
|
+
try {
|
|
38
|
+
valid = value.structuredContent !== void 0 && (await safeParseAsync(schemaFromDefinition(expected.outputSchema, false), value.structuredContent)).success;
|
|
39
|
+
} catch {}
|
|
40
|
+
if (!valid) fail("result.output-schema", "Successful structuredContent must be present and match the declared outputSchema.");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { McpCheckError, assertToolResult };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostic = require("../diagnostic-ol9IE9Dl.cjs");
|
|
3
|
+
let _modelcontextprotocol_client = require("@modelcontextprotocol/client");
|
|
4
|
+
let _modelcontextprotocol_client_validators_ajv = require("@modelcontextprotocol/client/validators/ajv");
|
|
5
|
+
let node_net = require("node:net");
|
|
6
|
+
//#region src/testing/server.ts
|
|
7
|
+
async function withMcpClient(options, run) {
|
|
8
|
+
let endpoint;
|
|
9
|
+
let headers;
|
|
10
|
+
const version = options.protocolVersion ?? "2026-07-28";
|
|
11
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
12
|
+
try {
|
|
13
|
+
endpoint = new URL(options.endpoint);
|
|
14
|
+
headers = new Headers(options.headers);
|
|
15
|
+
const host = endpoint.hostname;
|
|
16
|
+
const loopback = host === "localhost" || host === "[::1]" || (0, node_net.isIP)(host) === 4 && host.startsWith("127.");
|
|
17
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2147483647 || !["2025-11-25", "2026-07-28"].includes(version) || !["http:", "https:"].includes(endpoint.protocol) || endpoint.username || endpoint.password || endpoint.hash || endpoint.protocol === "http:" && !loopback && !options.handler && [...headers].length > 0) throw new Error();
|
|
18
|
+
} catch {
|
|
19
|
+
throw new require_diagnostic.McpCheckError({
|
|
20
|
+
code: "connection.options",
|
|
21
|
+
basis: "package-guarantee",
|
|
22
|
+
message: "Use a valid HTTP(S) endpoint without URL credentials or fragment, a supported protocol and a positive timeout. Remote HTTP with supplied headers is refused."
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const client = new _modelcontextprotocol_client.Client({
|
|
26
|
+
name: "mcp-js-tests",
|
|
27
|
+
version: "1"
|
|
28
|
+
}, {
|
|
29
|
+
supportedProtocolVersions: [version],
|
|
30
|
+
versionNegotiation: { mode: version === "2025-11-25" ? "legacy" : { pin: version } },
|
|
31
|
+
capabilities: options.capabilities ?? {},
|
|
32
|
+
inputRequired: { autoFulfill: false },
|
|
33
|
+
listMaxPages: 16
|
|
34
|
+
});
|
|
35
|
+
const transport = new _modelcontextprotocol_client.StreamableHTTPClientTransport(endpoint, {
|
|
36
|
+
requestInit: { headers },
|
|
37
|
+
fetch: async (url, init) => {
|
|
38
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
39
|
+
const request = new Request(url, {
|
|
40
|
+
...init,
|
|
41
|
+
redirect: "manual",
|
|
42
|
+
signal: init?.signal ? AbortSignal.any([timeout, init.signal]) : timeout
|
|
43
|
+
});
|
|
44
|
+
if (request.url !== endpoint.href) throw new Error("Test transport refused a different endpoint.");
|
|
45
|
+
let onAbort = () => {};
|
|
46
|
+
let response;
|
|
47
|
+
try {
|
|
48
|
+
response = await Promise.race([options.handler ? options.handler(request) : fetch(request), new Promise((_resolve, reject) => {
|
|
49
|
+
onAbort = () => reject(request.signal.reason);
|
|
50
|
+
if (request.signal.aborted) onAbort();
|
|
51
|
+
else request.signal.addEventListener("abort", onAbort, { once: true });
|
|
52
|
+
})]);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (timeout.aborted && error === timeout.reason) throw new _modelcontextprotocol_client.SdkError(_modelcontextprotocol_client.SdkErrorCode.RequestTimeout, "Request timed out");
|
|
55
|
+
throw error;
|
|
56
|
+
} finally {
|
|
57
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
58
|
+
}
|
|
59
|
+
if (response.status >= 300 && response.status < 400) {
|
|
60
|
+
await response.body?.cancel();
|
|
61
|
+
throw new Error("Test transport refused a redirect. Configure the final endpoint explicitly.");
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
try {
|
|
67
|
+
await client.connect(transport, { timeout: timeoutMs });
|
|
68
|
+
return await run(client);
|
|
69
|
+
} finally {
|
|
70
|
+
await client.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function checkMcpServer(options) {
|
|
74
|
+
const checks = [];
|
|
75
|
+
const calls = options.calls ?? [];
|
|
76
|
+
const timeout = options.timeoutMs ?? 1e4;
|
|
77
|
+
let nextCall = 0;
|
|
78
|
+
let stage = "server.connect";
|
|
79
|
+
let location;
|
|
80
|
+
const record = (code, message, status = "passed", basis = "protocol-requirement") => {
|
|
81
|
+
checks.push({
|
|
82
|
+
code,
|
|
83
|
+
message,
|
|
84
|
+
status,
|
|
85
|
+
basis,
|
|
86
|
+
location
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
await withMcpClient(options, async (client) => {
|
|
91
|
+
record(stage, "The official client connected with the configured protocol and caller headers.");
|
|
92
|
+
stage = "server.tools";
|
|
93
|
+
const { tools } = client.getServerCapabilities()?.tools ? await client.listTools(void 0, {
|
|
94
|
+
cacheMode: "bypass",
|
|
95
|
+
timeout
|
|
96
|
+
}) : { tools: [] };
|
|
97
|
+
record(stage, "The official client decoded the tool catalog; the tools capability is optional.");
|
|
98
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const [index, tool] of tools.entries()) {
|
|
100
|
+
location = `tools[${index}]`;
|
|
101
|
+
stage = "server.schemas";
|
|
102
|
+
for (const schema of [tool.inputSchema, tool.outputSchema]) {
|
|
103
|
+
if (!schema) continue;
|
|
104
|
+
if (typeof schema.$schema === "string" && !/^https?:\/\/json-schema\.org\/(?:draft\/(?:2020-12|2019-09)|draft-0[67])\/schema#?$/.test(schema.$schema)) {
|
|
105
|
+
unsupported.add(tool.name);
|
|
106
|
+
record(stage, "This helper cannot validate the declared schema dialect. Selected calls to this tool and subsequent calls will not run.", "not-tested", "package-guarantee");
|
|
107
|
+
} else new _modelcontextprotocol_client_validators_ajv.AjvJsonSchemaValidator().getValidator(schema);
|
|
108
|
+
}
|
|
109
|
+
if (!unsupported.has(tool.name)) record(stage, "Advertised schemas compile with the SDK validator.");
|
|
110
|
+
}
|
|
111
|
+
for (; nextCall < calls.length; nextCall++) {
|
|
112
|
+
const call = calls[nextCall];
|
|
113
|
+
location = `calls[${nextCall}]`;
|
|
114
|
+
stage = "tool.call";
|
|
115
|
+
if (unsupported.has(call.name)) break;
|
|
116
|
+
const tool = tools.find((entry) => entry.name === call.name);
|
|
117
|
+
if (!tool) throw new require_diagnostic.McpCheckError({
|
|
118
|
+
code: "tool.not-found",
|
|
119
|
+
basis: "app-expectation",
|
|
120
|
+
message: "Selected tool was not advertised to this caller. No call was made."
|
|
121
|
+
});
|
|
122
|
+
const { outputSchema, ...definition } = tool;
|
|
123
|
+
const result = await client.callTool({
|
|
124
|
+
name: call.name,
|
|
125
|
+
arguments: call.arguments
|
|
126
|
+
}, {
|
|
127
|
+
toolDefinition: definition,
|
|
128
|
+
timeout
|
|
129
|
+
});
|
|
130
|
+
if (result.isError === true !== (call.isError === true)) throw new require_diagnostic.McpCheckError({
|
|
131
|
+
code: "result.expected-error",
|
|
132
|
+
basis: "app-expectation",
|
|
133
|
+
message: call.isError ? "Expected an error result." : "Expected a successful result."
|
|
134
|
+
});
|
|
135
|
+
if (!result.isError && outputSchema && (result.structuredContent === void 0 || !new _modelcontextprotocol_client_validators_ajv.AjvJsonSchemaValidator().getValidator(outputSchema)(result.structuredContent).valid)) throw new require_diagnostic.McpCheckError({
|
|
136
|
+
code: "result.output-schema",
|
|
137
|
+
basis: "protocol-requirement",
|
|
138
|
+
message: "Successful structuredContent must match the advertised outputSchema."
|
|
139
|
+
});
|
|
140
|
+
record(stage, "The selected call returned the expected success/error result and matched its advertised output schema, if any.");
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const status = _modelcontextprotocol_client.SdkError.isInstance(error) && typeof error.data === "object" && error.data !== null && "status" in error.data ? error.data.status : void 0;
|
|
145
|
+
const sdkCode = status === 401 ? _modelcontextprotocol_client.SdkErrorCode.ClientHttpAuthentication : status === 403 ? _modelcontextprotocol_client.SdkErrorCode.ClientHttpForbidden : _modelcontextprotocol_client.SdkError.isInstance(error) ? error.code : void 0;
|
|
146
|
+
const incomplete = _modelcontextprotocol_client.SdkError.isInstance(error) && sdkCode === _modelcontextprotocol_client.SdkErrorCode.UnsupportedResultType && error.data !== null && typeof error.data === "object" && "resultType" in error.data && error.data.resultType === "input_required";
|
|
147
|
+
const typed = {
|
|
148
|
+
[_modelcontextprotocol_client.SdkErrorCode.ClientHttpAuthentication]: {
|
|
149
|
+
code: "server.unauthorized",
|
|
150
|
+
message: "The endpoint rejected authentication. Check the supplied credentials and audience."
|
|
151
|
+
},
|
|
152
|
+
[_modelcontextprotocol_client.SdkErrorCode.ClientHttpForbidden]: {
|
|
153
|
+
code: "server.forbidden",
|
|
154
|
+
message: "The endpoint refused access for this caller."
|
|
155
|
+
},
|
|
156
|
+
[_modelcontextprotocol_client.SdkErrorCode.RequestTimeout]: {
|
|
157
|
+
code: "server.timeout",
|
|
158
|
+
message: "The request timed out. Check endpoint availability and the configured timeout."
|
|
159
|
+
},
|
|
160
|
+
[_modelcontextprotocol_client.SdkErrorCode.InvalidResult]: {
|
|
161
|
+
code: "result.shape",
|
|
162
|
+
message: "The official client rejected the response shape."
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const known = sdkCode === void 0 ? void 0 : typed[sdkCode];
|
|
166
|
+
const diagnostic = incomplete ? {
|
|
167
|
+
code: "tool.input-required",
|
|
168
|
+
basis: "package-guarantee",
|
|
169
|
+
message: "The selected call requires additional input. No input was supplied and later calls will not run."
|
|
170
|
+
} : error instanceof require_diagnostic.McpCheckError ? error.diagnostic : {
|
|
171
|
+
code: stage,
|
|
172
|
+
basis: "package-guarantee",
|
|
173
|
+
message: stage === "server.connect" ? "Connection failed. Check endpoint, credentials and protocol support; response details are omitted." : stage === "server.schemas" ? "Schema compilation failed. Check dialect, references and syntax; remote references are not fetched." : "The check could not complete. Inspect this contract in an app test; response details are omitted.",
|
|
174
|
+
...known
|
|
175
|
+
};
|
|
176
|
+
checks.push({
|
|
177
|
+
...diagnostic,
|
|
178
|
+
location,
|
|
179
|
+
status: incomplete ? "not-tested" : "failed"
|
|
180
|
+
});
|
|
181
|
+
if (location === `calls[${nextCall}]`) nextCall++;
|
|
182
|
+
}
|
|
183
|
+
for (; nextCall < calls.length; nextCall++) {
|
|
184
|
+
location = `calls[${nextCall}]`;
|
|
185
|
+
record("tool.call", "Call not run because a prerequisite check or selected call did not complete.", "not-tested", "app-expectation");
|
|
186
|
+
}
|
|
187
|
+
location = void 0;
|
|
188
|
+
record("app.behavior", "Authentication enforcement, business behavior, browser interactions and deployed OAuth require app-owned tests. This is not full MCP conformance.", "not-tested", "app-expectation");
|
|
189
|
+
if (calls.length === 0) record("tool.calls", "No calls selected; input enforcement and result mapping were not exercised.", "not-tested", "app-expectation");
|
|
190
|
+
return {
|
|
191
|
+
checks,
|
|
192
|
+
passed: checks.every((check) => check.status !== "failed")
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
exports.checkMcpServer = checkMcpServer;
|
|
197
|
+
exports.withMcpClient = withMcpClient;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as Diagnostic } from "../diagnostic-DRKjgCsW.cjs";
|
|
2
|
+
import { Client, ClientCapabilities } from "@modelcontextprotocol/client";
|
|
3
|
+
//#region src/testing/server.d.ts
|
|
4
|
+
type ProtocolVersion = "2025-11-25" | "2026-07-28";
|
|
5
|
+
interface McpTestConnection {
|
|
6
|
+
endpoint: string | URL;
|
|
7
|
+
protocolVersion?: ProtocolVersion;
|
|
8
|
+
headers?: ConstructorParameters<typeof Headers>[0];
|
|
9
|
+
handler?: (request: Request) => Promise<Response>;
|
|
10
|
+
capabilities?: ClientCapabilities;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
declare function withMcpClient<T>(options: McpTestConnection, run: (client: Client) => Promise<T>): Promise<T>;
|
|
14
|
+
interface ServerCheck extends Diagnostic {
|
|
15
|
+
status: "passed" | "failed" | "not-tested";
|
|
16
|
+
location?: string;
|
|
17
|
+
}
|
|
18
|
+
interface ServerCheckReport {
|
|
19
|
+
checks: ServerCheck[];
|
|
20
|
+
passed: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ServerCheckOptions extends McpTestConnection {
|
|
23
|
+
calls?: {
|
|
24
|
+
name: string;
|
|
25
|
+
arguments?: Record<string, unknown>;
|
|
26
|
+
isError?: boolean;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
declare function checkMcpServer(options: ServerCheckOptions): Promise<ServerCheckReport>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, checkMcpServer, withMcpClient };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as Diagnostic } from "../diagnostic-DRKjgCsW.js";
|
|
2
|
+
import { Client, ClientCapabilities } from "@modelcontextprotocol/client";
|
|
3
|
+
//#region src/testing/server.d.ts
|
|
4
|
+
type ProtocolVersion = "2025-11-25" | "2026-07-28";
|
|
5
|
+
interface McpTestConnection {
|
|
6
|
+
endpoint: string | URL;
|
|
7
|
+
protocolVersion?: ProtocolVersion;
|
|
8
|
+
headers?: ConstructorParameters<typeof Headers>[0];
|
|
9
|
+
handler?: (request: Request) => Promise<Response>;
|
|
10
|
+
capabilities?: ClientCapabilities;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
declare function withMcpClient<T>(options: McpTestConnection, run: (client: Client) => Promise<T>): Promise<T>;
|
|
14
|
+
interface ServerCheck extends Diagnostic {
|
|
15
|
+
status: "passed" | "failed" | "not-tested";
|
|
16
|
+
location?: string;
|
|
17
|
+
}
|
|
18
|
+
interface ServerCheckReport {
|
|
19
|
+
checks: ServerCheck[];
|
|
20
|
+
passed: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ServerCheckOptions extends McpTestConnection {
|
|
23
|
+
calls?: {
|
|
24
|
+
name: string;
|
|
25
|
+
arguments?: Record<string, unknown>;
|
|
26
|
+
isError?: boolean;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
declare function checkMcpServer(options: ServerCheckOptions): Promise<ServerCheckReport>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, checkMcpServer, withMcpClient };
|