@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-запуска.
71 lines • 2.62 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: grouped_errors
* Mapping: GET /analytics/grouped-errors → analytics.routes.ts:329
* Upstream Zod: GroupedErrorsSchema (from, to, take, +фасет-фильтры).
*
* Список уникальных fingerprint'ов, отсортированных по count (default), с
* per-group stats: count, firstSeen, lastSeen, affectedUsers, exampleTraceId.
*
* sortBy не пробрасывается в upstream (ELS-endpoint его не принимает),
* но возвращается в structured-content для подсказки LLM.
*/
export const groupedErrorsInputShape = {
from: z.string().optional(),
to: z.string().optional(),
level: z.array(z.string().max(16)).optional(),
serviceName: z.array(z.string().max(255)).optional(),
take: z.number().int().min(1).max(100).default(20),
sortBy: z.enum(['count', 'lastSeen', 'affectedUsers']).default('count'),
};
export const groupedErrorsToolDef = {
name: 'grouped_errors',
title: 'Deduplicated error groups',
description: 'List of unique fingerprints sorted by occurrence, with per-group stats (count, firstSeen, lastSeen, affectedUsers, exampleTraceId). The "ranked list of all problems" view.',
inputShape: groupedErrorsInputShape,
};
export async function handleGroupedErrors(args, client) {
try {
const params = {
from: args.from,
to: args.to,
take: args.take,
levels: args.level?.join(','),
serviceName: args.serviceName?.join(','),
};
const { data, elsRequestId } = await client.groupedErrors(params);
const body = (data ?? {});
const items = Array.isArray(body.data)
? body.data
: Array.isArray(body.items)
? body.items
: [];
const meta = {
elsRequestId,
cached: false,
ttlSec: 60,
redactionApplied: false,
};
return {
structuredContent: {
items,
sortBy: args.sortBy,
nextCursor: null,
_meta: meta,
},
content: [
{
type: 'text',
text: `${items.length} grouped errors (take=${args.take}, sortBy=${args.sortBy}).`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=groupedErrors.js.map