@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.
- package/README.md +7 -1
- package/dist/{authorize-Cs1yyLrq.d.ts → authorize-BjNE3LPr.d.ts} +1 -1
- package/dist/{authorize-BcNuNPtP.d.cts → authorize-BzZFS0zi.d.cts} +1 -1
- package/dist/{base-CUkmyaXJ.d.cts → base-C8osWdMU.d.cts} +3 -0
- package/dist/{base-CUkmyaXJ.d.ts → base-C8osWdMU.d.ts} +3 -0
- package/dist/cli/extract-manifest.cjs +2 -2
- package/dist/cli/extract-manifest.js +2 -2
- package/dist/{authorize--rUeMOGU.js → cors-BDTQQJE2.js} +68 -24
- package/dist/{authorize-ChY44o_1.cjs → cors-BRv5KXKQ.cjs} +73 -29
- package/dist/{forwarded-BlLF3dfc.js → forwarded-B3EBjHnA.js} +3 -3
- package/dist/{forwarded-Bhwcj22u.cjs → forwarded-BC_RHnn5.cjs} +3 -3
- package/dist/{gate-CGZl0gjJ.cjs → gate-CAJSRt_t.cjs} +6 -4
- package/dist/{gate-BiM6EBeA.js → gate-uCVrbDBb.js} +5 -3
- package/dist/index.cjs +37 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +37 -0
- package/dist/{io-SMlD5WeX.d.ts → io-BYUyNFdn.d.ts} +1 -1
- package/dist/{io-VBHO8YH_.d.cts → io-B_YLNWDL.d.cts} +1 -1
- package/dist/{list-tools-BLGr7mot.js → list-tools-C1OiTDR9.js} +9 -13
- package/dist/{list-tools-BN97L2Yv.d.cts → list-tools-C3AoI2Zw.d.cts} +3 -3
- package/dist/list-tools-DES10avA.cjs +48 -0
- package/dist/{list-tools-BAqQVIHk.d.ts → list-tools-DXqSPvNY.d.ts} +3 -3
- package/dist/mcp-C9B7o75m.cjs +345 -0
- package/dist/mcp-HDkUr85V.js +340 -0
- package/dist/{package-DgiA0xuY.js → package-BI5r4uGM.js} +1 -1
- package/dist/{package-CGLPZwz-.cjs → package-ClCIqol1.cjs} +1 -1
- package/dist/protocols/mcp/index.cjs +1 -1
- package/dist/protocols/mcp/index.d.cts +3 -3
- package/dist/protocols/mcp/index.d.ts +3 -3
- package/dist/protocols/mcp/index.js +1 -1
- package/dist/protocols/oauth-metadata.cjs +11 -9
- package/dist/protocols/oauth-metadata.d.cts +2 -2
- package/dist/protocols/oauth-metadata.d.ts +2 -2
- package/dist/protocols/oauth-metadata.js +5 -3
- package/dist/protocols/rest/index.cjs +2 -2
- package/dist/protocols/rest/index.d.cts +4 -4
- package/dist/protocols/rest/index.d.ts +4 -4
- package/dist/protocols/rest/index.js +2 -2
- package/dist/{rest-BE05MUNS.cjs → rest-BBdfHMGh.cjs} +28 -27
- package/dist/{rest-BS7bBOd9.js → rest-Cr7NhxL3.js} +13 -12
- package/dist/schema-CW1jKvio.js +65 -0
- package/dist/schema-D3vClxb7.cjs +76 -0
- package/dist/stacks/supabase/index.cjs +7 -7
- package/dist/stacks/supabase/index.d.cts +1 -1
- package/dist/stacks/supabase/index.d.ts +1 -1
- package/dist/stacks/supabase/index.js +5 -5
- package/dist/stacks/supabase/vite.cjs +1 -1
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +1 -1
- package/dist/stacks/tanstack/index.cjs +8 -8
- package/dist/stacks/tanstack/index.d.cts +2 -2
- package/dist/stacks/tanstack/index.d.ts +2 -2
- package/dist/stacks/tanstack/index.js +5 -5
- package/dist/stacks/tanstack/vite.cjs +8 -4
- package/dist/stacks/tanstack/vite.d.cts +7 -1
- package/dist/stacks/tanstack/vite.d.ts +7 -1
- package/dist/stacks/tanstack/vite.js +8 -4
- package/dist/tool-result-CK6hXO43.cjs +89 -0
- package/dist/tool-result-DfCk445b.js +78 -0
- package/dist/{types-C0Wgm9zp.d.cts → types-D1cgsnPu.d.cts} +15 -7
- package/dist/{types-C0Wgm9zp.d.ts → types-D1cgsnPu.d.ts} +15 -7
- package/package.json +2 -1
- package/dist/content-D5LJAHyM.js +0 -12
- package/dist/content-NCYIGgOb.cjs +0 -17
- package/dist/list-tools-DCF6G4fn.cjs +0 -52
- package/dist/mcp-CUGwXkxb.cjs +0 -153
- package/dist/mcp-Czp-hHjN.js +0 -148
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { i as log, r as describeError } from "./logger-Ctv5xUSD.js";
|
|
2
|
+
import { n as schemaFromDefinition, t as jsonSchemaFromDefinition } from "./schema-CW1jKvio.js";
|
|
3
|
+
import { i as ToolContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-DSe96Ffd.js";
|
|
4
|
+
import { r as createRequestAuthorizer, u as nowMs } from "./cors-BDTQQJE2.js";
|
|
5
|
+
import { n as extractTextContent, t as finalizeToolResult } from "./tool-result-DfCk445b.js";
|
|
6
|
+
import { t as createGatedHandler } from "./gate-uCVrbDBb.js";
|
|
7
|
+
import { normalizeObjectSchema, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
8
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
10
|
+
import { McpServer as McpServer$1, classifyInboundRequest, createMcpHandler, isJsonContentType, isLegacyRequest } from "@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 = 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 = schemaFromDefinition(definition);
|
|
77
|
+
return { "~standard": {
|
|
78
|
+
version: 1,
|
|
79
|
+
vendor: "zod",
|
|
80
|
+
validate: async (value) => {
|
|
81
|
+
const parsed = await safeParseAsync(schema, value);
|
|
82
|
+
return parsed.success ? { value: parsed.data } : { issues: zodIssues(parsed.error) };
|
|
83
|
+
},
|
|
84
|
+
jsonSchema: {
|
|
85
|
+
input: () => jsonSchemaFromDefinition(definition, "input"),
|
|
86
|
+
output: () => 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 = nowMs();
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
result = await tool.handler(args, new ToolContext(auth));
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const callerMessage = 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: nowMs() - start,
|
|
105
|
+
errorText: errorSummary(err),
|
|
106
|
+
endUserId,
|
|
107
|
+
protocol
|
|
108
|
+
});
|
|
109
|
+
return 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: nowMs() - start,
|
|
131
|
+
endUserId,
|
|
132
|
+
protocol
|
|
133
|
+
});
|
|
134
|
+
return finalizeToolResult(tool, {
|
|
135
|
+
content: [{
|
|
136
|
+
type: "text",
|
|
137
|
+
text: `tool "${tool.name}" returned no result`
|
|
138
|
+
}],
|
|
139
|
+
isError: true
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
result = await finalizeToolResult(tool, result);
|
|
143
|
+
await recorder.emit({
|
|
144
|
+
tool: tool.name,
|
|
145
|
+
method: "tools/call",
|
|
146
|
+
outcome: result.isError ? "tool_error" : "ok",
|
|
147
|
+
durationMs: nowMs() - start,
|
|
148
|
+
errorText: result.isError ? 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 McpServer$1({
|
|
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 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 ? schemaFromDefinition(tool.outputSchema) : void 0;
|
|
199
|
+
const legacyOutputSchemaWrapped = naturalOutputSchema !== void 0 && 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 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 = 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 = createMcpHandler(() => buildServer(mcp, authResult.auth, recorder), {
|
|
276
|
+
legacy: "reject",
|
|
277
|
+
onerror: (error) => {
|
|
278
|
+
protocolError = error;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
let response;
|
|
282
|
+
if (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 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
|
+
log.error("mcp.transport_error", {
|
|
305
|
+
...protocolError ? 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
|
+
log.error("mcp.transport_error", {
|
|
318
|
+
...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 createGatedHandler({
|
|
332
|
+
authorizer,
|
|
333
|
+
allowedOrigins: mcp.allowedOrigins,
|
|
334
|
+
methods: ["POST"],
|
|
335
|
+
methodNotAllowed: statelessMethodNotAllowed,
|
|
336
|
+
handle
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
export { createMcpProtocolHandler as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { t as McpRuntimeOptions } from "../../authorize-
|
|
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/mcp/protocol.d.ts
|
|
5
5
|
type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { t as McpRuntimeOptions } from "../../authorize-
|
|
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/mcp/protocol.d.ts
|
|
5
5
|
type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
|
|
6
6
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
1
|
+
import { t as createMcpProtocolHandler } from "../../mcp-HDkUr85V.js";
|
|
2
2
|
export { createMcpProtocolHandler };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_logger = require("../logger-CN1q-KNn.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_cors = require("../cors-BRv5KXKQ.cjs");
|
|
4
4
|
//#region src/protocols/oauth-metadata.ts
|
|
5
5
|
function notFound() {
|
|
6
6
|
return new Response(JSON.stringify({ error: "not found" }), {
|
|
7
7
|
status: 404,
|
|
8
8
|
headers: {
|
|
9
|
-
...
|
|
9
|
+
...require_cors.JSON_HEADERS,
|
|
10
10
|
"Cache-Control": "no-store"
|
|
11
11
|
}
|
|
12
12
|
});
|
|
@@ -14,7 +14,7 @@ function notFound() {
|
|
|
14
14
|
async function buildProtectedResourceMetadata(mcp, auth, request, options, discovery) {
|
|
15
15
|
const issuer = await discovery.resolveIssuer();
|
|
16
16
|
const body = {
|
|
17
|
-
resource:
|
|
17
|
+
resource: require_cors.resolveProtectedResource(auth, request, options),
|
|
18
18
|
authorization_servers: [issuer],
|
|
19
19
|
bearer_methods_supported: ["header"],
|
|
20
20
|
resource_name: auth.resourceName ?? mcp.title,
|
|
@@ -24,7 +24,7 @@ async function buildProtectedResourceMetadata(mcp, auth, request, options, disco
|
|
|
24
24
|
return body;
|
|
25
25
|
}
|
|
26
26
|
function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
|
|
27
|
-
const runtime =
|
|
27
|
+
const runtime = require_cors.getOAuthRuntime(mcp, options);
|
|
28
28
|
if (runtime.kind === "configured" && runtime.auth.protectedResourceMetadataUrl === void 0 && runtime.auth.resource === void 0) {
|
|
29
29
|
if (runtime.options.resourcePath === void 0) throw new Error(`@lovable.dev/mcp-js: auth.resource or a resourcePath is required so the protected-resource metadata doesn't advertise the well-known URL as the resource`);
|
|
30
30
|
if (runtime.options.trustForwardedHost === true && runtime.options.forwardedHostTrustedByPlatform !== true) require_logger.log.warn("oauth.metadata.host_derived_resource", { detail: "trustForwardedHost is on and auth.resource is unpinned; the advertised resource follows X-Forwarded-Host. Pin auth.resource unless a trusted proxy overwrites that header." });
|
|
@@ -35,9 +35,9 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
|
|
|
35
35
|
const vary = varyHeaders.join(", ");
|
|
36
36
|
const respond = async (request) => {
|
|
37
37
|
if (runtime.kind !== "configured" || runtime.auth.protectedResourceMetadataUrl !== void 0) return notFound();
|
|
38
|
-
if (request.method !== "GET" && request.method !== "HEAD") return
|
|
38
|
+
if (request.method !== "GET" && request.method !== "HEAD") return require_cors.methodNotAllowed("GET, HEAD, OPTIONS");
|
|
39
39
|
const headers = {
|
|
40
|
-
...
|
|
40
|
+
...require_cors.JSON_HEADERS,
|
|
41
41
|
"Cache-Control": "public, max-age=300",
|
|
42
42
|
Vary: vary
|
|
43
43
|
};
|
|
@@ -49,12 +49,14 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
|
|
|
49
49
|
...require_logger.describeError(err),
|
|
50
50
|
outcome: "500 oauth configuration error"
|
|
51
51
|
});
|
|
52
|
-
return
|
|
52
|
+
return require_cors.oauthConfigurationErrorResponse();
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
return async (request) => {
|
|
56
|
-
|
|
57
|
-
return
|
|
56
|
+
const cors = require_cors.evaluateCors(request, mcp.allowedOrigins);
|
|
57
|
+
if (!cors.ok) return require_cors.finalizeWireResponse(request, cors.response);
|
|
58
|
+
if (request.method === "OPTIONS") return cors.preflight("GET, HEAD, OPTIONS");
|
|
59
|
+
return require_cors.finalizeWireResponse(request, cors.withHeaders(await respond(request)));
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as McpRuntimeOptions } from "../authorize-
|
|
1
|
+
import { u as McpDefinition } from "../types-D1cgsnPu.cjs";
|
|
2
|
+
import { t as McpRuntimeOptions } from "../authorize-BzZFS0zi.cjs";
|
|
3
3
|
//#region src/protocols/oauth-metadata.d.ts
|
|
4
4
|
type OAuthProtectedResourceMetadataHandler = (request: Request) => Promise<Response>;
|
|
5
5
|
declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as McpRuntimeOptions } from "../authorize-
|
|
1
|
+
import { u as McpDefinition } from "../types-D1cgsnPu.js";
|
|
2
|
+
import { t as McpRuntimeOptions } from "../authorize-BjNE3LPr.js";
|
|
3
3
|
//#region src/protocols/oauth-metadata.d.ts
|
|
4
4
|
type OAuthProtectedResourceMetadataHandler = (request: Request) => Promise<Response>;
|
|
5
5
|
declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as log, r as describeError } from "../logger-Ctv5xUSD.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as oauthConfigurationErrorResponse, d as JSON_HEADERS, f as finalizeWireResponse, i as getOAuthRuntime, p as methodNotAllowed, s as resolveProtectedResource, t as evaluateCors } from "../cors-BDTQQJE2.js";
|
|
3
3
|
//#region src/protocols/oauth-metadata.ts
|
|
4
4
|
function notFound() {
|
|
5
5
|
return new Response(JSON.stringify({ error: "not found" }), {
|
|
@@ -52,8 +52,10 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
return async (request) => {
|
|
55
|
-
|
|
56
|
-
return finalizeWireResponse(request,
|
|
55
|
+
const cors = evaluateCors(request, mcp.allowedOrigins);
|
|
56
|
+
if (!cors.ok) return finalizeWireResponse(request, cors.response);
|
|
57
|
+
if (request.method === "OPTIONS") return cors.preflight("GET, HEAD, OPTIONS");
|
|
58
|
+
return finalizeWireResponse(request, cors.withHeaders(await respond(request)));
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
61
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_list_tools = require("../../list-tools-
|
|
3
|
-
const require_rest = require("../../rest-
|
|
2
|
+
const require_list_tools = require("../../list-tools-DES10avA.cjs");
|
|
3
|
+
const require_rest = require("../../rest-BBdfHMGh.cjs");
|
|
4
4
|
exports.createInvokeToolHandler = require_rest.createInvokeToolHandler;
|
|
5
5
|
exports.createListToolsHandler = require_list_tools.createListToolsHandler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { t as McpRuntimeOptions } from "../../authorize-
|
|
4
|
-
import { n as createListToolsHandler, t as RestListToolsHandler } from "../../list-tools-
|
|
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
|
+
import { n as createListToolsHandler, t as RestListToolsHandler } from "../../list-tools-C3AoI2Zw.cjs";
|
|
5
5
|
//#region src/protocols/rest/invoke-tool.d.ts
|
|
6
6
|
type RestInvokeToolHandler = (request: Request, toolName: string, recorder?: MetricsRecorder) => Promise<Response>;
|
|
7
7
|
declare function createInvokeToolHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestInvokeToolHandler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { t as McpRuntimeOptions } from "../../authorize-
|
|
4
|
-
import { n as createListToolsHandler, t as RestListToolsHandler } from "../../list-tools-
|
|
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
|
+
import { n as createListToolsHandler, t as RestListToolsHandler } from "../../list-tools-DXqSPvNY.js";
|
|
5
5
|
//#region src/protocols/rest/invoke-tool.d.ts
|
|
6
6
|
type RestInvokeToolHandler = (request: Request, toolName: string, recorder?: MetricsRecorder) => Promise<Response>;
|
|
7
7
|
declare function createInvokeToolHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestInvokeToolHandler;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as createListToolsHandler } from "../../list-tools-
|
|
2
|
-
import { t as createInvokeToolHandler } from "../../rest-
|
|
1
|
+
import { n as createListToolsHandler } from "../../list-tools-C1OiTDR9.js";
|
|
2
|
+
import { t as createInvokeToolHandler } from "../../rest-Cr7NhxL3.js";
|
|
3
3
|
export { createInvokeToolHandler, createListToolsHandler };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_errors = require("./errors-CN6Da8iz.cjs");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const require_gate = require("./gate-
|
|
5
|
-
require("./list-tools-
|
|
2
|
+
const require_cors = require("./cors-BRv5KXKQ.cjs");
|
|
3
|
+
const require_tool_result = require("./tool-result-CK6hXO43.cjs");
|
|
4
|
+
const require_gate = require("./gate-CAJSRt_t.cjs");
|
|
5
|
+
require("./list-tools-DES10avA.cjs");
|
|
6
6
|
let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
7
7
|
//#region src/protocols/rest/invoke-tool.ts
|
|
8
8
|
const MAX_REFLECTED_TOOL_NAME = 256;
|
|
@@ -16,13 +16,13 @@ function isEmptyArgs(value) {
|
|
|
16
16
|
return Object.keys(value).length === 0;
|
|
17
17
|
}
|
|
18
18
|
function createInvokeToolHandler(mcp, options = {}) {
|
|
19
|
-
|
|
19
|
+
require_cors.assertRestResourceBinding(mcp, options);
|
|
20
20
|
const handle = async (request, authResult, recorder, toolName) => {
|
|
21
21
|
const endUserId = authResult.auth?.principal.sub;
|
|
22
22
|
const tool = mcp.tools.find((t) => t.name === toolName);
|
|
23
23
|
if (!tool) return new Response(JSON.stringify({ error: `unknown tool: ${safeReflectName(toolName)}` }), {
|
|
24
24
|
status: 404,
|
|
25
|
-
headers:
|
|
25
|
+
headers: require_cors.JSON_HEADERS
|
|
26
26
|
});
|
|
27
27
|
let rawArgs = {};
|
|
28
28
|
const text = await request.text();
|
|
@@ -31,7 +31,7 @@ function createInvokeToolHandler(mcp, options = {}) {
|
|
|
31
31
|
} catch {
|
|
32
32
|
return new Response(JSON.stringify({ error: "invalid JSON body" }), {
|
|
33
33
|
status: 400,
|
|
34
|
-
headers:
|
|
34
|
+
headers: require_cors.JSON_HEADERS
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
let args = rawArgs;
|
|
@@ -42,7 +42,7 @@ function createInvokeToolHandler(mcp, options = {}) {
|
|
|
42
42
|
details: (0, _modelcontextprotocol_sdk_server_zod_compat_js.getParseErrorMessage)(parsed.error)
|
|
43
43
|
}), {
|
|
44
44
|
status: 400,
|
|
45
|
-
headers:
|
|
45
|
+
headers: require_cors.JSON_HEADERS
|
|
46
46
|
});
|
|
47
47
|
args = parsed.data;
|
|
48
48
|
} catch {
|
|
@@ -51,15 +51,15 @@ function createInvokeToolHandler(mcp, options = {}) {
|
|
|
51
51
|
tool: toolName
|
|
52
52
|
}), {
|
|
53
53
|
status: 500,
|
|
54
|
-
headers:
|
|
54
|
+
headers: require_cors.JSON_HEADERS
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
else if (!isEmptyArgs(rawArgs)) return new Response(JSON.stringify({ error: "tool has no inputSchema; expected empty body" }), {
|
|
58
58
|
status: 400,
|
|
59
|
-
headers:
|
|
59
|
+
headers: require_cors.JSON_HEADERS
|
|
60
60
|
});
|
|
61
61
|
let result;
|
|
62
|
-
const start =
|
|
62
|
+
const start = require_cors.nowMs();
|
|
63
63
|
try {
|
|
64
64
|
result = await tool.handler(args, new require_errors.ToolContext(authResult.auth));
|
|
65
65
|
} catch (err) {
|
|
@@ -69,16 +69,17 @@ function createInvokeToolHandler(mcp, options = {}) {
|
|
|
69
69
|
tool: tool.name,
|
|
70
70
|
method: "tools/call",
|
|
71
71
|
outcome: "handler_error",
|
|
72
|
-
durationMs:
|
|
72
|
+
durationMs: require_cors.nowMs() - start,
|
|
73
73
|
errorText: require_errors.errorSummary(err),
|
|
74
|
-
endUserId
|
|
74
|
+
endUserId,
|
|
75
|
+
protocol: "rest"
|
|
75
76
|
});
|
|
76
77
|
return new Response(JSON.stringify({
|
|
77
78
|
error: "handler threw",
|
|
78
79
|
tool: toolName
|
|
79
80
|
}), {
|
|
80
81
|
status: 500,
|
|
81
|
-
headers:
|
|
82
|
+
headers: require_cors.JSON_HEADERS
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
85
|
result = {
|
|
@@ -94,32 +95,32 @@ function createInvokeToolHandler(mcp, options = {}) {
|
|
|
94
95
|
tool: tool.name,
|
|
95
96
|
method: "tools/call",
|
|
96
97
|
outcome: "handler_error",
|
|
97
|
-
durationMs:
|
|
98
|
-
endUserId
|
|
98
|
+
durationMs: require_cors.nowMs() - start,
|
|
99
|
+
endUserId,
|
|
100
|
+
protocol: "rest"
|
|
99
101
|
});
|
|
100
102
|
return new Response(JSON.stringify({ error: `tool "${toolName}" returned no result` }), {
|
|
101
103
|
status: 500,
|
|
102
|
-
headers:
|
|
104
|
+
headers: require_cors.JSON_HEADERS
|
|
103
105
|
});
|
|
104
106
|
}
|
|
107
|
+
result = await require_tool_result.finalizeToolResult(tool, result);
|
|
105
108
|
await recorder.emit({
|
|
106
109
|
tool: tool.name,
|
|
107
110
|
method: "tools/call",
|
|
108
111
|
outcome: result.isError ? "tool_error" : "ok",
|
|
109
|
-
durationMs:
|
|
110
|
-
errorText: result.isError ?
|
|
111
|
-
endUserId
|
|
112
|
-
|
|
113
|
-
return Response.json({
|
|
114
|
-
content: result.content ?? [],
|
|
115
|
-
structuredContent: result.structuredContent,
|
|
116
|
-
isError: result.isError
|
|
112
|
+
durationMs: require_cors.nowMs() - start,
|
|
113
|
+
errorText: result.isError ? require_tool_result.extractTextContent(result.content) : void 0,
|
|
114
|
+
endUserId,
|
|
115
|
+
protocol: "rest"
|
|
117
116
|
});
|
|
117
|
+
return Response.json(result);
|
|
118
118
|
};
|
|
119
119
|
const gated = require_gate.createGatedHandler({
|
|
120
|
-
authorizer:
|
|
120
|
+
authorizer: require_cors.createRequestAuthorizer(mcp, options),
|
|
121
|
+
allowedOrigins: mcp.allowedOrigins,
|
|
121
122
|
methods: ["POST"],
|
|
122
|
-
methodNotAllowed:
|
|
123
|
+
methodNotAllowed: require_cors.methodNotAllowed,
|
|
123
124
|
handle
|
|
124
125
|
});
|
|
125
126
|
return (request, toolName, recorder) => gated(request, recorder, toolName);
|