@lovable.dev/mcp-js 0.28.0 → 0.29.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +7 -1
  2. package/dist/{authorize-Cs1yyLrq.d.ts → authorize-BjNE3LPr.d.ts} +1 -1
  3. package/dist/{authorize-BcNuNPtP.d.cts → authorize-BzZFS0zi.d.cts} +1 -1
  4. package/dist/{base-CUkmyaXJ.d.cts → base-C8osWdMU.d.cts} +3 -0
  5. package/dist/{base-CUkmyaXJ.d.ts → base-C8osWdMU.d.ts} +3 -0
  6. package/dist/cli/extract-manifest.cjs +2 -2
  7. package/dist/cli/extract-manifest.js +2 -2
  8. package/dist/{authorize--rUeMOGU.js → cors-BDTQQJE2.js} +68 -24
  9. package/dist/{authorize-ChY44o_1.cjs → cors-BRv5KXKQ.cjs} +73 -29
  10. package/dist/{forwarded-BlLF3dfc.js → forwarded-B3EBjHnA.js} +3 -3
  11. package/dist/{forwarded-Bhwcj22u.cjs → forwarded-BC_RHnn5.cjs} +3 -3
  12. package/dist/{gate-CGZl0gjJ.cjs → gate-CAJSRt_t.cjs} +6 -4
  13. package/dist/{gate-BiM6EBeA.js → gate-uCVrbDBb.js} +5 -3
  14. package/dist/index.cjs +37 -0
  15. package/dist/index.d.cts +3 -3
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +37 -0
  18. package/dist/{io-SMlD5WeX.d.ts → io-BYUyNFdn.d.ts} +1 -1
  19. package/dist/{io-VBHO8YH_.d.cts → io-B_YLNWDL.d.cts} +1 -1
  20. package/dist/{list-tools-BLGr7mot.js → list-tools-C1OiTDR9.js} +9 -13
  21. package/dist/{list-tools-BN97L2Yv.d.cts → list-tools-C3AoI2Zw.d.cts} +3 -3
  22. package/dist/list-tools-DES10avA.cjs +48 -0
  23. package/dist/{list-tools-BAqQVIHk.d.ts → list-tools-DXqSPvNY.d.ts} +3 -3
  24. package/dist/mcp-C9B7o75m.cjs +345 -0
  25. package/dist/mcp-HDkUr85V.js +340 -0
  26. package/dist/{package-DgiA0xuY.js → package-BI5r4uGM.js} +1 -1
  27. package/dist/{package-CGLPZwz-.cjs → package-ClCIqol1.cjs} +1 -1
  28. package/dist/protocols/mcp/index.cjs +1 -1
  29. package/dist/protocols/mcp/index.d.cts +3 -3
  30. package/dist/protocols/mcp/index.d.ts +3 -3
  31. package/dist/protocols/mcp/index.js +1 -1
  32. package/dist/protocols/oauth-metadata.cjs +11 -9
  33. package/dist/protocols/oauth-metadata.d.cts +2 -2
  34. package/dist/protocols/oauth-metadata.d.ts +2 -2
  35. package/dist/protocols/oauth-metadata.js +5 -3
  36. package/dist/protocols/rest/index.cjs +2 -2
  37. package/dist/protocols/rest/index.d.cts +4 -4
  38. package/dist/protocols/rest/index.d.ts +4 -4
  39. package/dist/protocols/rest/index.js +2 -2
  40. package/dist/{rest-BE05MUNS.cjs → rest-BBdfHMGh.cjs} +28 -27
  41. package/dist/{rest-BS7bBOd9.js → rest-Cr7NhxL3.js} +13 -12
  42. package/dist/schema-CW1jKvio.js +65 -0
  43. package/dist/schema-D3vClxb7.cjs +76 -0
  44. package/dist/stacks/supabase/index.cjs +7 -7
  45. package/dist/stacks/supabase/index.d.cts +1 -1
  46. package/dist/stacks/supabase/index.d.ts +1 -1
  47. package/dist/stacks/supabase/index.js +5 -5
  48. package/dist/stacks/supabase/vite.cjs +1 -1
  49. package/dist/stacks/supabase/vite.d.cts +1 -1
  50. package/dist/stacks/supabase/vite.d.ts +1 -1
  51. package/dist/stacks/supabase/vite.js +1 -1
  52. package/dist/stacks/tanstack/index.cjs +8 -8
  53. package/dist/stacks/tanstack/index.d.cts +2 -2
  54. package/dist/stacks/tanstack/index.d.ts +2 -2
  55. package/dist/stacks/tanstack/index.js +5 -5
  56. package/dist/stacks/tanstack/vite.cjs +8 -4
  57. package/dist/stacks/tanstack/vite.d.cts +7 -1
  58. package/dist/stacks/tanstack/vite.d.ts +7 -1
  59. package/dist/stacks/tanstack/vite.js +8 -4
  60. package/dist/tool-result-CK6hXO43.cjs +89 -0
  61. package/dist/tool-result-DfCk445b.js +78 -0
  62. package/dist/{types-C0Wgm9zp.d.cts → types-D1cgsnPu.d.cts} +15 -7
  63. package/dist/{types-C0Wgm9zp.d.ts → types-D1cgsnPu.d.ts} +15 -7
  64. package/package.json +2 -1
  65. package/dist/content-D5LJAHyM.js +0 -12
  66. package/dist/content-NCYIGgOb.cjs +0 -17
  67. package/dist/list-tools-DCF6G4fn.cjs +0 -52
  68. package/dist/mcp-CUGwXkxb.cjs +0 -153
  69. package/dist/mcp-Czp-hHjN.js +0 -148
@@ -1,6 +1,6 @@
1
- import { c as McpDefinition } from "./types-C0Wgm9zp.cjs";
2
- import { t as MetricsRecorder } from "./base-CUkmyaXJ.cjs";
3
- import { t as McpRuntimeOptions } from "./authorize-BcNuNPtP.cjs";
1
+ import { u as McpDefinition } from "./types-D1cgsnPu.cjs";
2
+ import { t as MetricsRecorder } from "./base-C8osWdMU.cjs";
3
+ import { t as McpRuntimeOptions } from "./authorize-BzZFS0zi.cjs";
4
4
  //#region src/protocols/rest/list-tools.d.ts
5
5
  type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
6
  declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
@@ -0,0 +1,48 @@
1
+ const require_schema = require("./schema-D3vClxb7.cjs");
2
+ const require_cors = require("./cors-BRv5KXKQ.cjs");
3
+ const require_gate = require("./gate-CAJSRt_t.cjs");
4
+ //#region src/protocols/rest/list-tools.ts
5
+ function schemaToJsonSchema(definition, pipeStrategy) {
6
+ if (!definition) return null;
7
+ return require_schema.jsonSchemaFromDefinition(definition, pipeStrategy);
8
+ }
9
+ function buildMcpListing(mcp) {
10
+ return {
11
+ server: {
12
+ name: mcp.name,
13
+ version: mcp.version,
14
+ title: mcp.title
15
+ },
16
+ tools: mcp.tools.map((tool) => ({
17
+ name: tool.name,
18
+ title: tool.title,
19
+ description: tool.description,
20
+ annotations: tool.annotations,
21
+ inputSchema: schemaToJsonSchema(tool.inputSchema, "input"),
22
+ outputSchema: schemaToJsonSchema(tool.outputSchema, "output")
23
+ }))
24
+ };
25
+ }
26
+ function createListToolsHandler(mcp, options = {}) {
27
+ require_cors.assertRestResourceBinding(mcp, options);
28
+ return require_gate.createGatedHandler({
29
+ authorizer: require_cors.createRequestAuthorizer(mcp, options),
30
+ allowedOrigins: mcp.allowedOrigins,
31
+ methods: ["GET", "HEAD"],
32
+ methodNotAllowed: require_cors.methodNotAllowed,
33
+ handle: async () => Response.json(buildMcpListing(mcp))
34
+ });
35
+ }
36
+ //#endregion
37
+ Object.defineProperty(exports, "buildMcpListing", {
38
+ enumerable: true,
39
+ get: function() {
40
+ return buildMcpListing;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, "createListToolsHandler", {
44
+ enumerable: true,
45
+ get: function() {
46
+ return createListToolsHandler;
47
+ }
48
+ });
@@ -1,6 +1,6 @@
1
- import { c as McpDefinition } from "./types-C0Wgm9zp.js";
2
- import { t as MetricsRecorder } from "./base-CUkmyaXJ.js";
3
- import { t as McpRuntimeOptions } from "./authorize-Cs1yyLrq.js";
1
+ import { u as McpDefinition } from "./types-D1cgsnPu.js";
2
+ import { t as MetricsRecorder } from "./base-C8osWdMU.js";
3
+ import { t as McpRuntimeOptions } from "./authorize-BjNE3LPr.js";
4
4
  //#region src/protocols/rest/list-tools.d.ts
5
5
  type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
6
  declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
@@ -0,0 +1,345 @@
1
+ const require_logger = require("./logger-CN1q-KNn.cjs");
2
+ const require_schema = require("./schema-D3vClxb7.cjs");
3
+ const require_errors = require("./errors-CN6Da8iz.cjs");
4
+ const require_cors = require("./cors-BRv5KXKQ.cjs");
5
+ const require_tool_result = require("./tool-result-CK6hXO43.cjs");
6
+ const require_gate = require("./gate-CAJSRt_t.cjs");
7
+ let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
8
+ let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
9
+ let _modelcontextprotocol_sdk_server_webStandardStreamableHttp_js = require("@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js");
10
+ let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
11
+ //#region src/protocols/mcp/protocol.ts
12
+ const MODERN_PROTOCOL_VERSION = "2026-07-28";
13
+ function statelessMethodNotAllowed(allow) {
14
+ return Response.json({
15
+ jsonrpc: "2.0",
16
+ id: null,
17
+ error: {
18
+ code: -32e3,
19
+ message: "Method not allowed: stateless server offers no standalone SSE stream (GET) or session (DELETE)."
20
+ }
21
+ }, {
22
+ status: 405,
23
+ headers: { Allow: allow }
24
+ });
25
+ }
26
+ function acceptsResponseType(accept, responseType) {
27
+ if (accept === null) return false;
28
+ return accept.split(",").some((range) => {
29
+ const [mediaType, ...parameters] = range.split(";");
30
+ if (mediaType.trim().toLowerCase() !== responseType) return false;
31
+ const quality = parameters.find((parameter) => parameter.split("=", 1)[0]?.trim().toLowerCase() === "q");
32
+ if (quality === void 0) return true;
33
+ const separator = quality.indexOf("=");
34
+ if (separator === -1) return false;
35
+ const value = Number(quality.slice(separator + 1).trim());
36
+ return value > 0 && value <= 1;
37
+ });
38
+ }
39
+ function missingProtocolVersionHeader(id) {
40
+ return Response.json({
41
+ jsonrpc: "2.0",
42
+ id,
43
+ error: {
44
+ code: -32020,
45
+ message: "Bad Request: the required MCP-Protocol-Version header is absent",
46
+ data: { mismatch: {
47
+ header: "(missing)",
48
+ body: "the request body names protocol version 2026-07-28"
49
+ } }
50
+ }
51
+ }, { status: 400 });
52
+ }
53
+ function modernMessageWithoutProtocolHeader(request, body) {
54
+ if (request.headers.has("MCP-Protocol-Version")) return void 0;
55
+ const outcome = (0, _modelcontextprotocol_server.classifyInboundRequest)({
56
+ httpMethod: request.method,
57
+ mcpMethodHeader: request.headers.get("Mcp-Method") ?? void 0,
58
+ mcpNameHeader: request.headers.get("Mcp-Name") ?? void 0,
59
+ body
60
+ });
61
+ if (outcome.kind !== "modern" || outcome.classification.revision !== MODERN_PROTOCOL_VERSION) return;
62
+ return { id: outcome.messageKind === "request" ? outcome.message.id : null };
63
+ }
64
+ function zodIssues(error) {
65
+ const issues = error?.issues;
66
+ if (!Array.isArray(issues)) return [{ message: String(error) }];
67
+ return issues.map((issue) => {
68
+ const value = issue;
69
+ return {
70
+ message: typeof value.message === "string" ? value.message : String(value.message),
71
+ ...Array.isArray(value.path) ? { path: value.path } : {}
72
+ };
73
+ });
74
+ }
75
+ function standardSchemaFromDefinition(definition) {
76
+ const schema = require_schema.schemaFromDefinition(definition);
77
+ return { "~standard": {
78
+ version: 1,
79
+ vendor: "zod",
80
+ validate: async (value) => {
81
+ const parsed = await (0, _modelcontextprotocol_sdk_server_zod_compat_js.safeParseAsync)(schema, value);
82
+ return parsed.success ? { value: parsed.data } : { issues: zodIssues(parsed.error) };
83
+ },
84
+ jsonSchema: {
85
+ input: () => require_schema.jsonSchemaFromDefinition(definition, "input"),
86
+ output: () => require_schema.jsonSchemaFromDefinition(definition, "output")
87
+ }
88
+ } };
89
+ }
90
+ async function invokeTool(tool, auth, recorder, first, protocol) {
91
+ const endUserId = auth?.principal.sub;
92
+ const args = tool.inputSchema ? first ?? {} : {};
93
+ const start = require_cors.nowMs();
94
+ let result;
95
+ try {
96
+ result = await tool.handler(args, new require_errors.ToolContext(auth));
97
+ } catch (err) {
98
+ const callerMessage = require_errors.resolveToolErrorMessage(err);
99
+ if (callerMessage === void 0) {
100
+ await recorder.emit({
101
+ tool: tool.name,
102
+ method: "tools/call",
103
+ outcome: "handler_error",
104
+ durationMs: require_cors.nowMs() - start,
105
+ errorText: require_errors.errorSummary(err),
106
+ endUserId,
107
+ protocol
108
+ });
109
+ return require_tool_result.finalizeToolResult(tool, {
110
+ content: [{
111
+ type: "text",
112
+ text: "tool execution failed"
113
+ }],
114
+ isError: true
115
+ });
116
+ }
117
+ result = {
118
+ content: [{
119
+ type: "text",
120
+ text: callerMessage
121
+ }],
122
+ isError: true
123
+ };
124
+ }
125
+ if (result == null) {
126
+ await recorder.emit({
127
+ tool: tool.name,
128
+ method: "tools/call",
129
+ outcome: "handler_error",
130
+ durationMs: require_cors.nowMs() - start,
131
+ endUserId,
132
+ protocol
133
+ });
134
+ return require_tool_result.finalizeToolResult(tool, {
135
+ content: [{
136
+ type: "text",
137
+ text: `tool "${tool.name}" returned no result`
138
+ }],
139
+ isError: true
140
+ });
141
+ }
142
+ result = await require_tool_result.finalizeToolResult(tool, result);
143
+ await recorder.emit({
144
+ tool: tool.name,
145
+ method: "tools/call",
146
+ outcome: result.isError ? "tool_error" : "ok",
147
+ durationMs: require_cors.nowMs() - start,
148
+ errorText: result.isError ? require_tool_result.extractTextContent(result.content) : void 0,
149
+ endUserId,
150
+ protocol
151
+ });
152
+ return result;
153
+ }
154
+ function adaptToolCallback(tool, auth, recorder, legacy = false, legacyOutputSchemaWrapped = false) {
155
+ return async (first) => {
156
+ const result = await invokeTool(tool, auth, recorder, first, legacy ? "legacy" : MODERN_PROTOCOL_VERSION);
157
+ const content = result.content ?? [];
158
+ const structuredContent = result.structuredContent;
159
+ return {
160
+ content,
161
+ structuredContent: legacy && structuredContent !== void 0 && (legacyOutputSchemaWrapped || structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent))) ? { result: structuredContent } : structuredContent,
162
+ isError: result.isError
163
+ };
164
+ };
165
+ }
166
+ function buildServer(mcp, auth, recorder) {
167
+ const server = new _modelcontextprotocol_server.McpServer({
168
+ name: mcp.name,
169
+ version: mcp.version,
170
+ title: mcp.title
171
+ }, {
172
+ instructions: mcp.instructions,
173
+ capabilities: { tools: { listChanged: false } }
174
+ });
175
+ for (const tool of mcp.tools) {
176
+ const config = {
177
+ title: tool.title,
178
+ description: tool.description,
179
+ annotations: tool.annotations,
180
+ ...tool.outputSchema ? { outputSchema: standardSchemaFromDefinition(tool.outputSchema) } : {}
181
+ };
182
+ const callback = adaptToolCallback(tool, auth, recorder);
183
+ if (tool.inputSchema) server.registerTool(tool.name, {
184
+ ...config,
185
+ inputSchema: standardSchemaFromDefinition(tool.inputSchema)
186
+ }, callback);
187
+ else server.registerTool(tool.name, config, callback);
188
+ }
189
+ return server;
190
+ }
191
+ function buildLegacyServer(mcp, auth, recorder) {
192
+ const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
193
+ name: mcp.name,
194
+ version: mcp.version,
195
+ title: mcp.title
196
+ }, { instructions: mcp.instructions });
197
+ for (const tool of mcp.tools) {
198
+ const naturalOutputSchema = tool.outputSchema ? require_schema.schemaFromDefinition(tool.outputSchema) : void 0;
199
+ const legacyOutputSchemaWrapped = naturalOutputSchema !== void 0 && (0, _modelcontextprotocol_sdk_server_zod_compat_js.normalizeObjectSchema)(naturalOutputSchema) === void 0;
200
+ server.registerTool(tool.name, {
201
+ title: tool.title,
202
+ description: tool.description,
203
+ inputSchema: tool.inputSchema,
204
+ outputSchema: legacyOutputSchemaWrapped ? { result: naturalOutputSchema } : tool.outputSchema,
205
+ annotations: tool.annotations
206
+ }, adaptToolCallback(tool, auth, recorder, true, legacyOutputSchemaWrapped));
207
+ }
208
+ server.server.registerCapabilities({ tools: { listChanged: false } });
209
+ return server;
210
+ }
211
+ async function serveLegacy(request, parsedBody, mcp, auth, recorder) {
212
+ const server = buildLegacyServer(mcp, auth, recorder);
213
+ const transport = new _modelcontextprotocol_sdk_server_webStandardStreamableHttp_js.WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
214
+ let closed = false;
215
+ const close = () => {
216
+ if (closed) return;
217
+ closed = true;
218
+ transport.close().catch(() => {});
219
+ server.close().catch(() => {});
220
+ };
221
+ try {
222
+ await server.connect(transport);
223
+ request.signal.addEventListener("abort", close, { once: true });
224
+ const response = await transport.handleRequest(request, { parsedBody });
225
+ if (response.body === null || !response.headers.get("Content-Type")?.startsWith("text/event-stream")) {
226
+ close();
227
+ return response;
228
+ }
229
+ const reader = response.body.getReader();
230
+ const body = new ReadableStream({
231
+ async pull(controller) {
232
+ try {
233
+ const { done, value } = await reader.read();
234
+ if (done) {
235
+ close();
236
+ controller.close();
237
+ } else controller.enqueue(value);
238
+ } catch (error) {
239
+ close();
240
+ controller.error(error);
241
+ }
242
+ },
243
+ cancel(reason) {
244
+ close();
245
+ return reader.cancel(reason);
246
+ }
247
+ });
248
+ return new Response(body, response);
249
+ } catch (error) {
250
+ close();
251
+ throw error;
252
+ }
253
+ }
254
+ /**
255
+ * Build a Web-Standard request handler that serves the MCP protocol over
256
+ * streamable HTTP. A fresh `McpServer` + transport is constructed per
257
+ * request — the transport is stateless, so this is cheap and there is no
258
+ * cross-request state to leak. The per-request `recorder` is supplied by the
259
+ * caller (the stack handler) so telemetry reads the runtime env in-flight.
260
+ */
261
+ function createMcpProtocolHandler(mcp, options = {}) {
262
+ const authorizer = require_cors.createRequestAuthorizer(mcp, options);
263
+ const handle = async (request, authResult, recorder) => {
264
+ const accept = request.headers.get("Accept");
265
+ if (!acceptsResponseType(accept, "application/json") || !acceptsResponseType(accept, "text/event-stream")) return Response.json({
266
+ jsonrpc: "2.0",
267
+ id: null,
268
+ error: {
269
+ code: -32e3,
270
+ message: "Not Acceptable: Client must accept both application/json and text/event-stream"
271
+ }
272
+ }, { status: 406 });
273
+ let protocolError;
274
+ try {
275
+ const protocol = (0, _modelcontextprotocol_server.createMcpHandler)(() => buildServer(mcp, authResult.auth, recorder), {
276
+ legacy: "reject",
277
+ onerror: (error) => {
278
+ protocolError = error;
279
+ }
280
+ });
281
+ let response;
282
+ if ((0, _modelcontextprotocol_server.isJsonContentType)(request.headers.get("Content-Type"))) {
283
+ let parsedBody;
284
+ try {
285
+ parsedBody = await request.clone().json();
286
+ } catch {
287
+ const headerVersion = request.headers.get("MCP-Protocol-Version")?.trim();
288
+ response = headerVersion === void 0 || headerVersion < MODERN_PROTOCOL_VERSION ? await serveLegacy(request, void 0, mcp, authResult.auth, recorder) : await protocol.fetch(request);
289
+ }
290
+ if (response === void 0) {
291
+ const missingProtocolHeader = modernMessageWithoutProtocolHeader(request, parsedBody);
292
+ if (missingProtocolHeader !== void 0) return missingProtocolVersionHeader(missingProtocolHeader.id);
293
+ response = await (0, _modelcontextprotocol_server.isLegacyRequest)(request, parsedBody) ? await serveLegacy(request, parsedBody, mcp, authResult.auth, recorder) : await protocol.fetch(request, { parsedBody });
294
+ }
295
+ } else response = await protocol.fetch(request);
296
+ if (response.status < 500) return response;
297
+ await recorder.emit({
298
+ tool: null,
299
+ method: "transport",
300
+ outcome: "transport_error",
301
+ durationMs: 0,
302
+ endUserId: authResult.auth?.principal.sub
303
+ });
304
+ require_logger.log.error("mcp.transport_error", {
305
+ ...protocolError ? require_logger.describeError(protocolError) : {},
306
+ outcome: "500 internal error"
307
+ });
308
+ return response;
309
+ } catch (err) {
310
+ await recorder.emit({
311
+ tool: null,
312
+ method: "transport",
313
+ outcome: "transport_error",
314
+ durationMs: 0,
315
+ endUserId: authResult.auth?.principal.sub
316
+ });
317
+ require_logger.log.error("mcp.transport_error", {
318
+ ...require_logger.describeError(err),
319
+ outcome: "500 internal error"
320
+ });
321
+ return Response.json({
322
+ jsonrpc: "2.0",
323
+ id: null,
324
+ error: {
325
+ code: -32603,
326
+ message: "internal error"
327
+ }
328
+ }, { status: 500 });
329
+ }
330
+ };
331
+ return require_gate.createGatedHandler({
332
+ authorizer,
333
+ allowedOrigins: mcp.allowedOrigins,
334
+ methods: ["POST"],
335
+ methodNotAllowed: statelessMethodNotAllowed,
336
+ handle
337
+ });
338
+ }
339
+ //#endregion
340
+ Object.defineProperty(exports, "createMcpProtocolHandler", {
341
+ enumerable: true,
342
+ get: function() {
343
+ return createMcpProtocolHandler;
344
+ }
345
+ });