@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-запуска.
64 lines • 2.29 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: traffic_stats
* Mapping: GET /analytics/traffic → analytics.routes.ts:268
* Upstream Zod: HistogramSchema (тот же что и histogram — from+to+фильтры).
*
* Возвращает perService с RPM-сериями и latency p50/p95/p99 + summary.
*/
export const trafficStatsInputShape = {
from: z.string().min(1),
to: z.string().min(1),
level: z.array(z.string().max(16)).optional(),
serviceName: z.array(z.string().max(255)).optional(),
appVersion: z.array(z.string().max(64)).optional(),
};
export const trafficStatsToolDef = {
name: 'traffic_stats',
title: 'Traffic + latency stats per service',
description: [
'Returns RPM time-series per service + latency percentiles (p50/p95/p99) + summary.',
'',
'WHEN TO USE:',
' - Capacity planning - answer "is service X getting overloaded?".',
' - Latency regression hunting - did p95 jump after deploy?',
' - Correlate traffic dips with error spikes during incidents.',
].join('\n'),
inputShape: trafficStatsInputShape,
};
export async function handleTrafficStats(args, client) {
try {
const params = {
from: args.from,
to: args.to,
levels: args.level?.join(','),
serviceName: args.serviceName?.join(','),
appVersion: args.appVersion?.join(','),
};
const { data, elsRequestId } = await client.trafficStats(params);
const meta = {
elsRequestId,
cached: false,
ttlSec: 30,
redactionApplied: false,
};
const body = (data ?? {});
const perService = Array.isArray(body.perService) ? body.perService : [];
return {
structuredContent: { ...body, _meta: meta },
content: [
{
type: 'text',
text: `Traffic stats for ${perService.length} service(s), from ${args.from} to ${args.to}.`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=trafficStats.js.map