@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-запуска.
67 lines • 2.7 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: find_similar_errors
* Mapping: GET /errors/:traceId/similar → analytics.routes.ts:159
*
* Возвращает агрегаты (totalOccurrences, lastHour/24h/7d, topUrls, topIPs,
* sourceSplit) для ошибок с похожим message/fingerprint.
*
* ELS endpoint принимает query: `levels` (csv), `serviceName`, `appVersion`.
*/
export const findSimilarErrorsInputShape = {
traceId: z.string().min(1).max(128),
levels: z.array(z.string().max(16)).optional(),
serviceName: z.string().max(255).optional(),
appVersion: z.string().max(64).optional(),
limit: z.number().int().min(1).max(200).default(20),
// eslint-disable-next-line camelcase
response_format: z.enum(['compact', 'full', 'summary']).default('compact'),
};
export const findSimilarErrorsToolDef = {
name: 'find_similar_errors',
title: 'Find errors similar to a given traceId',
description: [
'Given a traceId, returns aggregated stats about similar errors (by message/fingerprint):',
'totalOccurrences, lastHour/24h/7d, firstSeen, lastSeen, topUrls, topIPs, sourceSplit.',
'',
'WHEN TO USE:',
' - After fixing an error - verify error rate dropped (compare lastHour vs prior 24h).',
' - Determining if a reported error is new or a long-standing recurrence.',
' - Triaging a CRITICAL fingerprint - check blast radius before alerting on-call.',
].join('\n'),
inputShape: findSimilarErrorsInputShape,
};
export async function handleFindSimilarErrors(args, client) {
try {
const params = {
levels: args.levels?.join(','),
serviceName: args.serviceName,
appVersion: args.appVersion,
};
const { data, elsRequestId } = await client.findSimilarErrors(args.traceId, params);
const meta = {
elsRequestId,
cached: false,
ttlSec: 60,
redactionApplied: false,
};
const result = (data ?? {});
const totalOccurrences = Number(result.totalOccurrences ?? 0);
return {
structuredContent: { ...result, _meta: meta },
content: [
{
type: 'text',
text: `Found ${totalOccurrences} similar errors (lastHour=${result.lastHour ?? 0}, last24h=${result.last24h ?? 0}, last7d=${result.last7d ?? 0}).`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=findSimilarErrors.js.map