@lovable.dev/mcp-js 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QC3DXQTH.js → chunk-DCWYK4CA.js} +34 -0
- package/dist/{chunk-RHDEW56Y.js → chunk-EZQVUNXB.js} +20 -11
- package/dist/{chunk-G4XA7IJM.js → chunk-H6BKTNJY.js} +199 -2
- package/dist/{chunk-VNRQPA4K.js → chunk-I5CAQUQI.js} +4 -3
- package/dist/{chunk-P3F324UC.js → chunk-MA5H6PSF.js} +0 -34
- package/dist/{chunk-LWHVXXKQ.js → chunk-SKSKC747.js} +1 -1
- package/dist/{chunk-QDKOF4UF.js → chunk-T24Z753F.js} +2 -2
- package/dist/{chunk-T2RED2TG.js → chunk-W2EZWPJ5.js} +19 -10
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +4 -4
- package/dist/index.js +4 -4
- package/dist/protocols/mcp/index.cjs +239 -213
- package/dist/protocols/mcp/index.d.cts +1 -1
- package/dist/protocols/mcp/index.d.ts +1 -1
- package/dist/protocols/mcp/index.js +5 -6
- package/dist/protocols/oauth-metadata.js +4 -3
- package/dist/protocols/rest/index.cjs +241 -215
- package/dist/protocols/rest/index.d.cts +2 -2
- package/dist/protocols/rest/index.d.ts +2 -2
- package/dist/protocols/rest/index.js +6 -7
- package/dist/{recorder-B-eJU4Qu.d.ts → recorder-qlzUKFxG.d.ts} +3 -3
- package/dist/stacks/supabase/index.cjs +55 -19
- package/dist/stacks/supabase/index.js +10 -12
- package/dist/stacks/supabase/vite.cjs +28 -4
- package/dist/stacks/supabase/vite.js +28 -4
- package/dist/stacks/tanstack/index.cjs +255 -219
- package/dist/stacks/tanstack/index.js +8 -9
- package/package.json +1 -1
- package/dist/chunk-XQSTN54Y.js +0 -189
package/dist/chunk-XQSTN54Y.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_METRICS_ENDPOINT,
|
|
3
|
-
resolveMetricsConfig
|
|
4
|
-
} from "./chunk-P3F324UC.js";
|
|
5
|
-
import {
|
|
6
|
-
describeError,
|
|
7
|
-
log
|
|
8
|
-
} from "./chunk-QC3DXQTH.js";
|
|
9
|
-
import {
|
|
10
|
-
version
|
|
11
|
-
} from "./chunk-LWHVXXKQ.js";
|
|
12
|
-
|
|
13
|
-
// src/metrics/otlp.ts
|
|
14
|
-
var SCOPE_NAME = "@lovable.dev/mcp-js";
|
|
15
|
-
var EVENT_NAME = "mcp.tool.invocation";
|
|
16
|
-
var SEVERITY_INFO = 9;
|
|
17
|
-
function strAttr(key, value) {
|
|
18
|
-
return { key, value: { stringValue: value } };
|
|
19
|
-
}
|
|
20
|
-
function intAttr(key, value) {
|
|
21
|
-
return { key, value: { intValue: String(Math.round(value)) } };
|
|
22
|
-
}
|
|
23
|
-
function toLogRecord(rec) {
|
|
24
|
-
const attributes = [
|
|
25
|
-
strAttr("event.name", EVENT_NAME),
|
|
26
|
-
strAttr("mcp.method", rec.method),
|
|
27
|
-
strAttr("mcp.outcome", rec.outcome),
|
|
28
|
-
intAttr("mcp.duration_ms", rec.durationMs)
|
|
29
|
-
];
|
|
30
|
-
if (rec.tool !== null)
|
|
31
|
-
attributes.push(strAttr("mcp.tool", rec.tool));
|
|
32
|
-
if (rec.reqBytes !== void 0)
|
|
33
|
-
attributes.push(intAttr("mcp.request_size_bytes", rec.reqBytes));
|
|
34
|
-
if (rec.resBytes !== void 0)
|
|
35
|
-
attributes.push(intAttr("mcp.response_size_bytes", rec.resBytes));
|
|
36
|
-
return {
|
|
37
|
-
timeUnixNano: rec.timeUnixNano,
|
|
38
|
-
observedTimeUnixNano: rec.timeUnixNano,
|
|
39
|
-
severityNumber: SEVERITY_INFO,
|
|
40
|
-
severityText: "INFO",
|
|
41
|
-
body: { stringValue: EVENT_NAME },
|
|
42
|
-
attributes
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function buildLogsPayload(records, server) {
|
|
46
|
-
return JSON.stringify({
|
|
47
|
-
resourceLogs: [
|
|
48
|
-
{
|
|
49
|
-
resource: {
|
|
50
|
-
attributes: [
|
|
51
|
-
strAttr("service.name", server.name),
|
|
52
|
-
strAttr("service.version", server.version),
|
|
53
|
-
strAttr("telemetry.sdk.name", SCOPE_NAME),
|
|
54
|
-
strAttr("telemetry.sdk.version", version),
|
|
55
|
-
strAttr("telemetry.sdk.language", "webjs")
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
scopeLogs: [
|
|
59
|
-
{
|
|
60
|
-
scope: { name: SCOPE_NAME, version },
|
|
61
|
-
logRecords: records.map(toLogRecord)
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function nowUnixNano() {
|
|
69
|
-
return `${Date.now()}000000`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// src/metrics/recorder.ts
|
|
73
|
-
function nowMs() {
|
|
74
|
-
return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
75
|
-
}
|
|
76
|
-
var NOOP_RECORDER = {
|
|
77
|
-
record() {
|
|
78
|
-
},
|
|
79
|
-
async flush() {
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
function createNoopRecorder() {
|
|
83
|
-
return NOOP_RECORDER;
|
|
84
|
-
}
|
|
85
|
-
function readRuntimeEnv(name) {
|
|
86
|
-
try {
|
|
87
|
-
const denoEnv = globalThis.Deno?.env;
|
|
88
|
-
const value = denoEnv?.get?.(name);
|
|
89
|
-
if (value)
|
|
90
|
-
return value;
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
if (typeof process !== "undefined") {
|
|
95
|
-
const value = process.env?.[name];
|
|
96
|
-
if (value)
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
} catch {
|
|
100
|
-
}
|
|
101
|
-
return void 0;
|
|
102
|
-
}
|
|
103
|
-
function probeWaitUntil() {
|
|
104
|
-
const fn = globalThis.EdgeRuntime?.waitUntil;
|
|
105
|
-
return typeof fn === "function" ? fn.bind(globalThis.EdgeRuntime) : void 0;
|
|
106
|
-
}
|
|
107
|
-
function createMetricsRecorder(ctx, deps = {}) {
|
|
108
|
-
const { config, server } = ctx;
|
|
109
|
-
if (!config.enabled)
|
|
110
|
-
return NOOP_RECORDER;
|
|
111
|
-
const doFetch = deps.fetch ?? globalThis.fetch;
|
|
112
|
-
if (!doFetch)
|
|
113
|
-
return NOOP_RECORDER;
|
|
114
|
-
const usesLovableEndpoint = config.endpoint === DEFAULT_METRICS_ENDPOINT;
|
|
115
|
-
const apiKey = usesLovableEndpoint ? (deps.getApiKey ?? (() => readRuntimeEnv(config.apiKeyEnvVar)))() : void 0;
|
|
116
|
-
if (usesLovableEndpoint && !apiKey) {
|
|
117
|
-
log.debug("metrics.disabled_no_api_key", { envVar: config.apiKeyEnvVar });
|
|
118
|
-
return NOOP_RECORDER;
|
|
119
|
-
}
|
|
120
|
-
const waitUntil = deps.waitUntil ?? probeWaitUntil();
|
|
121
|
-
const buffer = [];
|
|
122
|
-
let timer;
|
|
123
|
-
const schedule = (p) => {
|
|
124
|
-
if (waitUntil) {
|
|
125
|
-
try {
|
|
126
|
-
waitUntil(p);
|
|
127
|
-
return;
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
void p.catch(() => {
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
const headers = {};
|
|
135
|
-
if (!usesLovableEndpoint) {
|
|
136
|
-
for (const [key, value] of Object.entries(config.headers)) {
|
|
137
|
-
if (key.toLowerCase() !== "content-type")
|
|
138
|
-
headers[key] = value;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
headers["content-type"] = "application/json";
|
|
142
|
-
if (apiKey)
|
|
143
|
-
headers.authorization = `Bearer ${apiKey}`;
|
|
144
|
-
const flush = async () => {
|
|
145
|
-
if (buffer.length === 0)
|
|
146
|
-
return;
|
|
147
|
-
const records = buffer.splice(0, buffer.length);
|
|
148
|
-
try {
|
|
149
|
-
const res = await doFetch(config.endpoint, {
|
|
150
|
-
method: "POST",
|
|
151
|
-
headers,
|
|
152
|
-
body: buildLogsPayload(records, server),
|
|
153
|
-
keepalive: true
|
|
154
|
-
});
|
|
155
|
-
if (!res.ok)
|
|
156
|
-
log.debug("metrics.flush_rejected", { status: res.status });
|
|
157
|
-
} catch (err) {
|
|
158
|
-
log.debug("metrics.flush_failed", describeError(err));
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const ensureTimer = () => {
|
|
162
|
-
if (timer !== void 0)
|
|
163
|
-
return;
|
|
164
|
-
timer = setInterval(() => schedule(flush()), config.flushIntervalMs);
|
|
165
|
-
timer.unref?.();
|
|
166
|
-
};
|
|
167
|
-
return {
|
|
168
|
-
record(ev) {
|
|
169
|
-
if (config.sampleRate < 1 && Math.random() >= config.sampleRate)
|
|
170
|
-
return;
|
|
171
|
-
buffer.push({ ...ev, timeUnixNano: nowUnixNano() });
|
|
172
|
-
ensureTimer();
|
|
173
|
-
if (buffer.length >= config.maxBatchSize)
|
|
174
|
-
schedule(flush());
|
|
175
|
-
},
|
|
176
|
-
flush
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function createRecorderForRuntime(mcp) {
|
|
180
|
-
const config = resolveMetricsConfig(mcp.metrics);
|
|
181
|
-
if (!config.enabled)
|
|
182
|
-
return createNoopRecorder();
|
|
183
|
-
return createMetricsRecorder({ config, server: { name: mcp.name, version: mcp.version } });
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export {
|
|
187
|
-
nowMs,
|
|
188
|
-
createRecorderForRuntime
|
|
189
|
-
};
|