@kometolabs/mcp-analytics-receiver 0.0.0-stage → 0.1.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/Dockerfile +47 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +344 -2
- package/dist/admin.d.ts +17 -0
- package/dist/admin.js +264 -0
- package/dist/admin.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +199 -0
- package/dist/cli.js.map +1 -0
- package/dist/deploy/compose.yaml +121 -0
- package/dist/deploy/grafana/bootstrap-viewer.mjs +216 -0
- package/dist/deploy/grafana/dashboards/overview.json +1108 -0
- package/dist/deploy/grafana/provisioning/dashboards/overview.yaml +12 -0
- package/dist/deploy/grafana/provisioning/datasources/postgres.yaml +22 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +13 -0
- package/dist/http.js +127 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +44 -0
- package/dist/init.js +198 -0
- package/dist/init.js.map +1 -0
- package/dist/postgres.d.ts +21 -0
- package/dist/postgres.js +110 -0
- package/dist/postgres.js.map +1 -0
- package/dist/rejections.d.ts +13 -0
- package/dist/rejections.js +59 -0
- package/dist/rejections.js.map +1 -0
- package/dist/schema.d.ts +44 -0
- package/dist/schema.js +88 -0
- package/dist/schema.js.map +1 -0
- package/dist/sql/001-schema.sql +285 -0
- package/dist/sql/002-roles.sql +26 -0
- package/package.json +70 -3
package/dist/init.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { chmod, copyFile, mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
/** Shown to the operator as is; never contains generated secrets. */
|
|
6
|
+
export class InitError extends Error {
|
|
7
|
+
constructor(message) { super(message); this.name = 'InitError'; }
|
|
8
|
+
}
|
|
9
|
+
const SLUG = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;
|
|
10
|
+
const DEPLOY = fileURLToPath(new URL('./deploy/', import.meta.url));
|
|
11
|
+
const TEMPLATE_FILES = [
|
|
12
|
+
'compose.yaml',
|
|
13
|
+
'grafana/bootstrap-viewer.mjs',
|
|
14
|
+
'grafana/dashboards/overview.json',
|
|
15
|
+
'grafana/provisioning/dashboards/overview.yaml',
|
|
16
|
+
'grafana/provisioning/datasources/postgres.yaml',
|
|
17
|
+
];
|
|
18
|
+
async function version() {
|
|
19
|
+
const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
20
|
+
return manifest.version;
|
|
21
|
+
}
|
|
22
|
+
function slugFrom(name) {
|
|
23
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9_.-]+/g, '-').replace(/^[^a-z0-9_]+/, '').slice(0, 64).replace(/[-.]+$/, '');
|
|
24
|
+
return slug.length > 0 ? slug : 'default';
|
|
25
|
+
}
|
|
26
|
+
function publicUrlFrom(value) {
|
|
27
|
+
let url;
|
|
28
|
+
try {
|
|
29
|
+
url = new URL(value);
|
|
30
|
+
}
|
|
31
|
+
catch { /* reported below */ }
|
|
32
|
+
if (!url || !['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
|
|
33
|
+
throw new InitError('--public-url must be an http or https URL without credentials, query, or fragment');
|
|
34
|
+
}
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
async function exists(file) {
|
|
38
|
+
try {
|
|
39
|
+
await stat(file);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Reads KEY=value lines; values are taken literally, as Compose does for unquoted values. */
|
|
47
|
+
function parseEnv(text) {
|
|
48
|
+
const values = new Map();
|
|
49
|
+
for (const line of text.split('\n')) {
|
|
50
|
+
const match = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim());
|
|
51
|
+
if (match)
|
|
52
|
+
values.set(match[1], match[2]);
|
|
53
|
+
}
|
|
54
|
+
return values;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Writes a deployment directory: compose.yaml, Grafana provisioning, and a
|
|
58
|
+
* private .env with fresh secrets. Rerunning keeps .env, so the database
|
|
59
|
+
* passwords stay valid, and leaves compose.yaml alone unless `force` is set.
|
|
60
|
+
*/
|
|
61
|
+
export async function initDeployment(options) {
|
|
62
|
+
const random = options.random ?? ((bytes) => randomBytes(bytes).toString('base64url'));
|
|
63
|
+
const now = options.now ?? (() => new Date());
|
|
64
|
+
const directory = path.resolve(options.directory);
|
|
65
|
+
if (await exists(directory) && !(await stat(directory)).isDirectory())
|
|
66
|
+
throw new InitError('The target exists and is not a directory');
|
|
67
|
+
await mkdir(directory, { recursive: true });
|
|
68
|
+
const created = [];
|
|
69
|
+
const kept = [];
|
|
70
|
+
for (const file of TEMPLATE_FILES) {
|
|
71
|
+
const target = path.join(directory, file);
|
|
72
|
+
if (!options.force && await exists(target)) {
|
|
73
|
+
kept.push(file);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
77
|
+
await copyFile(path.join(DEPLOY, file), target);
|
|
78
|
+
created.push(file);
|
|
79
|
+
}
|
|
80
|
+
const envFile = path.join(directory, '.env');
|
|
81
|
+
let settings;
|
|
82
|
+
if (await exists(envFile)) {
|
|
83
|
+
settings = parseEnv(await readFile(envFile, 'utf8'));
|
|
84
|
+
kept.push('.env');
|
|
85
|
+
for (const [option, given] of [['--project', options.project], ['--public-url', options.publicUrl], ['--image', options.image]]) {
|
|
86
|
+
if (given !== undefined)
|
|
87
|
+
throw new InitError(`.env already exists; edit it instead of passing ${option}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const project = options.project ?? slugFrom(path.basename(directory));
|
|
92
|
+
if (!SLUG.test(project))
|
|
93
|
+
throw new InitError('--project must be 1-64 letters, digits, underscores, dots, or hyphens');
|
|
94
|
+
const publicUrl = publicUrlFrom(options.publicUrl ?? 'http://localhost:4319').href.replace(/\/+$/, '');
|
|
95
|
+
const image = options.image ?? `ghcr.io/kometolabs/mcp-analytics-receiver:${await version()}`;
|
|
96
|
+
if (!/^[\w.\-/:@]+$/.test(image))
|
|
97
|
+
throw new InitError('--image must be a container image reference');
|
|
98
|
+
const lines = [
|
|
99
|
+
`# Written by mcp-analytics-receiver init on ${now().toISOString().slice(0, 10)}. Keep this file private:`,
|
|
100
|
+
'# it holds every password and key of this deployment. `docker compose` reads it.',
|
|
101
|
+
'',
|
|
102
|
+
'# The receiver image and the project it accepts.',
|
|
103
|
+
`MCP_ANALYTICS_IMAGE=${image}`,
|
|
104
|
+
`MCP_ANALYTICS_PROJECT_ID=${project}`,
|
|
105
|
+
'',
|
|
106
|
+
'# Applications send with MCP_ANALYTICS_URL=<scheme>://<write key>@<public host>/<project>.',
|
|
107
|
+
`MCP_ANALYTICS_WRITE_KEY=${random(32)}`,
|
|
108
|
+
`MCP_ANALYTICS_PUBLIC_URL=${publicUrl}`,
|
|
109
|
+
'# Customer-held: applications hash user IDs with it, and mcp-analytics-admin',
|
|
110
|
+
'# forget-subject needs it. Rotating it breaks user continuity.',
|
|
111
|
+
`MCP_ANALYTICS_IDENTITY_SECRET=${random(32)}`,
|
|
112
|
+
'',
|
|
113
|
+
'# Host interface and port. Keep 127.0.0.1 behind a reverse proxy with HTTPS.',
|
|
114
|
+
'MCP_ANALYTICS_BIND=127.0.0.1',
|
|
115
|
+
'MCP_ANALYTICS_RECEIVER_PORT=4319',
|
|
116
|
+
'GRAFANA_BIND=127.0.0.1',
|
|
117
|
+
'GRAFANA_PORT=3000',
|
|
118
|
+
'GRAFANA_PUBLIC_URL=http://localhost:3000',
|
|
119
|
+
'',
|
|
120
|
+
'# Database and Grafana credentials.',
|
|
121
|
+
`POSTGRES_PASSWORD=${random(24)}`,
|
|
122
|
+
`MCP_ANALYTICS_WRITER_PASSWORD=${random(24)}`,
|
|
123
|
+
`MCP_ANALYTICS_READER_PASSWORD=${random(24)}`,
|
|
124
|
+
`GRAFANA_ADMIN_PASSWORD=${random(24)}`,
|
|
125
|
+
'GRAFANA_VIEWER_USER=viewer',
|
|
126
|
+
`GRAFANA_VIEWER_PASSWORD=${random(24)}`,
|
|
127
|
+
'',
|
|
128
|
+
];
|
|
129
|
+
// 'wx' never replaces a .env that appeared after the check above, and
|
|
130
|
+
// never follows a broken symlink to write the secrets somewhere else.
|
|
131
|
+
try {
|
|
132
|
+
await writeFile(envFile, lines.join('\n'), { mode: 0o600, flag: 'wx' });
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code === 'EEXIST') {
|
|
136
|
+
throw new InitError('Something other than a readable .env file is at the .env path; remove it and rerun init');
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
await chmod(envFile, 0o600);
|
|
141
|
+
settings = parseEnv(lines.join('\n'));
|
|
142
|
+
created.push('.env');
|
|
143
|
+
}
|
|
144
|
+
const setting = (key) => {
|
|
145
|
+
const value = settings.get(key);
|
|
146
|
+
if (value === undefined || value === '')
|
|
147
|
+
throw new InitError(`.env is missing ${key}`);
|
|
148
|
+
return value;
|
|
149
|
+
};
|
|
150
|
+
const receiver = publicUrlFrom(setting('MCP_ANALYTICS_PUBLIC_URL'));
|
|
151
|
+
receiver.username = encodeURIComponent(setting('MCP_ANALYTICS_WRITE_KEY'));
|
|
152
|
+
receiver.pathname = `${receiver.pathname.replace(/\/+$/, '')}/${setting('MCP_ANALYTICS_PROJECT_ID')}`;
|
|
153
|
+
return {
|
|
154
|
+
directory,
|
|
155
|
+
created,
|
|
156
|
+
kept,
|
|
157
|
+
application: { url: receiver.href, identitySecret: setting('MCP_ANALYTICS_IDENTITY_SECRET') },
|
|
158
|
+
grafana: { url: setting('GRAFANA_PUBLIC_URL'), user: setting('GRAFANA_VIEWER_USER'), password: setting('GRAFANA_VIEWER_PASSWORD') },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** The operator-facing summary init prints. */
|
|
162
|
+
export function describeInit(result, cwd = process.cwd()) {
|
|
163
|
+
const relative = path.relative(cwd, result.directory);
|
|
164
|
+
const shown = relative === '' ? '.' : relative.startsWith('..') ? result.directory : relative;
|
|
165
|
+
// Quoted for the shell when it contains anything beyond a plain path.
|
|
166
|
+
const cd = /^[\w./-]+$/.test(shown) ? shown : `'${shown.replaceAll("'", "'\\''")}'`;
|
|
167
|
+
// Grafana files are reported as one folder.
|
|
168
|
+
const files = (list) => [...new Set(list.map(file => file.startsWith('grafana/') ? 'grafana/' : file))].join(', ');
|
|
169
|
+
return [
|
|
170
|
+
result.created.length > 0 ? `Wrote ${files(result.created)} in ${shown}.` : `Nothing new to write in ${shown}.`,
|
|
171
|
+
...(result.kept.length > 0 ? [`Kept ${files(result.kept)} (use --force to rewrite the templates; .env is never overwritten).`] : []),
|
|
172
|
+
'',
|
|
173
|
+
'Start or upgrade the backend:',
|
|
174
|
+
` cd ${cd} && docker compose up -d`,
|
|
175
|
+
'',
|
|
176
|
+
'Add to your MCP server\'s environment:',
|
|
177
|
+
` MCP_ANALYTICS_URL=${result.application.url}`,
|
|
178
|
+
` MCP_ANALYTICS_IDENTITY_SECRET=${result.application.identitySecret}`,
|
|
179
|
+
'',
|
|
180
|
+
`Dashboard: ${result.grafana.url} (user ${result.grafana.user}, password ${result.grafana.password})`,
|
|
181
|
+
'Set MCP_ANALYTICS_PUBLIC_URL in .env to the receiver\'s public HTTPS address before sharing the URL.',
|
|
182
|
+
].join('\n');
|
|
183
|
+
}
|
|
184
|
+
/** Lists the files a fresh init writes; used by package checks. */
|
|
185
|
+
export async function deploymentTemplates() {
|
|
186
|
+
const found = [];
|
|
187
|
+
const walk = async (folder, prefix) => {
|
|
188
|
+
for (const entry of await readdir(folder, { withFileTypes: true })) {
|
|
189
|
+
if (entry.isDirectory())
|
|
190
|
+
await walk(path.join(folder, entry.name), `${prefix}${entry.name}/`);
|
|
191
|
+
else
|
|
192
|
+
found.push(`${prefix}${entry.name}`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
await walk(DEPLOY, '');
|
|
196
|
+
return found.sort();
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qEAAqE;AACrE,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC;CAC1E;AA2BD,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAClD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACpE,MAAM,cAAc,GAAG;IACrB,cAAc;IACd,8BAA8B;IAC9B,kCAAkC;IAClC,+CAA+C;IAC/C,gDAAgD;CACjD,CAAC;AAEF,KAAK,UAAU,OAAO;IACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,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,21 @@
|
|
|
1
|
+
import { type EventSink } from "@kometolabs/mcp-analytics";
|
|
2
|
+
/** Supply an operator-owned pool.query wrapper; the adapter has no pg dependency. */
|
|
3
|
+
export type Query = (text: string, values?: unknown[]) => Promise<unknown>;
|
|
4
|
+
/** A single INSERT commits atomically before the sink resolves under autocommit. */
|
|
5
|
+
export declare function createPostgresSink(query: Query): EventSink;
|
|
6
|
+
/**
|
|
7
|
+
* Requires an operator connection; the normal writer cannot delete event rows.
|
|
8
|
+
* Resolves to the number of deleted events when the driver reports it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deleteSubjectEvents(query: Query, subject: {
|
|
11
|
+
projectId: string;
|
|
12
|
+
subjectHash: string;
|
|
13
|
+
identityKeyVersion?: string;
|
|
14
|
+
}): Promise<number | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Delete old raw events; ordinary views update immediately without stale rollups.
|
|
17
|
+
* Resolves to the number of deleted events when the driver reports it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function purgeEventsBefore(query: Query, before: Date | string): Promise<number | undefined>;
|
|
20
|
+
export { configureDataset, DefinitionChangeError, migrateSchema, readSchemaVersion, SCHEMA_VERSION } from "./schema.js";
|
|
21
|
+
export type { DatasetDefinition, OwnerQuery, RolePasswords } from "./schema.js";
|
package/dist/postgres.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { validateEvent } from "@kometolabs/mcp-analytics";
|
|
2
|
+
const INSERT_EVENTS = `
|
|
3
|
+
INSERT INTO mcp_analytics.events (
|
|
4
|
+
schema_version, event_id, project_id, server_id, environment, occurred_at,
|
|
5
|
+
kind, tool_name, outcome, duration_ms, subject_hash, identity_key_version,
|
|
6
|
+
subject_type, client_application, source_tag, operation_hash
|
|
7
|
+
)
|
|
8
|
+
SELECT
|
|
9
|
+
schema_version, event_id, project_id, server_id, environment, occurred_at,
|
|
10
|
+
kind, tool_name, outcome, duration_ms, subject_hash, identity_key_version,
|
|
11
|
+
subject_type, client_application, source_tag, operation_hash
|
|
12
|
+
FROM jsonb_to_recordset($1::jsonb) AS batch (
|
|
13
|
+
schema_version integer, event_id uuid, project_id text, server_id text,
|
|
14
|
+
environment text, occurred_at timestamptz, kind text, tool_name text,
|
|
15
|
+
outcome text, duration_ms double precision, subject_hash text,
|
|
16
|
+
identity_key_version text, subject_type text, client_application text,
|
|
17
|
+
source_tag text, operation_hash text
|
|
18
|
+
)
|
|
19
|
+
ON CONFLICT (project_id, event_id) DO NOTHING
|
|
20
|
+
`;
|
|
21
|
+
function row(event) {
|
|
22
|
+
return {
|
|
23
|
+
schema_version: event.schemaVersion,
|
|
24
|
+
event_id: event.eventId,
|
|
25
|
+
project_id: event.projectId,
|
|
26
|
+
server_id: event.serverId,
|
|
27
|
+
environment: event.environment,
|
|
28
|
+
occurred_at: event.occurredAt,
|
|
29
|
+
kind: event.kind,
|
|
30
|
+
tool_name: event.toolName ?? null,
|
|
31
|
+
outcome: event.outcome ?? null,
|
|
32
|
+
duration_ms: event.durationMs ?? null,
|
|
33
|
+
subject_hash: event.subjectHash ?? null,
|
|
34
|
+
identity_key_version: event.identityKeyVersion ?? null,
|
|
35
|
+
subject_type: event.subjectType ?? null,
|
|
36
|
+
client_application: event.clientApplication ?? "unknown",
|
|
37
|
+
source_tag: event.sourceTag ?? null,
|
|
38
|
+
operation_hash: event.operationHash ?? null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** A single INSERT commits atomically before the sink resolves under autocommit. */
|
|
42
|
+
export function createPostgresSink(query) {
|
|
43
|
+
return async (events) => {
|
|
44
|
+
if (events.length === 0)
|
|
45
|
+
return;
|
|
46
|
+
let values;
|
|
47
|
+
try {
|
|
48
|
+
values = JSON.stringify(events.map((event) => row(validateEvent(event))));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new Error("Invalid analytics batch");
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await query(INSERT_EVENTS, [values]);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Driver messages can contain credentials, query parameters, or private data.
|
|
58
|
+
throw new Error("Analytics batch write failed");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const LABEL = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;
|
|
63
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
64
|
+
// The number of rows a DELETE removed, when the driver reports it (pg and PGlite do).
|
|
65
|
+
function deletedRows(result) {
|
|
66
|
+
if (!result || typeof result !== "object")
|
|
67
|
+
return undefined;
|
|
68
|
+
const { rowCount, affectedRows } = result;
|
|
69
|
+
const count = typeof rowCount === "number" ? rowCount : affectedRows;
|
|
70
|
+
return typeof count === "number" ? count : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Requires an operator connection; the normal writer cannot delete event rows.
|
|
74
|
+
* Resolves to the number of deleted events when the driver reports it.
|
|
75
|
+
*/
|
|
76
|
+
export async function deleteSubjectEvents(query, subject) {
|
|
77
|
+
if (!LABEL.test(subject.projectId) || !HASH.test(subject.subjectHash)
|
|
78
|
+
|| (subject.identityKeyVersion !== undefined && !LABEL.test(subject.identityKeyVersion))) {
|
|
79
|
+
throw new Error("Invalid subject deletion request");
|
|
80
|
+
}
|
|
81
|
+
const values = [subject.projectId, subject.subjectHash];
|
|
82
|
+
let sql = "DELETE FROM mcp_analytics.events WHERE project_id = $1 AND subject_hash = $2";
|
|
83
|
+
if (subject.identityKeyVersion !== undefined) {
|
|
84
|
+
values.push(subject.identityKeyVersion);
|
|
85
|
+
sql += " AND identity_key_version = $3";
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return deletedRows(await query(sql, values));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
throw new Error("Analytics subject deletion failed");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Delete old raw events; ordinary views update immediately without stale rollups.
|
|
96
|
+
* Resolves to the number of deleted events when the driver reports it.
|
|
97
|
+
*/
|
|
98
|
+
export async function purgeEventsBefore(query, before) {
|
|
99
|
+
const time = before instanceof Date ? before.getTime() : new Date(before).getTime();
|
|
100
|
+
if (!Number.isFinite(time))
|
|
101
|
+
throw new Error("Invalid retention cutoff");
|
|
102
|
+
try {
|
|
103
|
+
return deletedRows(await query("DELETE FROM mcp_analytics.events WHERE occurred_at < $1::timestamptz", [new Date(time).toISOString()]));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error("Analytics retention cleanup failed");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export { configureDataset, DefinitionChangeError, migrateSchema, readSchemaVersion, SCHEMA_VERSION } from "./schema.js";
|
|
110
|
+
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuC,MAAM,2BAA2B,CAAC;AAK/F,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;CAkBrB,CAAC;AAEF,SAAS,GAAG,CAAC,KAAqB;IAChC,OAAO;QACL,cAAc,EAAE,KAAK,CAAC,aAAa;QACnC,QAAQ,EAAE,KAAK,CAAC,OAAO;QACvB,UAAU,EAAE,KAAK,CAAC,SAAS;QAC3B,SAAS,EAAE,KAAK,CAAC,QAAQ;QACzB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,WAAW,EAAE,KAAK,CAAC,UAAU;QAC7B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC,QAAQ,IAAI,IAAI;QACjC,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI;QAC9B,WAAW,EAAE,KAAK,CAAC,UAAU,IAAI,IAAI;QACrC,YAAY,EAAE,KAAK,CAAC,WAAW,IAAI,IAAI;QACvC,oBAAoB,EAAE,KAAK,CAAC,kB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C,OAAO,EAAE,CAAC;IACpF,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IACxE,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,MAAM,KAAK,CAAC,sEAAsE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1I,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReceiverResult } from './index.js';
|
|
2
|
+
export interface RejectionLogOptions {
|
|
3
|
+
log: (message: string) => void;
|
|
4
|
+
intervalMs?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Logs the first rejection of each status at once, then a periodic summary of
|
|
8
|
+
* later rejections. Messages contain statuses, counts, and hints only.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createRejectionLog(options: RejectionLogOptions): {
|
|
11
|
+
record: (result: ReceiverResult) => void;
|
|
12
|
+
close: () => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Short operator hints. They describe the fix, never the request contents.
|
|
2
|
+
const HINTS = {
|
|
3
|
+
400: 'check that the sender uses the MCP analytics OTLP profile',
|
|
4
|
+
401: 'check the write key',
|
|
5
|
+
403: 'check MCP_ANALYTICS_PROJECT_ID and the sender projectId',
|
|
6
|
+
404: 'send OTLP logs to /v1/logs',
|
|
7
|
+
405: 'send POST requests',
|
|
8
|
+
408: 'the request body arrived too slowly',
|
|
9
|
+
413: 'reduce the batch or request size',
|
|
10
|
+
415: 'send JSON or Protobuf, optionally gzip-compressed',
|
|
11
|
+
503: 'storage is unavailable or the receiver is busy',
|
|
12
|
+
};
|
|
13
|
+
const plural = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
14
|
+
function describe(status) {
|
|
15
|
+
const hint = HINTS[status];
|
|
16
|
+
return hint === undefined ? `HTTP ${status}` : `HTTP ${status} (${hint})`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Logs the first rejection of each status at once, then a periodic summary of
|
|
20
|
+
* later rejections. Messages contain statuses, counts, and hints only.
|
|
21
|
+
*/
|
|
22
|
+
export function createRejectionLog(options) {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const pending = new Map();
|
|
25
|
+
const log = (message) => { try {
|
|
26
|
+
options.log(message);
|
|
27
|
+
}
|
|
28
|
+
catch { /* logging never affects ingestion */ } };
|
|
29
|
+
const summarize = () => {
|
|
30
|
+
if (pending.size === 0)
|
|
31
|
+
return;
|
|
32
|
+
const parts = [...pending].sort(([a], [b]) => a - b)
|
|
33
|
+
.map(([status, count]) => `${describe(status)}: ${plural(count.requests, 'request')}, ${plural(count.events, 'event')}`);
|
|
34
|
+
pending.clear();
|
|
35
|
+
log(`Analytics receiver rejections since the last summary: ${parts.join('; ')}.`);
|
|
36
|
+
};
|
|
37
|
+
const timer = setInterval(summarize, options.intervalMs ?? 60_000);
|
|
38
|
+
timer.unref();
|
|
39
|
+
return {
|
|
40
|
+
record({ status, events }) {
|
|
41
|
+
if (status < 400)
|
|
42
|
+
return;
|
|
43
|
+
if (!seen.has(status)) {
|
|
44
|
+
seen.add(status);
|
|
45
|
+
log(`Analytics receiver rejected a request: ${describe(status)}, ${plural(events, 'event')}. Later rejections with this status are summarized periodically.`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const count = pending.get(status) ?? { requests: 0, events: 0 };
|
|
49
|
+
count.requests += 1;
|
|
50
|
+
count.events += events;
|
|
51
|
+
pending.set(status, count);
|
|
52
|
+
},
|
|
53
|
+
close() {
|
|
54
|
+
clearInterval(timer);
|
|
55
|
+
summarize();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=rejections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejections.js","sourceRoot":"","sources":["../src/rejections.ts"],"names":[],"mappings":"AAEA,2EAA2E;AAC3E,MAAM,KAAK,GAAqC;IAC9C,GAAG,EAAE,2DAA2D;IAChE,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,yDAAyD;IAC9D,GAAG,EAAE,4BAA4B;IACjC,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,qCAAqC;IAC1C,GAAG,EAAE,kCAAkC;IACvC,GAAG,EAAE,mDAAmD;IACxD,GAAG,EAAE,gDAAgD;CACtD,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AAE5F,SAAS,QAAQ,CAAC,MAAc;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,MAAM,KAAK,IAAI,GAAG,CAAC;AAC5E,CAAC;AAOD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA4B;IAI7D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAgD,CAAC;IACxE,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,EAAE,GAAG,IAAI,CAAC;QAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,qCAAqC,CAAC,C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C,EAAE,CAAC;YAChE,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;YACpB,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK;YACH,aAAa,CAAC,KAAK,CAAC,CAAC;YACrB,SAAS,EAAE,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A query on one owner session (not a pool): migrations run in a transaction. */
|
|
2
|
+
export type OwnerQuery = (text: string, values?: unknown[]) => Promise<{
|
|
3
|
+
rows: Record<string, unknown>[];
|
|
4
|
+
}>;
|
|
5
|
+
/** The schema version that this package's 001-schema.sql converges to. */
|
|
6
|
+
export declare const SCHEMA_VERSION = 2;
|
|
7
|
+
/** Null for a database without the analytics schema; 1 for the unversioned first alpha. */
|
|
8
|
+
export declare function readSchemaVersion(query: OwnerQuery): Promise<number | null>;
|
|
9
|
+
/** Login passwords for the writer (receiver) and reader (Grafana) roles. */
|
|
10
|
+
export interface RolePasswords {
|
|
11
|
+
writer?: string;
|
|
12
|
+
reader?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Applies the packaged schema and roles files in one transaction, so a failure
|
|
16
|
+
* leaves the previous schema and grants in place. Safe to rerun. Given
|
|
17
|
+
* passwords enable LOGIN for those roles and set (or rotate) their passwords.
|
|
18
|
+
*/
|
|
19
|
+
export declare function migrateSchema(query: OwnerQuery, passwords?: RolePasswords): Promise<{
|
|
20
|
+
from: number | null;
|
|
21
|
+
to: number;
|
|
22
|
+
}>;
|
|
23
|
+
export interface DatasetDefinition {
|
|
24
|
+
projectId: string;
|
|
25
|
+
serverId: string;
|
|
26
|
+
environment: string;
|
|
27
|
+
/** The successful tool call that counts as the value action; omit for application mode. */
|
|
28
|
+
valueTool?: string;
|
|
29
|
+
mode: "tool" | "application";
|
|
30
|
+
/** Days after the start of retained history that still count as existing users (default 14). */
|
|
31
|
+
existingUserDays?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Thrown when a dataset already has a different value definition. */
|
|
34
|
+
export declare class DefinitionChangeError extends Error {
|
|
35
|
+
constructor();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a dataset's value definition, or updates only its existing-user
|
|
39
|
+
* window. The definition itself is immutable per dataset.
|
|
40
|
+
*/
|
|
41
|
+
export declare function configureDataset(query: OwnerQuery, definition: DatasetDefinition): Promise<{
|
|
42
|
+
status: "created" | "unchanged" | "updated";
|
|
43
|
+
existingUserDays: number;
|
|
44
|
+
}>;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
/** The schema version that this package's 001-schema.sql converges to. */
|
|
3
|
+
export const SCHEMA_VERSION = 2;
|
|
4
|
+
const LABEL = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;
|
|
5
|
+
/** Null for a database without the analytics schema; 1 for the unversioned first alpha. */
|
|
6
|
+
export async function readSchemaVersion(query) {
|
|
7
|
+
const [found] = (await query(`SELECT to_regclass('mcp_analytics.schema_info') IS NOT NULL AS versioned,
|
|
8
|
+
to_regclass('mcp_analytics.events') IS NOT NULL AS installed`)).rows;
|
|
9
|
+
if (!found?.versioned)
|
|
10
|
+
return found?.installed ? 1 : null;
|
|
11
|
+
const [row] = (await query("SELECT version FROM mcp_analytics.schema_info")).rows;
|
|
12
|
+
return row ? Number(row.version) : 1;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Applies the packaged schema and roles files in one transaction, so a failure
|
|
16
|
+
* leaves the previous schema and grants in place. Safe to rerun. Given
|
|
17
|
+
* passwords enable LOGIN for those roles and set (or rotate) their passwords.
|
|
18
|
+
*/
|
|
19
|
+
export async function migrateSchema(query, passwords = {}) {
|
|
20
|
+
for (const value of [passwords.writer, passwords.reader]) {
|
|
21
|
+
if (value !== undefined && (typeof value !== "string" || value.length === 0 || value.includes("\0"))) {
|
|
22
|
+
throw new TypeError("Invalid role password");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const [schema, roles] = await Promise.all(["001-schema.sql", "002-roles.sql"]
|
|
26
|
+
.map((file) => readFile(new URL(`./sql/${file}`, import.meta.url), "utf8")));
|
|
27
|
+
const from = await readSchemaVersion(query);
|
|
28
|
+
await query("BEGIN");
|
|
29
|
+
try {
|
|
30
|
+
await query(schema);
|
|
31
|
+
await query(roles);
|
|
32
|
+
// ALTER ROLE takes no bind parameters, so the server quotes the password.
|
|
33
|
+
for (const [role, password] of [["mcp_writer", passwords.writer], ["mcp_reader", passwords.reader]]) {
|
|
34
|
+
if (password === undefined)
|
|
35
|
+
continue;
|
|
36
|
+
const [statement] = (await query("SELECT format('ALTER ROLE %I LOGIN PASSWORD %L', $1::text, $2::text) AS sql", [role, password])).rows;
|
|
37
|
+
await query(String(statement?.sql));
|
|
38
|
+
}
|
|
39
|
+
await query("COMMIT");
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
await query("ROLLBACK").catch(() => undefined);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
return { from, to: (await readSchemaVersion(query)) ?? SCHEMA_VERSION };
|
|
46
|
+
}
|
|
47
|
+
/** Thrown when a dataset already has a different value definition. */
|
|
48
|
+
export class DefinitionChangeError extends Error {
|
|
49
|
+
constructor() {
|
|
50
|
+
super("This dataset already has a different value definition. Definitions cannot change; "
|
|
51
|
+
+ "use a new project, server, or environment for a new definition.");
|
|
52
|
+
this.name = "DefinitionChangeError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a dataset's value definition, or updates only its existing-user
|
|
57
|
+
* window. The definition itself is immutable per dataset.
|
|
58
|
+
*/
|
|
59
|
+
export async function configureDataset(query, definition) {
|
|
60
|
+
const { projectId, serverId, environment, mode, existingUserDays } = definition;
|
|
61
|
+
const valueTool = mode === "tool" ? definition.valueTool : undefined;
|
|
62
|
+
if (![projectId, serverId, environment].every((value) => typeof value === "string" && LABEL.test(value))
|
|
63
|
+
|| (mode !== "tool" && mode !== "application")
|
|
64
|
+
|| (mode === "tool" ? typeof valueTool !== "string" || !LABEL.test(valueTool) : definition.valueTool !== undefined)
|
|
65
|
+
|| (existingUserDays !== undefined && (!Number.isInteger(existingUserDays) || existingUserDays < 0 || existingUserDays > 365))) {
|
|
66
|
+
throw new TypeError("Invalid dataset definition");
|
|
67
|
+
}
|
|
68
|
+
const keys = [projectId, serverId, environment];
|
|
69
|
+
const inserted = await query(`INSERT INTO mcp_analytics.project_settings
|
|
70
|
+
(project_id, server_id, environment, value_tool, value_mode, existing_user_days)
|
|
71
|
+
VALUES ($1, $2, $3, $4, $5, COALESCE($6::integer, 14))
|
|
72
|
+
ON CONFLICT (project_id, server_id, environment) DO NOTHING
|
|
73
|
+
RETURNING existing_user_days`, [...keys, valueTool ?? null, mode, existingUserDays ?? null]);
|
|
74
|
+
if (inserted.rows[0])
|
|
75
|
+
return { status: "created", existingUserDays: Number(inserted.rows[0].existing_user_days) };
|
|
76
|
+
const [current] = (await query(`SELECT value_mode, value_tool, existing_user_days FROM mcp_analytics.project_settings
|
|
77
|
+
WHERE project_id = $1 AND server_id = $2 AND environment = $3`, keys)).rows;
|
|
78
|
+
if (!current || current.value_mode !== mode || (current.value_tool ?? undefined) !== valueTool) {
|
|
79
|
+
throw new DefinitionChangeError();
|
|
80
|
+
}
|
|
81
|
+
if (existingUserDays === undefined || Number(current.existing_user_days) === existingUserDays) {
|
|
82
|
+
return { status: "unchanged", existingUserDays: Number(current.existing_user_days) };
|
|
83
|
+
}
|
|
84
|
+
await query(`UPDATE mcp_analytics.project_settings SET existing_user_days = $4
|
|
85
|
+
WHERE project_id = $1 AND server_id = $2 AND environment = $3`, [...keys, existingUserDays]);
|
|
86
|
+
return { status: "updated", existingUserDays };
|
|
87
|
+
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