@inso_web/els-mcp
Version:
MCP-сервер поверх INSO Error Logs Service. Read-only tools (search, analytics, fingerprinting, correlations) для подключения Claude Desktop/Code и ChatGPT к логам ошибок. Streamable HTTP transport + stdio для npx-запуска.
69 lines • 2.92 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: baseline_compare
* Mapping: GET /analytics/baseline → analytics.routes.ts:358
* Upstream Zod: BaselineSchema (windowDays ≥ 7, +фасет-фильтры).
*
* Возвращает baseline-метрики (p50/p95/mean), currentTotal и список аномалий
* (точки выше baseline.p95). Upstream defaults windowDays=30, мы используем
* default=7 как в spec, но допускаем 1..90 (upstream примет min=7, поэтому
* клампим на стороне tool).
*/
export const baselineCompareInputShape = {
windowDays: z.number().int().min(1).max(90).default(7),
level: z.array(z.string().max(16)).optional(),
serviceName: z.string().max(255).optional(),
};
export const baselineCompareToolDef = {
name: 'baseline_compare',
title: 'Compare current period vs historical baseline',
description: 'Show how current error rate compares to historical baseline (rolling N days). Returns p50/p95 thresholds and "above baseline" anomalies.',
inputShape: baselineCompareInputShape,
};
export async function handleBaselineCompare(args, client) {
try {
// Upstream BaselineSchema enforces windowDays >= 7; клампим прозрачно
// и отмечаем в warnings.
const effectiveWindow = Math.max(7, args.windowDays);
const warnings = [];
if (effectiveWindow !== args.windowDays) {
warnings.push(`windowDays=${args.windowDays} clamped to ${effectiveWindow} (upstream min=7).`);
}
const params = {
windowDays: effectiveWindow,
levels: args.level?.join(','),
serviceName: args.serviceName,
};
const { data, elsRequestId } = await client.baseline(params);
const body = (data ?? {});
const meta = {
elsRequestId,
cached: false,
ttlSec: 300,
redactionApplied: false,
...(warnings.length > 0 ? { warnings } : {}),
};
return {
structuredContent: {
windowDays: effectiveWindow,
currentTotal: Number(body.currentTotal ?? body.total ?? 0),
baseline: body.baseline ?? {},
anomalies: Array.isArray(body.anomalies) ? body.anomalies : [],
_meta: meta,
},
content: [
{
type: 'text',
text: `Baseline window=${effectiveWindow}d, currentTotal=${Number(body.currentTotal ?? body.total ?? 0)}, anomalies=${Array.isArray(body.anomalies) ? body.anomalies.length : 0}.`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=baselineCompare.js.map