@lovable.dev/mcp-js 3.0.6 → 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.
Files changed (40) hide show
  1. package/README.md +61 -1
  2. package/dist/cli/check-server.cjs +61 -0
  3. package/dist/cli/check-server.d.cts +1 -0
  4. package/dist/cli/check-server.d.ts +1 -0
  5. package/dist/cli/check-server.js +62 -0
  6. package/dist/cli/extract-manifest.cjs +1 -1
  7. package/dist/cli/extract-manifest.js +1 -1
  8. package/dist/{cors-C3JU5DNM.js → cors-Df2tqbzV.js} +1 -1
  9. package/dist/{cors-dZ1AWhSq.cjs → cors-YjwGFsid.cjs} +1 -1
  10. package/dist/diagnostic-ClI2_5MW.js +11 -0
  11. package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
  12. package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
  13. package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
  14. package/dist/{io-x7rcGbQj.js → io-BoS6dhC0.js} +1 -1
  15. package/dist/{io-DV_Bkma8.cjs → io-D_DKGquD.cjs} +1 -1
  16. package/dist/{mcp-woEauhMi.js → mcp-Bm89K_uU.js} +3 -69
  17. package/dist/{mcp-WUiGYfjS.cjs → mcp-aNWgpVIF.cjs} +5 -71
  18. package/dist/{package-DIh9b_dF.js → package-C6IcwY5Z.js} +1 -1
  19. package/dist/{package-CoGnWS6Y.cjs → package-Cl7NhnV4.cjs} +1 -1
  20. package/dist/protocols/mcp/index.cjs +1 -1
  21. package/dist/protocols/mcp/index.js +1 -1
  22. package/dist/protocols/oauth-metadata.cjs +1 -1
  23. package/dist/protocols/oauth-metadata.js +1 -1
  24. package/dist/stacks/supabase/index.cjs +2 -2
  25. package/dist/stacks/supabase/index.js +2 -2
  26. package/dist/stacks/supabase/vite.cjs +1 -1
  27. package/dist/stacks/supabase/vite.js +1 -1
  28. package/dist/stacks/tanstack/index.cjs +2 -2
  29. package/dist/stacks/tanstack/index.js +2 -2
  30. package/dist/testing/index.cjs +46 -0
  31. package/dist/testing/index.d.cts +10 -0
  32. package/dist/testing/index.d.ts +10 -0
  33. package/dist/testing/index.js +44 -0
  34. package/dist/testing/server.cjs +197 -0
  35. package/dist/testing/server.d.cts +31 -0
  36. package/dist/testing/server.d.ts +31 -0
  37. package/dist/testing/server.js +195 -0
  38. package/dist/tool-result-DcNioyiI.js +70 -0
  39. package/dist/tool-result-rU-PpNNi.cjs +87 -0
  40. package/package.json +26 -2
@@ -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 };
@@ -0,0 +1,195 @@
1
+ import { t as McpCheckError } from "../diagnostic-ClI2_5MW.js";
2
+ import { Client, SdkError, SdkErrorCode, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
3
+ import { AjvJsonSchemaValidator } from "@modelcontextprotocol/client/validators/ajv";
4
+ import { isIP } from "node:net";
5
+ //#region src/testing/server.ts
6
+ async function withMcpClient(options, run) {
7
+ let endpoint;
8
+ let headers;
9
+ const version = options.protocolVersion ?? "2026-07-28";
10
+ const timeoutMs = options.timeoutMs ?? 1e4;
11
+ try {
12
+ endpoint = new URL(options.endpoint);
13
+ headers = new Headers(options.headers);
14
+ const host = endpoint.hostname;
15
+ const loopback = host === "localhost" || host === "[::1]" || isIP(host) === 4 && host.startsWith("127.");
16
+ 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();
17
+ } catch {
18
+ throw new McpCheckError({
19
+ code: "connection.options",
20
+ basis: "package-guarantee",
21
+ 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."
22
+ });
23
+ }
24
+ const client = new Client({
25
+ name: "mcp-js-tests",
26
+ version: "1"
27
+ }, {
28
+ supportedProtocolVersions: [version],
29
+ versionNegotiation: { mode: version === "2025-11-25" ? "legacy" : { pin: version } },
30
+ capabilities: options.capabilities ?? {},
31
+ inputRequired: { autoFulfill: false },
32
+ listMaxPages: 16
33
+ });
34
+ const transport = new StreamableHTTPClientTransport(endpoint, {
35
+ requestInit: { headers },
36
+ fetch: async (url, init) => {
37
+ const timeout = AbortSignal.timeout(timeoutMs);
38
+ const request = new Request(url, {
39
+ ...init,
40
+ redirect: "manual",
41
+ signal: init?.signal ? AbortSignal.any([timeout, init.signal]) : timeout
42
+ });
43
+ if (request.url !== endpoint.href) throw new Error("Test transport refused a different endpoint.");
44
+ let onAbort = () => {};
45
+ let response;
46
+ try {
47
+ response = await Promise.race([options.handler ? options.handler(request) : fetch(request), new Promise((_resolve, reject) => {
48
+ onAbort = () => reject(request.signal.reason);
49
+ if (request.signal.aborted) onAbort();
50
+ else request.signal.addEventListener("abort", onAbort, { once: true });
51
+ })]);
52
+ } catch (error) {
53
+ if (timeout.aborted && error === timeout.reason) throw new SdkError(SdkErrorCode.RequestTimeout, "Request timed out");
54
+ throw error;
55
+ } finally {
56
+ request.signal.removeEventListener("abort", onAbort);
57
+ }
58
+ if (response.status >= 300 && response.status < 400) {
59
+ await response.body?.cancel();
60
+ throw new Error("Test transport refused a redirect. Configure the final endpoint explicitly.");
61
+ }
62
+ return response;
63
+ }
64
+ });
65
+ try {
66
+ await client.connect(transport, { timeout: timeoutMs });
67
+ return await run(client);
68
+ } finally {
69
+ await client.close();
70
+ }
71
+ }
72
+ async function checkMcpServer(options) {
73
+ const checks = [];
74
+ const calls = options.calls ?? [];
75
+ const timeout = options.timeoutMs ?? 1e4;
76
+ let nextCall = 0;
77
+ let stage = "server.connect";
78
+ let location;
79
+ const record = (code, message, status = "passed", basis = "protocol-requirement") => {
80
+ checks.push({
81
+ code,
82
+ message,
83
+ status,
84
+ basis,
85
+ location
86
+ });
87
+ };
88
+ try {
89
+ await withMcpClient(options, async (client) => {
90
+ record(stage, "The official client connected with the configured protocol and caller headers.");
91
+ stage = "server.tools";
92
+ const { tools } = client.getServerCapabilities()?.tools ? await client.listTools(void 0, {
93
+ cacheMode: "bypass",
94
+ timeout
95
+ }) : { tools: [] };
96
+ record(stage, "The official client decoded the tool catalog; the tools capability is optional.");
97
+ const unsupported = /* @__PURE__ */ new Set();
98
+ for (const [index, tool] of tools.entries()) {
99
+ location = `tools[${index}]`;
100
+ stage = "server.schemas";
101
+ for (const schema of [tool.inputSchema, tool.outputSchema]) {
102
+ if (!schema) continue;
103
+ if (typeof schema.$schema === "string" && !/^https?:\/\/json-schema\.org\/(?:draft\/(?:2020-12|2019-09)|draft-0[67])\/schema#?$/.test(schema.$schema)) {
104
+ unsupported.add(tool.name);
105
+ 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");
106
+ } else new AjvJsonSchemaValidator().getValidator(schema);
107
+ }
108
+ if (!unsupported.has(tool.name)) record(stage, "Advertised schemas compile with the SDK validator.");
109
+ }
110
+ for (; nextCall < calls.length; nextCall++) {
111
+ const call = calls[nextCall];
112
+ location = `calls[${nextCall}]`;
113
+ stage = "tool.call";
114
+ if (unsupported.has(call.name)) break;
115
+ const tool = tools.find((entry) => entry.name === call.name);
116
+ if (!tool) throw new McpCheckError({
117
+ code: "tool.not-found",
118
+ basis: "app-expectation",
119
+ message: "Selected tool was not advertised to this caller. No call was made."
120
+ });
121
+ const { outputSchema, ...definition } = tool;
122
+ const result = await client.callTool({
123
+ name: call.name,
124
+ arguments: call.arguments
125
+ }, {
126
+ toolDefinition: definition,
127
+ timeout
128
+ });
129
+ if (result.isError === true !== (call.isError === true)) throw new McpCheckError({
130
+ code: "result.expected-error",
131
+ basis: "app-expectation",
132
+ message: call.isError ? "Expected an error result." : "Expected a successful result."
133
+ });
134
+ if (!result.isError && outputSchema && (result.structuredContent === void 0 || !new AjvJsonSchemaValidator().getValidator(outputSchema)(result.structuredContent).valid)) throw new McpCheckError({
135
+ code: "result.output-schema",
136
+ basis: "protocol-requirement",
137
+ message: "Successful structuredContent must match the advertised outputSchema."
138
+ });
139
+ record(stage, "The selected call returned the expected success/error result and matched its advertised output schema, if any.");
140
+ }
141
+ });
142
+ } catch (error) {
143
+ const status = SdkError.isInstance(error) && typeof error.data === "object" && error.data !== null && "status" in error.data ? error.data.status : void 0;
144
+ const sdkCode = status === 401 ? SdkErrorCode.ClientHttpAuthentication : status === 403 ? SdkErrorCode.ClientHttpForbidden : SdkError.isInstance(error) ? error.code : void 0;
145
+ const incomplete = SdkError.isInstance(error) && sdkCode === SdkErrorCode.UnsupportedResultType && error.data !== null && typeof error.data === "object" && "resultType" in error.data && error.data.resultType === "input_required";
146
+ const typed = {
147
+ [SdkErrorCode.ClientHttpAuthentication]: {
148
+ code: "server.unauthorized",
149
+ message: "The endpoint rejected authentication. Check the supplied credentials and audience."
150
+ },
151
+ [SdkErrorCode.ClientHttpForbidden]: {
152
+ code: "server.forbidden",
153
+ message: "The endpoint refused access for this caller."
154
+ },
155
+ [SdkErrorCode.RequestTimeout]: {
156
+ code: "server.timeout",
157
+ message: "The request timed out. Check endpoint availability and the configured timeout."
158
+ },
159
+ [SdkErrorCode.InvalidResult]: {
160
+ code: "result.shape",
161
+ message: "The official client rejected the response shape."
162
+ }
163
+ };
164
+ const known = sdkCode === void 0 ? void 0 : typed[sdkCode];
165
+ const diagnostic = incomplete ? {
166
+ code: "tool.input-required",
167
+ basis: "package-guarantee",
168
+ message: "The selected call requires additional input. No input was supplied and later calls will not run."
169
+ } : error instanceof McpCheckError ? error.diagnostic : {
170
+ code: stage,
171
+ basis: "package-guarantee",
172
+ 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.",
173
+ ...known
174
+ };
175
+ checks.push({
176
+ ...diagnostic,
177
+ location,
178
+ status: incomplete ? "not-tested" : "failed"
179
+ });
180
+ if (location === `calls[${nextCall}]`) nextCall++;
181
+ }
182
+ for (; nextCall < calls.length; nextCall++) {
183
+ location = `calls[${nextCall}]`;
184
+ record("tool.call", "Call not run because a prerequisite check or selected call did not complete.", "not-tested", "app-expectation");
185
+ }
186
+ location = void 0;
187
+ 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");
188
+ if (calls.length === 0) record("tool.calls", "No calls selected; input enforcement and result mapping were not exercised.", "not-tested", "app-expectation");
189
+ return {
190
+ checks,
191
+ passed: checks.every((check) => check.status !== "failed")
192
+ };
193
+ }
194
+ //#endregion
195
+ export { checkMcpServer, withMcpClient };
@@ -0,0 +1,70 @@
1
+ import { n as schemaFromDefinition } from "./schema-JK_1KkOa.js";
2
+ import { getParseErrorMessage, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
3
+ //#region src/core/tool-result.ts
4
+ function normalizeResourceLinkIcon(icon) {
5
+ if (typeof icon.sizes !== "string") return icon;
6
+ const { sizes, ...rest } = icon;
7
+ const normalized = sizes.trim();
8
+ return normalized === "" ? rest : {
9
+ ...rest,
10
+ sizes: normalized.split(/\s+/)
11
+ };
12
+ }
13
+ function normalizeToolContent(content) {
14
+ return (content ?? []).map((block) => {
15
+ if (block.type !== "resource_link" || block.icons === void 0) return block;
16
+ return {
17
+ ...block,
18
+ icons: block.icons.map(normalizeResourceLinkIcon)
19
+ };
20
+ });
21
+ }
22
+ function outputValidationError(text) {
23
+ return {
24
+ content: [{
25
+ type: "text",
26
+ text
27
+ }],
28
+ isError: true
29
+ };
30
+ }
31
+ function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
32
+ if (value === null || typeof value === "boolean" || typeof value === "string") return true;
33
+ if (typeof value === "number") return Number.isFinite(value);
34
+ if (typeof value !== "object" || ancestors.has(value)) return false;
35
+ const prototype = Object.getPrototypeOf(value);
36
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
37
+ ancestors.add(value);
38
+ const valid = (Array.isArray(value) ? value : Object.values(value).filter((entry) => entry !== void 0)).every((entry) => isJsonValue(entry, ancestors));
39
+ ancestors.delete(value);
40
+ return valid;
41
+ }
42
+ async function finalizeToolResult(tool, result) {
43
+ const content = normalizeToolContent(result.content);
44
+ let structuredContent = result.structuredContent;
45
+ if (tool.outputSchema && !result.isError) {
46
+ if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
47
+ try {
48
+ const parsed = await safeParseAsync(schemaFromDefinition(tool.outputSchema, false), structuredContent);
49
+ if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${getParseErrorMessage(parsed.error)}`);
50
+ structuredContent = parsed.data;
51
+ } catch {
52
+ return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
53
+ }
54
+ }
55
+ if (structuredContent !== void 0 && !isJsonValue(structuredContent)) {
56
+ if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
57
+ structuredContent = void 0;
58
+ }
59
+ if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
60
+ type: "text",
61
+ text: JSON.stringify(structuredContent)
62
+ });
63
+ return {
64
+ content,
65
+ structuredContent,
66
+ isError: result.isError
67
+ };
68
+ }
69
+ //#endregion
70
+ export { isJsonValue as n, normalizeToolContent as r, finalizeToolResult as t };