@mongrov/analytics 0.1.0-alpha.10 → 0.1.0-alpha.8
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/LICENSE +21 -0
- package/README.md +0 -16
- package/dist/tools/index.d.ts +1 -13
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -21
- package/dist/tools/index.js.map +1 -1
- package/package.json +16 -31
- package/dist/tools/__fakes__/engine.d.ts +0 -25
- package/dist/tools/__fakes__/engine.d.ts.map +0 -1
- package/dist/tools/__fakes__/engine.js +0 -37
- package/dist/tools/__fakes__/engine.js.map +0 -1
- package/dist/tools/audit.d.ts +0 -31
- package/dist/tools/audit.d.ts.map +0 -1
- package/dist/tools/audit.js +0 -157
- package/dist/tools/audit.js.map +0 -1
- package/dist/tools/authorize.d.ts +0 -36
- package/dist/tools/authorize.d.ts.map +0 -1
- package/dist/tools/authorize.js +0 -87
- package/dist/tools/authorize.js.map +0 -1
- package/dist/tools/budget.d.ts +0 -15
- package/dist/tools/budget.d.ts.map +0 -1
- package/dist/tools/budget.js +0 -64
- package/dist/tools/budget.js.map +0 -1
- package/dist/tools/factory.d.ts +0 -43
- package/dist/tools/factory.d.ts.map +0 -1
- package/dist/tools/factory.js +0 -137
- package/dist/tools/factory.js.map +0 -1
- package/dist/tools/formatters.d.ts +0 -17
- package/dist/tools/formatters.d.ts.map +0 -1
- package/dist/tools/formatters.js +0 -30
- package/dist/tools/formatters.js.map +0 -1
- package/dist/tools/impls/activity.d.ts +0 -15
- package/dist/tools/impls/activity.d.ts.map +0 -1
- package/dist/tools/impls/activity.js +0 -61
- package/dist/tools/impls/activity.js.map +0 -1
- package/dist/tools/impls/anomaly.d.ts +0 -21
- package/dist/tools/impls/anomaly.d.ts.map +0 -1
- package/dist/tools/impls/anomaly.js +0 -70
- package/dist/tools/impls/anomaly.js.map +0 -1
- package/dist/tools/impls/compare.d.ts +0 -21
- package/dist/tools/impls/compare.d.ts.map +0 -1
- package/dist/tools/impls/compare.js +0 -68
- package/dist/tools/impls/compare.js.map +0 -1
- package/dist/tools/impls/hrv.d.ts +0 -15
- package/dist/tools/impls/hrv.d.ts.map +0 -1
- package/dist/tools/impls/hrv.js +0 -36
- package/dist/tools/impls/hrv.js.map +0 -1
- package/dist/tools/impls/insights.d.ts +0 -18
- package/dist/tools/impls/insights.d.ts.map +0 -1
- package/dist/tools/impls/insights.js +0 -41
- package/dist/tools/impls/insights.js.map +0 -1
- package/dist/tools/impls/sleep.d.ts +0 -15
- package/dist/tools/impls/sleep.d.ts.map +0 -1
- package/dist/tools/impls/sleep.js +0 -43
- package/dist/tools/impls/sleep.js.map +0 -1
- package/dist/tools/mcp/adapter.d.ts +0 -33
- package/dist/tools/mcp/adapter.d.ts.map +0 -1
- package/dist/tools/mcp/adapter.js +0 -56
- package/dist/tools/mcp/adapter.js.map +0 -1
- package/dist/tools/mcp/guard.d.ts +0 -17
- package/dist/tools/mcp/guard.d.ts.map +0 -1
- package/dist/tools/mcp/guard.js +0 -22
- package/dist/tools/mcp/guard.js.map +0 -1
- package/dist/tools/mcp/index.d.ts +0 -20
- package/dist/tools/mcp/index.d.ts.map +0 -1
- package/dist/tools/mcp/index.js +0 -16
- package/dist/tools/mcp/index.js.map +0 -1
- package/dist/tools/mcp/server.d.ts +0 -39
- package/dist/tools/mcp/server.d.ts.map +0 -1
- package/dist/tools/mcp/server.js +0 -70
- package/dist/tools/mcp/server.js.map +0 -1
- package/dist/tools/mcp/transports/http.d.ts +0 -54
- package/dist/tools/mcp/transports/http.d.ts.map +0 -1
- package/dist/tools/mcp/transports/http.js +0 -133
- package/dist/tools/mcp/transports/http.js.map +0 -1
- package/dist/tools/mcp/transports/stdio.d.ts +0 -22
- package/dist/tools/mcp/transports/stdio.d.ts.map +0 -1
- package/dist/tools/mcp/transports/stdio.js +0 -19
- package/dist/tools/mcp/transports/stdio.js.map +0 -1
- package/dist/tools/rate-limit.d.ts +0 -26
- package/dist/tools/rate-limit.d.ts.map +0 -1
- package/dist/tools/rate-limit.js +0 -67
- package/dist/tools/rate-limit.js.map +0 -1
- package/dist/tools/types.d.ts +0 -121
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js +0 -16
- package/dist/tools/types.js.map +0 -1
- package/dist/tools/wrap.d.ts +0 -53
- package/dist/tools/wrap.d.ts.map +0 -1
- package/dist/tools/wrap.js +0 -135
- package/dist/tools/wrap.js.map +0 -1
package/dist/tools/impls/hrv.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { deltaPct, formatBytes } from '../formatters';
|
|
3
|
-
export const getHRVInputSchema = z.object({
|
|
4
|
-
userId: z.string(),
|
|
5
|
-
days: z.number().int().min(1).max(90),
|
|
6
|
-
});
|
|
7
|
-
export const getHRV = async (input, ctx) => {
|
|
8
|
-
const rows = await ctx.analytics.execute(`SELECT date_trunc('day', ts)::VARCHAR AS day, AVG(hrv_ms)::DOUBLE AS avg_hrv
|
|
9
|
-
FROM hrv
|
|
10
|
-
WHERE user_id = $userId AND brand = $brand AND family_id = $familyId
|
|
11
|
-
AND ts >= now() - INTERVAL ($days) DAY
|
|
12
|
-
AND hrv_ms IS NOT NULL
|
|
13
|
-
GROUP BY 1 ORDER BY 1`, {
|
|
14
|
-
userId: input.userId,
|
|
15
|
-
brand: ctx.brand,
|
|
16
|
-
familyId: ctx.familyId,
|
|
17
|
-
days: input.days,
|
|
18
|
-
});
|
|
19
|
-
if (rows.length === 0) {
|
|
20
|
-
return finalize('No HRV data for the requested window.', 0);
|
|
21
|
-
}
|
|
22
|
-
const values = rows.map(r => r.avg_hrv);
|
|
23
|
-
const baseline = values.reduce((a, v) => a + v, 0) / values.length;
|
|
24
|
-
const latest = values[values.length - 1];
|
|
25
|
-
const daily = rows
|
|
26
|
-
.map(r => ` ${r.day}: ${r.avg_hrv.toFixed(1)}ms`)
|
|
27
|
-
.join('\n');
|
|
28
|
-
const text = `HRV, last ${input.days} days:\n${daily}\n`
|
|
29
|
-
+ ` ${input.days}-day avg: ${baseline.toFixed(1)}ms `
|
|
30
|
-
+ `(latest ${latest.toFixed(1)}ms, ${deltaPct(latest, baseline)} vs avg)`;
|
|
31
|
-
return finalize(text, rows.length);
|
|
32
|
-
};
|
|
33
|
-
function finalize(text, rowCount) {
|
|
34
|
-
return { text, rowCount, bytes: formatBytes(text) };
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=hrv.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hrv.js","sourceRoot":"","sources":["../../../src/tools/impls/hrv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAGrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CACtC,CAAC,CAAA;AASF,MAAM,CAAC,MAAM,MAAM,GAA0B,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IAChE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,OAAO,CACtC;;;;;2BAKuB,EACvB;QACE,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CACF,CAAA;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAA;IAClE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACxC,MAAM,KAAK,GAAG,IAAI;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;SACjD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,IAAI,GACN,aAAa,KAAK,CAAC,IAAI,WAAW,KAAK,IAAI;UAC3C,KAAK,KAAK,CAAC,IAAI,aAAa,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;UACpD,WAAW,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAA;IAE3E,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB;IAC9C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAA;AACrD,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ToolImpl } from '../types';
|
|
3
|
-
export declare const getInsightsInputSchema: z.ZodObject<{
|
|
4
|
-
userId: z.ZodString;
|
|
5
|
-
days: z.ZodDefault<z.ZodNumber>;
|
|
6
|
-
severity: z.ZodOptional<z.ZodEnum<["info", "warn", "critical"]>>;
|
|
7
|
-
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
days: number;
|
|
9
|
-
userId: string;
|
|
10
|
-
severity?: "info" | "warn" | "critical" | undefined;
|
|
11
|
-
}, {
|
|
12
|
-
userId: string;
|
|
13
|
-
days?: number | undefined;
|
|
14
|
-
severity?: "info" | "warn" | "critical" | undefined;
|
|
15
|
-
}>;
|
|
16
|
-
export type GetInsightsInput = z.infer<typeof getInsightsInputSchema>;
|
|
17
|
-
export declare const getInsights: ToolImpl<GetInsightsInput>;
|
|
18
|
-
//# sourceMappingURL=insights.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insights.d.ts","sourceRoot":"","sources":["../../../src/tools/impls/insights.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EAIjC,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAUrE,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,gBAAgB,CAuClD,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { formatBytes } from '../formatters';
|
|
3
|
-
export const getInsightsInputSchema = z.object({
|
|
4
|
-
userId: z.string(),
|
|
5
|
-
days: z.number().int().min(1).max(30).default(7),
|
|
6
|
-
severity: z.enum(['info', 'warn', 'critical']).optional(),
|
|
7
|
-
});
|
|
8
|
-
export const getInsights = async (input, ctx) => {
|
|
9
|
-
const params = {
|
|
10
|
-
userId: input.userId,
|
|
11
|
-
brand: ctx.brand,
|
|
12
|
-
familyId: ctx.familyId,
|
|
13
|
-
days: input.days,
|
|
14
|
-
};
|
|
15
|
-
let severityClause = '';
|
|
16
|
-
if (input.severity) {
|
|
17
|
-
severityClause = ' AND severity = $severity';
|
|
18
|
-
params.severity = input.severity;
|
|
19
|
-
}
|
|
20
|
-
const rows = await ctx.analytics.execute(`SELECT id, ts::VARCHAR AS ts, severity, title, body
|
|
21
|
-
FROM insight
|
|
22
|
-
WHERE user_id = $userId AND brand = $brand AND family_id = $familyId
|
|
23
|
-
AND ts >= now() - INTERVAL ($days) DAY${severityClause}
|
|
24
|
-
ORDER BY ts DESC`, params);
|
|
25
|
-
if (rows.length === 0) {
|
|
26
|
-
const scope = input.severity ? ` (${input.severity})` : '';
|
|
27
|
-
return finalize(`No insights${scope} in the last ${input.days} days.`, 0);
|
|
28
|
-
}
|
|
29
|
-
const bullets = rows
|
|
30
|
-
.map((r) => {
|
|
31
|
-
const body = r.body ? ` — ${r.body}` : '';
|
|
32
|
-
return ` [${r.severity}] ${r.ts}: ${r.title}${body}`;
|
|
33
|
-
})
|
|
34
|
-
.join('\n');
|
|
35
|
-
const text = `Insights, last ${input.days} days:\n${bullets}`;
|
|
36
|
-
return finalize(text, rows.length);
|
|
37
|
-
};
|
|
38
|
-
function finalize(text, rowCount) {
|
|
39
|
-
return { text, rowCount, bytes: formatBytes(text) };
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=insights.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insights.js","sourceRoot":"","sources":["../../../src/tools/impls/insights.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1D,CAAC,CAAA;AAYF,MAAM,CAAC,MAAM,WAAW,GAA+B,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IAC1E,MAAM,MAAM,GAA4B;QACtC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAA;IACD,IAAI,cAAc,GAAG,EAAE,CAAA;IACvB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,cAAc,GAAG,2BAA2B,CAAA;QAC5C,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;IAClC,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,OAAO,CACtC;;;+CAG2C,cAAc;sBACvC,EAClB,MAAM,CACP,CAAA;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1D,OAAO,QAAQ,CACb,cAAc,KAAK,gBAAgB,KAAK,CAAC,IAAI,QAAQ,EACrD,CAAC,CACF,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACzC,OAAO,MAAM,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,CAAA;IACvD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,IAAI,GAAG,kBAAkB,KAAK,CAAC,IAAI,WAAW,OAAO,EAAE,CAAA;IAC7D,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB;IAC9C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAA;AACrD,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ToolImpl } from '../types';
|
|
3
|
-
export declare const getSleepSummaryInputSchema: z.ZodObject<{
|
|
4
|
-
userId: z.ZodString;
|
|
5
|
-
days: z.ZodNumber;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
days: number;
|
|
8
|
-
userId: string;
|
|
9
|
-
}, {
|
|
10
|
-
days: number;
|
|
11
|
-
userId: string;
|
|
12
|
-
}>;
|
|
13
|
-
export type GetSleepSummaryInput = z.infer<typeof getSleepSummaryInputSchema>;
|
|
14
|
-
export declare const getSleepSummary: ToolImpl<GetSleepSummaryInput>;
|
|
15
|
-
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../src/tools/impls/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,0BAA0B;;;;;;;;;EAGrC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAU7E,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,oBAAoB,CA0C1D,CAAA"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { formatBytes } from '../formatters';
|
|
3
|
-
export const getSleepSummaryInputSchema = z.object({
|
|
4
|
-
userId: z.string(),
|
|
5
|
-
days: z.number().int().min(1).max(90),
|
|
6
|
-
});
|
|
7
|
-
export const getSleepSummary = async (input, ctx) => {
|
|
8
|
-
const rows = await ctx.analytics.execute(`SELECT night_of::VARCHAR AS night_of,
|
|
9
|
-
SUM(total_minutes)::INTEGER AS total_minutes,
|
|
10
|
-
SUM(deep_minutes)::INTEGER AS deep_minutes,
|
|
11
|
-
SUM(rem_minutes)::INTEGER AS rem_minutes,
|
|
12
|
-
SUM(light_minutes)::INTEGER AS light_minutes
|
|
13
|
-
FROM sleep_session
|
|
14
|
-
WHERE user_id = $userId AND brand = $brand AND family_id = $familyId
|
|
15
|
-
AND ts_start >= now() - INTERVAL ($days) DAY
|
|
16
|
-
GROUP BY night_of ORDER BY night_of`, {
|
|
17
|
-
userId: input.userId,
|
|
18
|
-
brand: ctx.brand,
|
|
19
|
-
familyId: ctx.familyId,
|
|
20
|
-
days: input.days,
|
|
21
|
-
});
|
|
22
|
-
if (rows.length === 0) {
|
|
23
|
-
return finalize('No sleep sessions for the requested window.', 0);
|
|
24
|
-
}
|
|
25
|
-
const totalMean = rows.reduce((a, r) => a + r.total_minutes, 0) / rows.length;
|
|
26
|
-
const perNight = rows
|
|
27
|
-
.map((r) => {
|
|
28
|
-
const parts = [`${r.total_minutes}m total`];
|
|
29
|
-
if (r.deep_minutes != null)
|
|
30
|
-
parts.push(`${r.deep_minutes}m deep`);
|
|
31
|
-
if (r.rem_minutes != null)
|
|
32
|
-
parts.push(`${r.rem_minutes}m REM`);
|
|
33
|
-
return ` ${r.night_of}: ${parts.join(', ')}`;
|
|
34
|
-
})
|
|
35
|
-
.join('\n');
|
|
36
|
-
const text = `Sleep, last ${input.days} days:\n${perNight}\n`
|
|
37
|
-
+ ` ${rows.length}-night avg total: ${totalMean.toFixed(0)}m`;
|
|
38
|
-
return finalize(text, rows.length);
|
|
39
|
-
};
|
|
40
|
-
function finalize(text, rowCount) {
|
|
41
|
-
return { text, rowCount, bytes: formatBytes(text) };
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=sleep.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../../src/tools/impls/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CACtC,CAAC,CAAA;AAYF,MAAM,CAAC,MAAM,eAAe,GAAmC,KAAK,EAClE,KAAK,EACL,GAAG,EACH,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,OAAO,CACtC;;;;;;;;yCAQqC,EACrC;QACE,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CACF,CAAA;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC,6CAA6C,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,MAAM,SAAS,GACX,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;IAC/D,MAAM,QAAQ,GAAG,IAAI;SAClB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,KAAK,GAAa,CAAC,GAAG,CAAC,CAAC,aAAa,SAAS,CAAC,CAAA;QACrD,IAAI,CAAC,CAAC,YAAY,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,YAAY,QAAQ,CAAC,CAAA;QACjE,IAAI,CAAC,CAAC,WAAW,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,OAAO,CAAC,CAAA;QAC9D,OAAO,KAAK,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAC/C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,IAAI,GACN,eAAe,KAAK,CAAC,IAAI,WAAW,QAAQ,IAAI;UAChD,KAAK,IAAI,CAAC,MAAM,qBAAqB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAA;IAEhE,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB;IAC9C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAA;AACrD,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `toMcpTools` — adapt the six wrapped AI SDK v4 tools that back
|
|
3
|
-
* `AnalyticsToolsHandle` into the shape MCP servers speak.
|
|
4
|
-
*
|
|
5
|
-
* MCP servers want `{ name, description, inputSchema (JSON Schema),
|
|
6
|
-
* handler(args) => { content: [{ type: 'text', text }] } }`. Our
|
|
7
|
-
* factory returns AI SDK v4 tools whose `execute(args, opts) =>
|
|
8
|
-
* Promise<string>` already runs the full
|
|
9
|
-
* rate → auth → execute → budget → audit chain — so the adapter is
|
|
10
|
-
* a thin translation layer, not a second wrapper.
|
|
11
|
-
*
|
|
12
|
-
* The Zod parameter schemas are converted to JSON Schema draft-7 via
|
|
13
|
-
* `zod-to-json-schema` (drops `$schema` and `additionalProperties`
|
|
14
|
-
* so MCP clients get a compact tool descriptor). `.default()` values
|
|
15
|
-
* survive the conversion (asserted in the tests) so LLMs see the
|
|
16
|
-
* documented defaults on `detectAnomaly.stddevThreshold` and
|
|
17
|
-
* `getInsights.days`.
|
|
18
|
-
*/
|
|
19
|
-
import type { AnalyticsToolsHandle } from '../factory';
|
|
20
|
-
export interface McpTool {
|
|
21
|
-
name: string;
|
|
22
|
-
description: string;
|
|
23
|
-
inputSchema: Record<string, unknown>;
|
|
24
|
-
handler: (args: unknown) => Promise<{
|
|
25
|
-
content: {
|
|
26
|
-
type: 'text';
|
|
27
|
-
text: string;
|
|
28
|
-
}[];
|
|
29
|
-
isError?: boolean;
|
|
30
|
-
}>;
|
|
31
|
-
}
|
|
32
|
-
export declare function toMcpTools(handle: AnalyticsToolsHandle): McpTool[];
|
|
33
|
-
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;QAClC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;QACzC,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAC,CAAA;CACH;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,EAAE,CAyClE"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `toMcpTools` — adapt the six wrapped AI SDK v4 tools that back
|
|
3
|
-
* `AnalyticsToolsHandle` into the shape MCP servers speak.
|
|
4
|
-
*
|
|
5
|
-
* MCP servers want `{ name, description, inputSchema (JSON Schema),
|
|
6
|
-
* handler(args) => { content: [{ type: 'text', text }] } }`. Our
|
|
7
|
-
* factory returns AI SDK v4 tools whose `execute(args, opts) =>
|
|
8
|
-
* Promise<string>` already runs the full
|
|
9
|
-
* rate → auth → execute → budget → audit chain — so the adapter is
|
|
10
|
-
* a thin translation layer, not a second wrapper.
|
|
11
|
-
*
|
|
12
|
-
* The Zod parameter schemas are converted to JSON Schema draft-7 via
|
|
13
|
-
* `zod-to-json-schema` (drops `$schema` and `additionalProperties`
|
|
14
|
-
* so MCP clients get a compact tool descriptor). `.default()` values
|
|
15
|
-
* survive the conversion (asserted in the tests) so LLMs see the
|
|
16
|
-
* documented defaults on `detectAnomaly.stddevThreshold` and
|
|
17
|
-
* `getInsights.days`.
|
|
18
|
-
*/
|
|
19
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
20
|
-
export function toMcpTools(handle) {
|
|
21
|
-
const entries = Object.entries(handle.tools);
|
|
22
|
-
return entries.map(([name, tool]) => {
|
|
23
|
-
const parameters = tool.parameters;
|
|
24
|
-
const rawSchema = zodToJsonSchema(parameters, {
|
|
25
|
-
target: 'jsonSchema7',
|
|
26
|
-
$refStrategy: 'none',
|
|
27
|
-
});
|
|
28
|
-
// Strip the top-level $schema marker — MCP clients don't need it,
|
|
29
|
-
// and its presence bloats every list_tools response.
|
|
30
|
-
const { $schema: _drop, ...inputSchema } = rawSchema;
|
|
31
|
-
return {
|
|
32
|
-
name: String(name),
|
|
33
|
-
description: tool.description ?? '',
|
|
34
|
-
inputSchema,
|
|
35
|
-
handler: async (args) => {
|
|
36
|
-
if (!tool.execute) {
|
|
37
|
-
return {
|
|
38
|
-
content: [{
|
|
39
|
-
type: 'text',
|
|
40
|
-
text: `Tool ${String(name)} is not executable.`,
|
|
41
|
-
}],
|
|
42
|
-
isError: true,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const text = await tool.execute(args, {
|
|
46
|
-
toolCallId: `mcp:${String(name)}`,
|
|
47
|
-
messages: [],
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
content: [{ type: 'text', text: String(text) }],
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/tools/mcp/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAapD,MAAM,UAAU,UAAU,CAAC,MAA4B;IACrD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAGxC,CAAA;IAEH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QAClC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAmD,CAAA;QAC3E,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,EAAE;YAC5C,MAAM,EAAE,aAAa;YACrB,YAAY,EAAE,MAAM;SACrB,CAA4B,CAAA;QAE7B,kEAAkE;QAClE,qDAAqD;QACrD,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,WAAW,EAAE,GAAG,SAAS,CAAA;QAEpD,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;YAClB,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;YACnC,WAAW;YACX,OAAO,EAAE,KAAK,EAAE,IAAa,EAAE,EAAE;gBAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,OAAO;wBACL,OAAO,EAAE,CAAC;gCACR,IAAI,EAAE,MAAe;gCACrB,IAAI,EAAE,QAAQ,MAAM,CAAC,IAAI,CAAC,qBAAqB;6BAChD,CAAC;wBACF,OAAO,EAAE,IAAI;qBACd,CAAA;gBACH,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAa,EAAE;oBAC7C,UAAU,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE;oBACjC,QAAQ,EAAE,EAAE;iBACb,CAAC,CAAA;gBACF,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;iBACzD,CAAA;YACH,CAAC;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `shouldStartMcpServer` — cross-runtime dev flag for the MCP subpath.
|
|
3
|
-
*
|
|
4
|
-
* Returns `true` iff the process is a React Native dev build
|
|
5
|
-
* (`__DEV__ === true`) **or** the Node process has
|
|
6
|
-
* `ENABLE_MCP_SERVER=1` set. Prod RN builds have `__DEV__ === false`
|
|
7
|
-
* and no `process.env`, so the check returns `false` and the caller
|
|
8
|
-
* short-circuits — with `sideEffects: false` at the package root,
|
|
9
|
-
* this lets bundlers drop every module reachable only through the
|
|
10
|
-
* MCP subpath (including `@modelcontextprotocol/sdk`).
|
|
11
|
-
*
|
|
12
|
-
* The helper is intentionally pure — importing it does not itself
|
|
13
|
-
* import the SDK. Callers should gate SDK imports behind
|
|
14
|
-
* `shouldStartMcpServer()` at their entry point.
|
|
15
|
-
*/
|
|
16
|
-
export declare function shouldStartMcpServer(): boolean;
|
|
17
|
-
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,wBAAgB,oBAAoB,IAAI,OAAO,CAO9C"}
|
package/dist/tools/mcp/guard.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `shouldStartMcpServer` — cross-runtime dev flag for the MCP subpath.
|
|
3
|
-
*
|
|
4
|
-
* Returns `true` iff the process is a React Native dev build
|
|
5
|
-
* (`__DEV__ === true`) **or** the Node process has
|
|
6
|
-
* `ENABLE_MCP_SERVER=1` set. Prod RN builds have `__DEV__ === false`
|
|
7
|
-
* and no `process.env`, so the check returns `false` and the caller
|
|
8
|
-
* short-circuits — with `sideEffects: false` at the package root,
|
|
9
|
-
* this lets bundlers drop every module reachable only through the
|
|
10
|
-
* MCP subpath (including `@modelcontextprotocol/sdk`).
|
|
11
|
-
*
|
|
12
|
-
* The helper is intentionally pure — importing it does not itself
|
|
13
|
-
* import the SDK. Callers should gate SDK imports behind
|
|
14
|
-
* `shouldStartMcpServer()` at their entry point.
|
|
15
|
-
*/
|
|
16
|
-
export function shouldStartMcpServer() {
|
|
17
|
-
const isRnDev = typeof __DEV__ !== 'undefined' && __DEV__ === true;
|
|
18
|
-
const isNodeFlag = typeof process !== 'undefined'
|
|
19
|
-
&& process.env?.ENABLE_MCP_SERVER === '1';
|
|
20
|
-
return isRnDev || isNodeFlag;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=guard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../../src/tools/mcp/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,UAAU,oBAAoB;IAClC,MAAM,OAAO,GACT,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,CAAA;IACtD,MAAM,UAAU,GACZ,OAAO,OAAO,KAAK,WAAW;WAC3B,OAAO,CAAC,GAAG,EAAE,iBAAiB,KAAK,GAAG,CAAA;IAC7C,OAAO,OAAO,IAAI,UAAU,CAAA;AAC9B,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@mongrov/analytics/tools/mcp` — Model Context Protocol server for
|
|
3
|
-
* the six analytics tools. See `./README.md` for wiring examples.
|
|
4
|
-
*
|
|
5
|
-
* Importing this barrel does NOT itself construct a server. Callers
|
|
6
|
-
* gate SDK-touching code behind `shouldStartMcpServer()`; combined
|
|
7
|
-
* with the package's `sideEffects: false`, prod bundles reachable
|
|
8
|
-
* only through this subpath drop the `@modelcontextprotocol/sdk`
|
|
9
|
-
* runtime entirely.
|
|
10
|
-
*/
|
|
11
|
-
export { toMcpTools } from './adapter';
|
|
12
|
-
export type { McpTool } from './adapter';
|
|
13
|
-
export { shouldStartMcpServer } from './guard';
|
|
14
|
-
export { createMcpServer } from './server';
|
|
15
|
-
export type { CreateMcpServerConfig, McpServerHandle, } from './server';
|
|
16
|
-
export { createStdioTransport } from './transports/stdio';
|
|
17
|
-
export type { CreateStdioTransportOptions } from './transports/stdio';
|
|
18
|
-
export { createHttpTransport } from './transports/http';
|
|
19
|
-
export type { CreateHttpTransportConfig, HttpTransportHandle, } from './transports/http';
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EACV,qBAAqB,EACrB,eAAe,GAChB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACzD,YAAY,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,YAAY,EACV,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,mBAAmB,CAAA"}
|
package/dist/tools/mcp/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@mongrov/analytics/tools/mcp` — Model Context Protocol server for
|
|
3
|
-
* the six analytics tools. See `./README.md` for wiring examples.
|
|
4
|
-
*
|
|
5
|
-
* Importing this barrel does NOT itself construct a server. Callers
|
|
6
|
-
* gate SDK-touching code behind `shouldStartMcpServer()`; combined
|
|
7
|
-
* with the package's `sideEffects: false`, prod bundles reachable
|
|
8
|
-
* only through this subpath drop the `@modelcontextprotocol/sdk`
|
|
9
|
-
* runtime entirely.
|
|
10
|
-
*/
|
|
11
|
-
export { toMcpTools } from './adapter';
|
|
12
|
-
export { shouldStartMcpServer } from './guard';
|
|
13
|
-
export { createMcpServer } from './server';
|
|
14
|
-
export { createStdioTransport } from './transports/stdio';
|
|
15
|
-
export { createHttpTransport } from './transports/http';
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAM1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `createMcpServer` — wrap an `AnalyticsToolsHandle` in an MCP server
|
|
3
|
-
* that speaks `tools/list` + `tools/call` to any MCP client.
|
|
4
|
-
*
|
|
5
|
-
* We use the low-level `Server` + `setRequestHandler` rather than the
|
|
6
|
-
* higher-level `McpServer.registerTool`, because `registerTool` wants
|
|
7
|
-
* either a Zod raw shape or an `AnySchema`, and our tools were built
|
|
8
|
-
* around `zod.object(...)` (not raw shapes) and are already converted
|
|
9
|
-
* to JSON Schema by `toMcpTools`. Emitting the pre-baked JSON Schema
|
|
10
|
-
* from `tools/list` keeps the source of truth in one place (the Zod
|
|
11
|
-
* schemas in `src/tools/impls/*.ts`).
|
|
12
|
-
*
|
|
13
|
-
* `call_tool` re-dispatches into the wrapped `tool.execute`, which
|
|
14
|
-
* runs the full rate → auth → execute → budget → audit chain via the
|
|
15
|
-
* ctx container the handle owns. `handle.setContext(...)` before an
|
|
16
|
-
* MCP session behaves identically to setting it before an AI SDK turn.
|
|
17
|
-
*/
|
|
18
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
19
|
-
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
20
|
-
import type { AnalyticsToolsHandle } from '../factory';
|
|
21
|
-
import type { ToolsLogger } from '../types';
|
|
22
|
-
export interface CreateMcpServerConfig {
|
|
23
|
-
toolsHandle: AnalyticsToolsHandle;
|
|
24
|
-
/** Server name advertised on `initialize`. Default `'mongrov-analytics'`. */
|
|
25
|
-
name?: string;
|
|
26
|
-
/** Server version advertised on `initialize`. Default `'0.1.0'`. */
|
|
27
|
-
version?: string;
|
|
28
|
-
logger?: ToolsLogger;
|
|
29
|
-
}
|
|
30
|
-
export interface McpServerHandle {
|
|
31
|
-
/** The underlying SDK server — exposed for advanced callers. */
|
|
32
|
-
server: Server;
|
|
33
|
-
/** Attach to a transport and start listening. */
|
|
34
|
-
connect: (transport: Transport) => Promise<void>;
|
|
35
|
-
/** Close the connection. Does NOT close the underlying tools handle. */
|
|
36
|
-
close: () => Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
export declare function createMcpServer(config: CreateMcpServerConfig): McpServerHandle;
|
|
39
|
-
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAK9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAG3C,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,oBAAoB,CAAA;IACjC,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAA;IACd,iDAAiD;IACjD,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAChD,wEAAwE;IACxE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CA2DjB"}
|
package/dist/tools/mcp/server.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `createMcpServer` — wrap an `AnalyticsToolsHandle` in an MCP server
|
|
3
|
-
* that speaks `tools/list` + `tools/call` to any MCP client.
|
|
4
|
-
*
|
|
5
|
-
* We use the low-level `Server` + `setRequestHandler` rather than the
|
|
6
|
-
* higher-level `McpServer.registerTool`, because `registerTool` wants
|
|
7
|
-
* either a Zod raw shape or an `AnySchema`, and our tools were built
|
|
8
|
-
* around `zod.object(...)` (not raw shapes) and are already converted
|
|
9
|
-
* to JSON Schema by `toMcpTools`. Emitting the pre-baked JSON Schema
|
|
10
|
-
* from `tools/list` keeps the source of truth in one place (the Zod
|
|
11
|
-
* schemas in `src/tools/impls/*.ts`).
|
|
12
|
-
*
|
|
13
|
-
* `call_tool` re-dispatches into the wrapped `tool.execute`, which
|
|
14
|
-
* runs the full rate → auth → execute → budget → audit chain via the
|
|
15
|
-
* ctx container the handle owns. `handle.setContext(...)` before an
|
|
16
|
-
* MCP session behaves identically to setting it before an AI SDK turn.
|
|
17
|
-
*/
|
|
18
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
19
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
20
|
-
import { toMcpTools } from './adapter';
|
|
21
|
-
export function createMcpServer(config) {
|
|
22
|
-
const mcpTools = toMcpTools(config.toolsHandle);
|
|
23
|
-
const byName = new Map(mcpTools.map(t => [t.name, t]));
|
|
24
|
-
const server = new Server({
|
|
25
|
-
name: config.name ?? 'mongrov-analytics',
|
|
26
|
-
version: config.version ?? '0.1.0',
|
|
27
|
-
}, { capabilities: { tools: {} } });
|
|
28
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
29
|
-
tools: mcpTools.map(t => ({
|
|
30
|
-
name: t.name,
|
|
31
|
-
description: t.description,
|
|
32
|
-
inputSchema: t.inputSchema,
|
|
33
|
-
})),
|
|
34
|
-
}));
|
|
35
|
-
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
36
|
-
const tool = byName.get(req.params.name);
|
|
37
|
-
if (!tool) {
|
|
38
|
-
return {
|
|
39
|
-
content: [{
|
|
40
|
-
type: 'text',
|
|
41
|
-
text: `Unknown tool: ${req.params.name}`,
|
|
42
|
-
}],
|
|
43
|
-
isError: true,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
return await tool.handler(req.params.arguments ?? {});
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
51
|
-
config.logger?.error('mcp tool handler threw', {
|
|
52
|
-
toolName: req.params.name,
|
|
53
|
-
err: message,
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
content: [{
|
|
57
|
-
type: 'text',
|
|
58
|
-
text: `Tool call failed.`,
|
|
59
|
-
}],
|
|
60
|
-
isError: true,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
server,
|
|
66
|
-
connect: transport => server.connect(transport),
|
|
67
|
-
close: () => server.close(),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/tools/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAElE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAA;AAG3C,OAAO,EAAgB,UAAU,EAAE,MAAM,WAAW,CAAA;AAoBpD,MAAM,UAAU,eAAe,CAC7B,MAA6B;IAE7B,MAAM,QAAQ,GAAc,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC1D,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAU,CAAC,CAAC,CAAA;IAE/D,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;QACE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,mBAAmB;QACxC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO;KACnC,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAA;IAED,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QAC5D,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,WAAW,EAAE,CAAC,CAAC,WAId;SACF,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;IAEH,MAAM,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;gBACL,OAAO,EAAE,CAAC;wBACR,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,iBAAiB,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE;qBACzC,CAAC;gBACF,OAAO,EAAE,IAAI;aACd,CAAA;QACH,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;QACvD,CAAC;QACD,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAChE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,wBAAwB,EAAE;gBAC7C,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;gBACzB,GAAG,EAAE,OAAO;aACb,CAAC,CAAA;YACF,OAAO;gBACL,OAAO,EAAE,CAAC;wBACR,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,mBAAmB;qBAC1B,CAAC;gBACF,OAAO,EAAE,IAAI;aACd,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,MAAM;QACN,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;QAC/C,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAC5B,CAAA;AACH,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `createHttpTransport` — Node HTTP transport for `createMcpServer`.
|
|
3
|
-
*
|
|
4
|
-
* Boots a bare `node:http` server that gates requests behind an
|
|
5
|
-
* optional bearer token, then hands them to the SDK's
|
|
6
|
-
* `StreamableHTTPServerTransport`. Runs in stateless mode
|
|
7
|
-
* (no `sessionIdGenerator`) — every request is self-contained, which
|
|
8
|
-
* matches how our tools are already wired (`handle.setContext(...)`
|
|
9
|
-
* carries the per-user scope, not the transport).
|
|
10
|
-
*
|
|
11
|
-
* Deliberately minimal:
|
|
12
|
-
* - one path (default `/mcp`)
|
|
13
|
-
* - one method (POST + GET both dispatched to the SDK)
|
|
14
|
-
* - bearer via `Authorization: Bearer <token>`, constant-time cmp
|
|
15
|
-
* - unauthenticated boot logs a warn but is allowed for local dev
|
|
16
|
-
*
|
|
17
|
-
* Meaningful only under Node; RN builds should never import this
|
|
18
|
-
* module — the guard + `sideEffects: false` keep it out of prod
|
|
19
|
-
* bundles.
|
|
20
|
-
*
|
|
21
|
-
* Callers wire it as:
|
|
22
|
-
* const t = await createHttpTransport({ port: 8787, authToken: 'x' })
|
|
23
|
-
* await mcpServer.connect(t.transport)
|
|
24
|
-
* // ...
|
|
25
|
-
* await t.close()
|
|
26
|
-
*/
|
|
27
|
-
import type { Server as HttpServer } from 'node:http';
|
|
28
|
-
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
29
|
-
import type { ToolsLogger } from '../../types';
|
|
30
|
-
export interface CreateHttpTransportConfig {
|
|
31
|
-
/** Listening port. `0` picks an ephemeral port (tests). Default `0`. */
|
|
32
|
-
port?: number;
|
|
33
|
-
/** URL path. Default `/mcp`. */
|
|
34
|
-
path?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Optional bearer token. If set, incoming requests must present
|
|
37
|
-
* `Authorization: Bearer <authToken>` or get a 401. If unset, all
|
|
38
|
-
* requests pass — logged as a warn on boot.
|
|
39
|
-
*/
|
|
40
|
-
authToken?: string;
|
|
41
|
-
logger?: ToolsLogger;
|
|
42
|
-
}
|
|
43
|
-
export interface HttpTransportHandle {
|
|
44
|
-
/** The SDK transport — hand to `mcpServer.connect(...)`. */
|
|
45
|
-
transport: Transport;
|
|
46
|
-
/** The Node HTTP server — exposed for advanced callers. */
|
|
47
|
-
server: HttpServer;
|
|
48
|
-
/** Actual listening port (resolved when `port: 0`). */
|
|
49
|
-
port: number;
|
|
50
|
-
/** Shut down the HTTP server + transport. */
|
|
51
|
-
close: () => Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
export declare function createHttpTransport(config?: CreateHttpTransportConfig): Promise<HttpTransportHandle>;
|
|
54
|
-
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../src/tools/mcp/transports/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAmB,MAAM,IAAI,UAAU,EAAkB,MAAM,WAAW,CAAA;AAItF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,yBAAyB;IACxC,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,SAAS,EAAE,SAAS,CAAA;IACpB,2DAA2D;IAC3D,MAAM,EAAE,UAAU,CAAA;IAClB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,6CAA6C;IAC7C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAgCD,wBAAsB,mBAAmB,CACvC,MAAM,GAAE,yBAA8B,GACrC,OAAO,CAAC,mBAAmB,CAAC,CAkF9B"}
|