@lovable.dev/mcp-js 0.22.1 → 0.22.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/authorize-CumVyk7p.d.cts +27 -0
  2. package/dist/authorize-D6p4-9_D.d.ts +27 -0
  3. package/dist/base-DCe0kP79.d.cts +29 -0
  4. package/dist/base-DCe0kP79.d.ts +29 -0
  5. package/dist/cli/extract-manifest.cjs +116 -201
  6. package/dist/cli/extract-manifest.d.cts +1 -1
  7. package/dist/cli/extract-manifest.d.ts +1 -1
  8. package/dist/cli/extract-manifest.js +117 -156
  9. package/dist/content-D5LJAHyM.js +12 -0
  10. package/dist/content-NCYIGgOb.cjs +17 -0
  11. package/dist/context-BweeEcoA.cjs +56 -0
  12. package/dist/context-CIpPzN7P.js +51 -0
  13. package/dist/cors-CSDhBjFd.cjs +913 -0
  14. package/dist/cors-rWp_tbLZ.js +830 -0
  15. package/dist/forwarded--h4efJy-.js +43 -0
  16. package/dist/forwarded-Pi8Hs5Ps.cjs +48 -0
  17. package/dist/fs-errors-CWNzOV75.cjs +11 -0
  18. package/dist/fs-errors-PA2t1TIp.js +6 -0
  19. package/dist/index.cjs +129 -329
  20. package/dist/index.d.cts +26 -26
  21. package/dist/index.d.ts +26 -26
  22. package/dist/index.js +118 -177
  23. package/dist/{io-D4srzRKc.d.ts → io-CfSPxeBN.d.ts} +6 -4
  24. package/dist/io-DPYvBqET.d.cts +15 -0
  25. package/dist/list-tools-B4TTPEl1.d.cts +8 -0
  26. package/dist/list-tools-CFUX-uo-.cjs +57 -0
  27. package/dist/list-tools-DVJrjtmH.js +46 -0
  28. package/dist/list-tools-bh6-eqZM.d.ts +8 -0
  29. package/dist/logger-2OXtfiIW.js +141 -0
  30. package/dist/logger-BqPOa_E1.cjs +194 -0
  31. package/dist/mcp-BNcpj8o7.cjs +128 -0
  32. package/dist/mcp-Bx3bJHzH.js +123 -0
  33. package/dist/metadata-path-CAkNcfyY.js +12 -0
  34. package/dist/metadata-path-zd7NSNoa.cjs +17 -0
  35. package/dist/package-CgwD4Ywz.js +4 -0
  36. package/dist/package-DzstF8Ih.cjs +9 -0
  37. package/dist/paths-IS65L6TA.js +7 -0
  38. package/dist/paths-OP318a6c.cjs +18 -0
  39. package/dist/protocols/mcp/index.cjs +3 -750
  40. package/dist/protocols/mcp/index.d.cts +6 -7
  41. package/dist/protocols/mcp/index.d.ts +6 -7
  42. package/dist/protocols/mcp/index.js +2 -12
  43. package/dist/protocols/oauth-metadata.cjs +48 -539
  44. package/dist/protocols/oauth-metadata.d.cts +5 -6
  45. package/dist/protocols/oauth-metadata.d.ts +5 -6
  46. package/dist/protocols/oauth-metadata.js +52 -10
  47. package/dist/protocols/rest/index.cjs +5 -843
  48. package/dist/protocols/rest/index.d.cts +7 -10
  49. package/dist/protocols/rest/index.d.ts +7 -10
  50. package/dist/protocols/rest/index.js +3 -16
  51. package/dist/rest-BRshnow2.js +117 -0
  52. package/dist/rest-C4ZEGSIV.cjs +122 -0
  53. package/dist/stacks/supabase/index.cjs +76 -1318
  54. package/dist/stacks/supabase/index.d.cts +29 -30
  55. package/dist/stacks/supabase/index.d.ts +29 -30
  56. package/dist/stacks/supabase/index.js +73 -89
  57. package/dist/stacks/supabase/vite.cjs +258 -287
  58. package/dist/stacks/supabase/vite.d.cts +24 -24
  59. package/dist/stacks/supabase/vite.d.ts +24 -24
  60. package/dist/stacks/supabase/vite.js +252 -252
  61. package/dist/stacks/tanstack/index.cjs +42 -1272
  62. package/dist/stacks/tanstack/index.d.cts +8 -9
  63. package/dist/stacks/tanstack/index.d.ts +8 -9
  64. package/dist/stacks/tanstack/index.js +36 -41
  65. package/dist/stacks/tanstack/vite.cjs +223 -312
  66. package/dist/stacks/tanstack/vite.d.cts +80 -81
  67. package/dist/stacks/tanstack/vite.d.ts +80 -81
  68. package/dist/stacks/tanstack/vite.js +216 -282
  69. package/dist/types-BYdYYTjk.d.cts +321 -0
  70. package/dist/types-BYdYYTjk.d.ts +321 -0
  71. package/package.json +4 -4
  72. package/dist/authorize-BMeXd_Sh.d.ts +0 -25
  73. package/dist/base-CM-KCpp6.d.ts +0 -28
  74. package/dist/chunk-5HVSJCKE.js +0 -114
  75. package/dist/chunk-6DXGZZA4.js +0 -6
  76. package/dist/chunk-6QFZYYUV.js +0 -11
  77. package/dist/chunk-6SZOFKGH.js +0 -58
  78. package/dist/chunk-H37EB22A.js +0 -125
  79. package/dist/chunk-IFDWUM7L.js +0 -741
  80. package/dist/chunk-IXZIFYO6.js +0 -79
  81. package/dist/chunk-MA5H6PSF.js +0 -46
  82. package/dist/chunk-TJN33K5U.js +0 -141
  83. package/dist/chunk-UQK5UO6C.js +0 -26
  84. package/dist/chunk-XQWJN6DC.js +0 -14
  85. package/dist/chunk-Y3ZFPEQH.js +0 -8
  86. package/dist/chunk-ZQXSWTPU.js +0 -6
  87. package/dist/types-qqrmJ736.d.ts +0 -321
@@ -0,0 +1,321 @@
1
+ import { TypeOf, ZodRawShape, ZodType } from "zod";
2
+ //#region src/auth/types.d.ts
3
+ type JwtClaims = Record<string, unknown> & {
4
+ iss?: string;
5
+ sub?: string;
6
+ aud?: string | string[];
7
+ exp?: number;
8
+ iat?: number;
9
+ nbf?: number;
10
+ scope?: string;
11
+ client_id?: string;
12
+ email?: string;
13
+ /** RFC 8707 resource indicator(s) the token was granted for (Lovable OAuth convention). */
14
+ resource?: string | string[];
15
+ };
16
+ /**
17
+ * The safe-to-surface half of the auth context, reachable by tools only through
18
+ * `ToolContext` accessors (`getUserId()`, `getClaims()`, …). Carries no
19
+ * credential — the bearer is isolated in `OAuthBearer`.
20
+ */
21
+ interface OAuthPrincipal {
22
+ claims: JwtClaims;
23
+ issuer: string;
24
+ resource: string;
25
+ acceptedAudiences: readonly string[];
26
+ scopes: string[];
27
+ sub?: string;
28
+ email?: string;
29
+ clientId?: string;
30
+ }
31
+ /**
32
+ * The raw bearer, isolated from the safe fields. Pass it only into outbound
33
+ * `fetch`/client construction; never return or log it — a leaked token stays
34
+ * valid at the AS until it expires. `token` is a non-enumerable property, so
35
+ * `JSON.stringify`, object spread, and `console.log` omit it by construction.
36
+ */
37
+ interface OAuthBearer {
38
+ readonly token: string;
39
+ }
40
+ interface McpAuthContext {
41
+ type: "oauth";
42
+ principal: OAuthPrincipal;
43
+ bearer: OAuthBearer;
44
+ }
45
+ interface McpAuthConfig {
46
+ readonly type: "oauth";
47
+ readonly issuer: string;
48
+ readonly resource?: string;
49
+ readonly resourceName?: string;
50
+ readonly resourceDocumentation?: string;
51
+ /**
52
+ * Absolute URL of an externally hosted RFC 9728 protected-resource metadata
53
+ * document. When set, the SDK advertises this URL in the 401
54
+ * `WWW-Authenticate: resource_metadata` challenge and does not generate or
55
+ * serve its own metadata (the `/.well-known/oauth-protected-resource` handler
56
+ * 404s). Use it when the resource server already publishes its own PRM.
57
+ *
58
+ * Mutually exclusive with the Vite plugin's `metadataPath`: that option has
59
+ * the SDK serve the document itself at a custom path, so configuring both is
60
+ * rejected at handler construction.
61
+ */
62
+ readonly protectedResourceMetadataUrl?: string;
63
+ readonly requireOAuthClientClaim?: boolean;
64
+ readonly acceptedAudiences?: readonly string[];
65
+ /**
66
+ * Accept a token whose RFC 8707 `resource` claim matches an accepted
67
+ * audience (trailing slashes ignored) when its `aud` is an empty array or
68
+ * absent — the shape Lovable's OAuth server mints; applies to any configured
69
+ * issuer. A populated `aud` is always authoritative and is never overridden.
70
+ * Defaults to true. Set false to require a matching `aud` (strict RFC 9068).
71
+ */
72
+ readonly acceptResourceClaim?: boolean;
73
+ readonly requiredScopes?: readonly string[];
74
+ readonly jwksUri?: string;
75
+ readonly algorithms?: readonly string[];
76
+ readonly clockToleranceSeconds?: number;
77
+ /**
78
+ * Allowed values for the access token's JOSE `typ` header. Defaults to
79
+ * `["at+jwt", "JWT"]` so both the RFC 9068 access-token shape and the plain
80
+ * user-JWT shape (notably Supabase GoTrue's OAuth tokens) are accepted out of
81
+ * the box. Pin to `["at+jwt"]` to enforce strict RFC 9068. The header `typ`
82
+ * must be present and string-typed; this option only controls which values pass.
83
+ */
84
+ readonly accessTokenTyp?: readonly string[];
85
+ }
86
+ //#endregion
87
+ //#region src/auth/context.d.ts
88
+ /**
89
+ * The auth surface passed to every tool handler as its second argument. It wraps
90
+ * the verified per-request auth context in a private field, so the context — and
91
+ * the bearer token inside it — can't be read, enumerated, spread, or
92
+ * `JSON.stringify`'d off the instance; the accessors below are the only way out.
93
+ * `getToken()` is the single intentional escape hatch for the raw bearer.
94
+ */
95
+ declare class ToolContext {
96
+ #private;
97
+ constructor(auth: McpAuthContext | undefined);
98
+ /** Whether the in-flight tool call carries a verified auth context. */
99
+ isAuthenticated(): boolean;
100
+ /** The verified bearer token, or `undefined` when unauthenticated. Pass it to downstream APIs; never return or log it. */
101
+ getToken(): string | undefined;
102
+ /** The verified user id (the token `sub`), or `undefined`. */
103
+ getUserId(): string | undefined;
104
+ /** The verified user email, or `undefined` when absent. */
105
+ getUserEmail(): string | undefined;
106
+ /** The verified OAuth `client_id`, or `undefined`. */
107
+ getClientId(): string | undefined;
108
+ /** The verified OAuth scopes, or `undefined` when unauthenticated. */
109
+ getScopes(): string[] | undefined;
110
+ /** The verified token issuer, or `undefined`. */
111
+ getIssuer(): string | undefined;
112
+ /**
113
+ * The full verified JWT claims, or `undefined`. Use this for app/business
114
+ * authorization on issuer-specific claims that have no dedicated accessor.
115
+ */
116
+ getClaims(): JwtClaims | undefined;
117
+ }
118
+ //#endregion
119
+ //#region src/metrics/config.d.ts
120
+ /**
121
+ * Usage-metrics options. Pass a boolean to the Vite plugins for the common
122
+ * on/off case, or this object to override the ingest endpoint (e.g. to
123
+ * self-host the collector outside Lovable).
124
+ */
125
+ interface MetricsOptions {
126
+ /** Master switch. Default `true`; metrics still self-disable at runtime when
127
+ * the API key env var is absent. */
128
+ enabled?: boolean;
129
+ /** OTLP/HTTP (JSON) logs URL to POST each invocation to — the default Lovable
130
+ * route or any OTLP collector. Must be an absolute http(s) URL.
131
+ * @default "https://api.lovable.dev/v1/app-mcp-usage" */
132
+ endpoint?: string;
133
+ /** Extra request headers — e.g. the auth token for a private OTLP collector.
134
+ * Sent verbatim with every request (and baked into the build output, so source
135
+ * your own build-time env for secrets). Ignored for the default Lovable
136
+ * endpoint, which authenticates with `LOVABLE_API_KEY` instead. `content-type`
137
+ * cannot be overridden (OTLP/HTTP JSON requires `application/json`). */
138
+ headers?: Record<string, string>;
139
+ }
140
+ /** Either the bare on/off toggle or the full options object. */
141
+ type MetricsConfig = boolean | MetricsOptions;
142
+ //#endregion
143
+ //#region src/core/types.d.ts
144
+ /**
145
+ * Any zod schema. Aliased to zod's `ZodType` (no generics) — non-deprecated
146
+ * in both v3 and v4. Use this when you need to type an individual schema;
147
+ * for the `{ text: z.string() }` shape passed to `defineTool`'s
148
+ * `inputSchema`, use `ZodRawShape`.
149
+ */
150
+ type ZodSchema = ZodType;
151
+ /**
152
+ * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
+ * `defineTool`'s `inputSchema`/`outputSchema` expects.
154
+ */
155
+ type ZodRawShape$1 = ZodRawShape;
156
+ /**
157
+ * Infer the parsed-output type of a zod raw shape — given
158
+ * `{ text: ZodString, n: ZodNumber }`, produces `{ text: string, n: number }`.
159
+ */
160
+ type ShapeOutput<Shape extends ZodRawShape$1> = { [K in keyof Shape]: Shape[K] extends ZodType ? TypeOf<Shape[K]> : unknown; };
161
+ /**
162
+ * Per-content-block metadata. Distinct from `ToolAnnotations`, which
163
+ * decorates the tool as a whole — these decorate a single piece of
164
+ * content (an image, a text block, etc.) within the tool's result.
165
+ */
166
+ interface ContentAnnotations {
167
+ /** Which side of the conversation the content is addressed at. */
168
+ audience?: ("user" | "assistant")[];
169
+ /** Higher = more important. Used by clients that summarise content. */
170
+ priority?: number;
171
+ /** ISO 8601 timestamp. */
172
+ lastModified?: string;
173
+ }
174
+ interface ContentBlockBase {
175
+ annotations?: ContentAnnotations;
176
+ _meta?: Record<string, unknown>;
177
+ }
178
+ interface TextContent extends ContentBlockBase {
179
+ type: "text";
180
+ text: string;
181
+ }
182
+ interface ImageContent extends ContentBlockBase {
183
+ type: "image";
184
+ data: string;
185
+ mimeType: string;
186
+ }
187
+ interface AudioContent extends ContentBlockBase {
188
+ type: "audio";
189
+ data: string;
190
+ mimeType: string;
191
+ }
192
+ interface EmbeddedTextResource extends ContentBlockBase {
193
+ type: "resource";
194
+ resource: {
195
+ uri: string;
196
+ mimeType?: string;
197
+ text: string;
198
+ _meta?: Record<string, unknown>;
199
+ };
200
+ }
201
+ interface EmbeddedBlobResource extends ContentBlockBase {
202
+ type: "resource";
203
+ resource: {
204
+ uri: string;
205
+ mimeType?: string;
206
+ blob: string;
207
+ _meta?: Record<string, unknown>;
208
+ };
209
+ }
210
+ type EmbeddedResource = EmbeddedTextResource | EmbeddedBlobResource;
211
+ /**
212
+ * Optional icon entry on `ResourceLink`. Clients that display a resource
213
+ * with a glyph (file browsers, side panels, etc.) pick the best match by
214
+ * MIME type, `sizes`, and the active `theme`. All fields besides `src`
215
+ * are optional — `src` is typically a `file://`, `data:`, or `https:` URI.
216
+ */
217
+ interface ResourceLinkIcon {
218
+ src: string;
219
+ mimeType?: string;
220
+ /** Space-separated dimension string, HTML `<link sizes>` convention (e.g. `"16x16 32x32"`). */
221
+ sizes?: string;
222
+ theme?: "light" | "dark";
223
+ }
224
+ interface ResourceLink extends ContentBlockBase {
225
+ type: "resource_link";
226
+ uri: string;
227
+ name: string;
228
+ title?: string;
229
+ description?: string;
230
+ mimeType?: string;
231
+ icons?: ResourceLinkIcon[];
232
+ }
233
+ /**
234
+ * A single content block in a tool result. Matches the MCP wire format
235
+ * for `tools/call` responses (`type: "text" | "image" | "audio" |
236
+ * "resource" | "resource_link"`).
237
+ */
238
+ type ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResource | ResourceLink;
239
+ /**
240
+ * The shape of `ToolHandlerResult.content` — an array of content blocks
241
+ * the tool returns to the caller.
242
+ */
243
+ type ToolContent = ContentBlock[];
244
+ /**
245
+ * Per-tool client hints (not enforcement). `annotations.title` is
246
+ * intentionally omitted — use `ToolDefinition.title`, which the MCP
247
+ * 2025-06-18+ spec promoted to top-level.
248
+ */
249
+ interface ToolAnnotations {
250
+ /** Tool does not modify state. */
251
+ readOnlyHint?: boolean;
252
+ /** Tool may make irreversible changes. Only meaningful when readOnlyHint is false. */
253
+ destructiveHint?: boolean;
254
+ /** Calling N times has the same effect as calling once. */
255
+ idempotentHint?: boolean;
256
+ /** Tool interacts with external/unbounded systems (DB, network, third-party APIs). */
257
+ openWorldHint?: boolean;
258
+ }
259
+ interface ToolHandlerResult {
260
+ content?: ToolContent;
261
+ structuredContent?: Record<string, unknown>;
262
+ isError?: boolean;
263
+ }
264
+ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined> {
265
+ readonly name: string;
266
+ /** Human-readable display name shown to the user in MCP clients. Required. */
267
+ readonly title: string;
268
+ /** Prose read by the LLM to decide whether to call this tool. Required. */
269
+ readonly description: string;
270
+ readonly inputSchema?: TInput;
271
+ readonly outputSchema?: TOutput;
272
+ readonly annotations?: ToolAnnotations;
273
+ readonly handler: TInput extends ZodRawShape$1 ? (args: ShapeOutput<TInput>, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult> : (args: Record<string, never> | undefined, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
274
+ }
275
+ /**
276
+ * Type-erased element of `McpDefinition.tools`. Per-tool generic typing
277
+ * happens at the `defineTool` call site; see README §6 for the rationale.
278
+ */
279
+ interface AnyToolDefinition {
280
+ readonly name: string;
281
+ readonly title: string;
282
+ readonly description: string;
283
+ readonly inputSchema?: ZodRawShape$1;
284
+ readonly outputSchema?: ZodRawShape$1;
285
+ readonly annotations?: ToolAnnotations;
286
+ readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
287
+ }
288
+ /**
289
+ * Fields a caller supplies when constructing an MCP definition. Pass this
290
+ * shape to `defineMcp(...)` — its return type is the branded `McpDefinition`,
291
+ * which is the type every internal factory (`createInvokeToolHandler`,
292
+ * `createMcpProtocolHandler`, …) consumes. The brand forces consumers
293
+ * through `defineMcp`'s `assertUniqueNames` + freeze.
294
+ */
295
+ interface McpDefinitionInput {
296
+ readonly name: string;
297
+ /** Human-readable display name shown to MCP clients. Required. */
298
+ readonly title: string;
299
+ readonly version: string;
300
+ readonly auth?: McpAuthConfig;
301
+ /**
302
+ * Server-level prose the LLM reads as context for all tools on this server.
303
+ * Required for the same reason `ToolDefinition.description` is — optional
304
+ * fields encourage drift in production agent behavior. Pass an explicit
305
+ * empty string to opt out.
306
+ */
307
+ readonly instructions: string;
308
+ readonly tools: readonly AnyToolDefinition[];
309
+ /**
310
+ * Usage-metrics emission (runtime telemetry), on by default. `false` opts out;
311
+ * `{ endpoint, headers }` sends to your own OTLP collector. Self-disables at
312
+ * runtime without `LOVABLE_API_KEY` on the default Lovable endpoint.
313
+ */
314
+ readonly metrics?: MetricsConfig;
315
+ }
316
+ declare const McpDefinitionBrand: unique symbol;
317
+ type McpDefinition = McpDefinitionInput & {
318
+ readonly [McpDefinitionBrand]: never;
319
+ };
320
+ //#endregion
321
+ export { McpAuthConfig as C, JwtClaims as S, ZodRawShape$1 as _, EmbeddedResource as a, MetricsOptions as b, McpDefinition as c, ResourceLinkIcon as d, TextContent as f, ToolHandlerResult as g, ToolDefinition as h, EmbeddedBlobResource as i, McpDefinitionInput as l, ToolContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ToolAnnotations as p, ContentBlock as r, ImageContent as s, AudioContent as t, ResourceLink as u, ZodSchema as v, ToolContext as x, MetricsConfig as y };
@@ -0,0 +1,321 @@
1
+ import { TypeOf, ZodRawShape, ZodType } from "zod";
2
+ //#region src/auth/types.d.ts
3
+ type JwtClaims = Record<string, unknown> & {
4
+ iss?: string;
5
+ sub?: string;
6
+ aud?: string | string[];
7
+ exp?: number;
8
+ iat?: number;
9
+ nbf?: number;
10
+ scope?: string;
11
+ client_id?: string;
12
+ email?: string;
13
+ /** RFC 8707 resource indicator(s) the token was granted for (Lovable OAuth convention). */
14
+ resource?: string | string[];
15
+ };
16
+ /**
17
+ * The safe-to-surface half of the auth context, reachable by tools only through
18
+ * `ToolContext` accessors (`getUserId()`, `getClaims()`, …). Carries no
19
+ * credential — the bearer is isolated in `OAuthBearer`.
20
+ */
21
+ interface OAuthPrincipal {
22
+ claims: JwtClaims;
23
+ issuer: string;
24
+ resource: string;
25
+ acceptedAudiences: readonly string[];
26
+ scopes: string[];
27
+ sub?: string;
28
+ email?: string;
29
+ clientId?: string;
30
+ }
31
+ /**
32
+ * The raw bearer, isolated from the safe fields. Pass it only into outbound
33
+ * `fetch`/client construction; never return or log it — a leaked token stays
34
+ * valid at the AS until it expires. `token` is a non-enumerable property, so
35
+ * `JSON.stringify`, object spread, and `console.log` omit it by construction.
36
+ */
37
+ interface OAuthBearer {
38
+ readonly token: string;
39
+ }
40
+ interface McpAuthContext {
41
+ type: "oauth";
42
+ principal: OAuthPrincipal;
43
+ bearer: OAuthBearer;
44
+ }
45
+ interface McpAuthConfig {
46
+ readonly type: "oauth";
47
+ readonly issuer: string;
48
+ readonly resource?: string;
49
+ readonly resourceName?: string;
50
+ readonly resourceDocumentation?: string;
51
+ /**
52
+ * Absolute URL of an externally hosted RFC 9728 protected-resource metadata
53
+ * document. When set, the SDK advertises this URL in the 401
54
+ * `WWW-Authenticate: resource_metadata` challenge and does not generate or
55
+ * serve its own metadata (the `/.well-known/oauth-protected-resource` handler
56
+ * 404s). Use it when the resource server already publishes its own PRM.
57
+ *
58
+ * Mutually exclusive with the Vite plugin's `metadataPath`: that option has
59
+ * the SDK serve the document itself at a custom path, so configuring both is
60
+ * rejected at handler construction.
61
+ */
62
+ readonly protectedResourceMetadataUrl?: string;
63
+ readonly requireOAuthClientClaim?: boolean;
64
+ readonly acceptedAudiences?: readonly string[];
65
+ /**
66
+ * Accept a token whose RFC 8707 `resource` claim matches an accepted
67
+ * audience (trailing slashes ignored) when its `aud` is an empty array or
68
+ * absent — the shape Lovable's OAuth server mints; applies to any configured
69
+ * issuer. A populated `aud` is always authoritative and is never overridden.
70
+ * Defaults to true. Set false to require a matching `aud` (strict RFC 9068).
71
+ */
72
+ readonly acceptResourceClaim?: boolean;
73
+ readonly requiredScopes?: readonly string[];
74
+ readonly jwksUri?: string;
75
+ readonly algorithms?: readonly string[];
76
+ readonly clockToleranceSeconds?: number;
77
+ /**
78
+ * Allowed values for the access token's JOSE `typ` header. Defaults to
79
+ * `["at+jwt", "JWT"]` so both the RFC 9068 access-token shape and the plain
80
+ * user-JWT shape (notably Supabase GoTrue's OAuth tokens) are accepted out of
81
+ * the box. Pin to `["at+jwt"]` to enforce strict RFC 9068. The header `typ`
82
+ * must be present and string-typed; this option only controls which values pass.
83
+ */
84
+ readonly accessTokenTyp?: readonly string[];
85
+ }
86
+ //#endregion
87
+ //#region src/auth/context.d.ts
88
+ /**
89
+ * The auth surface passed to every tool handler as its second argument. It wraps
90
+ * the verified per-request auth context in a private field, so the context — and
91
+ * the bearer token inside it — can't be read, enumerated, spread, or
92
+ * `JSON.stringify`'d off the instance; the accessors below are the only way out.
93
+ * `getToken()` is the single intentional escape hatch for the raw bearer.
94
+ */
95
+ declare class ToolContext {
96
+ #private;
97
+ constructor(auth: McpAuthContext | undefined);
98
+ /** Whether the in-flight tool call carries a verified auth context. */
99
+ isAuthenticated(): boolean;
100
+ /** The verified bearer token, or `undefined` when unauthenticated. Pass it to downstream APIs; never return or log it. */
101
+ getToken(): string | undefined;
102
+ /** The verified user id (the token `sub`), or `undefined`. */
103
+ getUserId(): string | undefined;
104
+ /** The verified user email, or `undefined` when absent. */
105
+ getUserEmail(): string | undefined;
106
+ /** The verified OAuth `client_id`, or `undefined`. */
107
+ getClientId(): string | undefined;
108
+ /** The verified OAuth scopes, or `undefined` when unauthenticated. */
109
+ getScopes(): string[] | undefined;
110
+ /** The verified token issuer, or `undefined`. */
111
+ getIssuer(): string | undefined;
112
+ /**
113
+ * The full verified JWT claims, or `undefined`. Use this for app/business
114
+ * authorization on issuer-specific claims that have no dedicated accessor.
115
+ */
116
+ getClaims(): JwtClaims | undefined;
117
+ }
118
+ //#endregion
119
+ //#region src/metrics/config.d.ts
120
+ /**
121
+ * Usage-metrics options. Pass a boolean to the Vite plugins for the common
122
+ * on/off case, or this object to override the ingest endpoint (e.g. to
123
+ * self-host the collector outside Lovable).
124
+ */
125
+ interface MetricsOptions {
126
+ /** Master switch. Default `true`; metrics still self-disable at runtime when
127
+ * the API key env var is absent. */
128
+ enabled?: boolean;
129
+ /** OTLP/HTTP (JSON) logs URL to POST each invocation to — the default Lovable
130
+ * route or any OTLP collector. Must be an absolute http(s) URL.
131
+ * @default "https://api.lovable.dev/v1/app-mcp-usage" */
132
+ endpoint?: string;
133
+ /** Extra request headers — e.g. the auth token for a private OTLP collector.
134
+ * Sent verbatim with every request (and baked into the build output, so source
135
+ * your own build-time env for secrets). Ignored for the default Lovable
136
+ * endpoint, which authenticates with `LOVABLE_API_KEY` instead. `content-type`
137
+ * cannot be overridden (OTLP/HTTP JSON requires `application/json`). */
138
+ headers?: Record<string, string>;
139
+ }
140
+ /** Either the bare on/off toggle or the full options object. */
141
+ type MetricsConfig = boolean | MetricsOptions;
142
+ //#endregion
143
+ //#region src/core/types.d.ts
144
+ /**
145
+ * Any zod schema. Aliased to zod's `ZodType` (no generics) — non-deprecated
146
+ * in both v3 and v4. Use this when you need to type an individual schema;
147
+ * for the `{ text: z.string() }` shape passed to `defineTool`'s
148
+ * `inputSchema`, use `ZodRawShape`.
149
+ */
150
+ type ZodSchema = ZodType;
151
+ /**
152
+ * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
+ * `defineTool`'s `inputSchema`/`outputSchema` expects.
154
+ */
155
+ type ZodRawShape$1 = ZodRawShape;
156
+ /**
157
+ * Infer the parsed-output type of a zod raw shape — given
158
+ * `{ text: ZodString, n: ZodNumber }`, produces `{ text: string, n: number }`.
159
+ */
160
+ type ShapeOutput<Shape extends ZodRawShape$1> = { [K in keyof Shape]: Shape[K] extends ZodType ? TypeOf<Shape[K]> : unknown; };
161
+ /**
162
+ * Per-content-block metadata. Distinct from `ToolAnnotations`, which
163
+ * decorates the tool as a whole — these decorate a single piece of
164
+ * content (an image, a text block, etc.) within the tool's result.
165
+ */
166
+ interface ContentAnnotations {
167
+ /** Which side of the conversation the content is addressed at. */
168
+ audience?: ("user" | "assistant")[];
169
+ /** Higher = more important. Used by clients that summarise content. */
170
+ priority?: number;
171
+ /** ISO 8601 timestamp. */
172
+ lastModified?: string;
173
+ }
174
+ interface ContentBlockBase {
175
+ annotations?: ContentAnnotations;
176
+ _meta?: Record<string, unknown>;
177
+ }
178
+ interface TextContent extends ContentBlockBase {
179
+ type: "text";
180
+ text: string;
181
+ }
182
+ interface ImageContent extends ContentBlockBase {
183
+ type: "image";
184
+ data: string;
185
+ mimeType: string;
186
+ }
187
+ interface AudioContent extends ContentBlockBase {
188
+ type: "audio";
189
+ data: string;
190
+ mimeType: string;
191
+ }
192
+ interface EmbeddedTextResource extends ContentBlockBase {
193
+ type: "resource";
194
+ resource: {
195
+ uri: string;
196
+ mimeType?: string;
197
+ text: string;
198
+ _meta?: Record<string, unknown>;
199
+ };
200
+ }
201
+ interface EmbeddedBlobResource extends ContentBlockBase {
202
+ type: "resource";
203
+ resource: {
204
+ uri: string;
205
+ mimeType?: string;
206
+ blob: string;
207
+ _meta?: Record<string, unknown>;
208
+ };
209
+ }
210
+ type EmbeddedResource = EmbeddedTextResource | EmbeddedBlobResource;
211
+ /**
212
+ * Optional icon entry on `ResourceLink`. Clients that display a resource
213
+ * with a glyph (file browsers, side panels, etc.) pick the best match by
214
+ * MIME type, `sizes`, and the active `theme`. All fields besides `src`
215
+ * are optional — `src` is typically a `file://`, `data:`, or `https:` URI.
216
+ */
217
+ interface ResourceLinkIcon {
218
+ src: string;
219
+ mimeType?: string;
220
+ /** Space-separated dimension string, HTML `<link sizes>` convention (e.g. `"16x16 32x32"`). */
221
+ sizes?: string;
222
+ theme?: "light" | "dark";
223
+ }
224
+ interface ResourceLink extends ContentBlockBase {
225
+ type: "resource_link";
226
+ uri: string;
227
+ name: string;
228
+ title?: string;
229
+ description?: string;
230
+ mimeType?: string;
231
+ icons?: ResourceLinkIcon[];
232
+ }
233
+ /**
234
+ * A single content block in a tool result. Matches the MCP wire format
235
+ * for `tools/call` responses (`type: "text" | "image" | "audio" |
236
+ * "resource" | "resource_link"`).
237
+ */
238
+ type ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResource | ResourceLink;
239
+ /**
240
+ * The shape of `ToolHandlerResult.content` — an array of content blocks
241
+ * the tool returns to the caller.
242
+ */
243
+ type ToolContent = ContentBlock[];
244
+ /**
245
+ * Per-tool client hints (not enforcement). `annotations.title` is
246
+ * intentionally omitted — use `ToolDefinition.title`, which the MCP
247
+ * 2025-06-18+ spec promoted to top-level.
248
+ */
249
+ interface ToolAnnotations {
250
+ /** Tool does not modify state. */
251
+ readOnlyHint?: boolean;
252
+ /** Tool may make irreversible changes. Only meaningful when readOnlyHint is false. */
253
+ destructiveHint?: boolean;
254
+ /** Calling N times has the same effect as calling once. */
255
+ idempotentHint?: boolean;
256
+ /** Tool interacts with external/unbounded systems (DB, network, third-party APIs). */
257
+ openWorldHint?: boolean;
258
+ }
259
+ interface ToolHandlerResult {
260
+ content?: ToolContent;
261
+ structuredContent?: Record<string, unknown>;
262
+ isError?: boolean;
263
+ }
264
+ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined> {
265
+ readonly name: string;
266
+ /** Human-readable display name shown to the user in MCP clients. Required. */
267
+ readonly title: string;
268
+ /** Prose read by the LLM to decide whether to call this tool. Required. */
269
+ readonly description: string;
270
+ readonly inputSchema?: TInput;
271
+ readonly outputSchema?: TOutput;
272
+ readonly annotations?: ToolAnnotations;
273
+ readonly handler: TInput extends ZodRawShape$1 ? (args: ShapeOutput<TInput>, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult> : (args: Record<string, never> | undefined, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
274
+ }
275
+ /**
276
+ * Type-erased element of `McpDefinition.tools`. Per-tool generic typing
277
+ * happens at the `defineTool` call site; see README §6 for the rationale.
278
+ */
279
+ interface AnyToolDefinition {
280
+ readonly name: string;
281
+ readonly title: string;
282
+ readonly description: string;
283
+ readonly inputSchema?: ZodRawShape$1;
284
+ readonly outputSchema?: ZodRawShape$1;
285
+ readonly annotations?: ToolAnnotations;
286
+ readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
287
+ }
288
+ /**
289
+ * Fields a caller supplies when constructing an MCP definition. Pass this
290
+ * shape to `defineMcp(...)` — its return type is the branded `McpDefinition`,
291
+ * which is the type every internal factory (`createInvokeToolHandler`,
292
+ * `createMcpProtocolHandler`, …) consumes. The brand forces consumers
293
+ * through `defineMcp`'s `assertUniqueNames` + freeze.
294
+ */
295
+ interface McpDefinitionInput {
296
+ readonly name: string;
297
+ /** Human-readable display name shown to MCP clients. Required. */
298
+ readonly title: string;
299
+ readonly version: string;
300
+ readonly auth?: McpAuthConfig;
301
+ /**
302
+ * Server-level prose the LLM reads as context for all tools on this server.
303
+ * Required for the same reason `ToolDefinition.description` is — optional
304
+ * fields encourage drift in production agent behavior. Pass an explicit
305
+ * empty string to opt out.
306
+ */
307
+ readonly instructions: string;
308
+ readonly tools: readonly AnyToolDefinition[];
309
+ /**
310
+ * Usage-metrics emission (runtime telemetry), on by default. `false` opts out;
311
+ * `{ endpoint, headers }` sends to your own OTLP collector. Self-disables at
312
+ * runtime without `LOVABLE_API_KEY` on the default Lovable endpoint.
313
+ */
314
+ readonly metrics?: MetricsConfig;
315
+ }
316
+ declare const McpDefinitionBrand: unique symbol;
317
+ type McpDefinition = McpDefinitionInput & {
318
+ readonly [McpDefinitionBrand]: never;
319
+ };
320
+ //#endregion
321
+ export { McpAuthConfig as C, JwtClaims as S, ZodRawShape$1 as _, EmbeddedResource as a, MetricsOptions as b, McpDefinition as c, ResourceLinkIcon as d, TextContent as f, ToolHandlerResult as g, ToolDefinition as h, EmbeddedBlobResource as i, McpDefinitionInput as l, ToolContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ToolAnnotations as p, ContentBlock as r, ImageContent as s, AudioContent as t, ResourceLink as u, ZodSchema as v, ToolContext as x, MetricsConfig as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/mcp-js",
3
- "version": "0.22.1",
3
+ "version": "0.22.2-rc.0",
4
4
  "description": "Author MCP servers for Lovable apps. Declare tools with defineTool, register them in defineMcp, and a framework adapter (TanStack or Supabase Edge Functions) emits the route(s) at build time.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -126,16 +126,16 @@
126
126
  "devDependencies": {
127
127
  "@types/node": "22.13.13",
128
128
  "rimraf": "^5.0.0",
129
- "tsup": "^7.2.0",
129
+ "tsdown": "^0.22.5",
130
130
  "typescript": "^5.9.3",
131
131
  "vite": "^7.3.1",
132
132
  "vitest": "^4.1.5",
133
133
  "zod": "^4.1.13"
134
134
  },
135
135
  "scripts": {
136
- "build": "tsup src/index.ts src/protocols/mcp/index.ts src/protocols/oauth-metadata.ts src/protocols/rest/index.ts src/stacks/tanstack/index.ts src/stacks/tanstack/vite.ts src/stacks/supabase/index.ts src/stacks/supabase/vite.ts src/cli/extract-manifest.ts --format cjs,esm --dts --outDir dist",
136
+ "build": "tsdown",
137
137
  "check:package": "tmp=$(mktemp -d) && pnpm pack --out \"$tmp/pkg.tgz\" && tar -xzf \"$tmp/pkg.tgz\" -C \"$tmp\" && publint \"$tmp/package\" --strict && attw \"$tmp/pkg.tgz\"",
138
- "dev": "tsup src/index.ts src/protocols/mcp/index.ts src/protocols/oauth-metadata.ts src/protocols/rest/index.ts src/stacks/tanstack/index.ts src/stacks/tanstack/vite.ts src/stacks/supabase/index.ts src/stacks/supabase/vite.ts src/cli/extract-manifest.ts --format cjs,esm --dts --watch",
138
+ "dev": "tsdown --watch",
139
139
  "typecheck": "tsgo --noEmit",
140
140
  "format": "oxfmt --write src/ tests/",
141
141
  "format:check": "oxfmt --check src/ tests/",