@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-запуска.
66 lines • 2.73 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: find_correlated_errors
* Mapping: GET /errors/:traceId/correlated → analytics.routes.ts:188
*
* Возвращает другие ошибки в ±windowMinutes от данной — для поиска
* каскадных сбоев. ELS endpoint принимает: windowMinutes, limit, +
* фасет-фильтры из QueryErrorsSchema (levels, serviceName, ...).
*/
export const findCorrelatedErrorsInputShape = {
traceId: z.string().min(1).max(128),
windowMinutes: z.number().int().min(1).max(1440).default(15),
limit: z.number().int().min(1).max(100).default(20),
level: z.array(z.string().max(16)).optional(),
serviceName: z.array(z.string().max(255)).optional(),
// eslint-disable-next-line camelcase
response_format: z.enum(['compact', 'full', 'summary']).default('compact'),
};
export const findCorrelatedErrorsToolDef = {
name: 'find_correlated_errors',
title: 'Find errors that co-occur in time around a traceId',
description: [
'Given a traceId, returns other errors within +/-windowMinutes (default 15) in the same app.',
'',
'WHEN TO USE:',
' - Investigating a cascading failure - did an upstream timeout produce downstream errors?',
' - Incident postmortem - build a timeline of what fired around the primary error.',
' - User reports a sequence of failures - find the common root by time proximity.',
].join('\n'),
inputShape: findCorrelatedErrorsInputShape,
};
export async function handleFindCorrelatedErrors(args, client) {
try {
const params = {
windowMinutes: args.windowMinutes,
limit: args.limit,
levels: args.level?.join(','),
serviceName: args.serviceName?.join(','),
};
const { data, elsRequestId } = await client.findCorrelatedErrors(args.traceId, params);
const meta = {
elsRequestId,
cached: false,
ttlSec: 60,
redactionApplied: false,
};
const result = (data ?? {});
const correlated = Array.isArray(result.correlated) ? result.correlated : [];
return {
structuredContent: { ...result, _meta: meta },
content: [
{
type: 'text',
text: `Found ${correlated.length} correlated errors within ±${args.windowMinutes}min of ${args.traceId}.`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=findCorrelatedErrors.js.map