@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-запуска.
70 lines • 2.37 kB
JavaScript
import { z } from 'zod';
import { ToolError } from '../lib/errors.js';
/**
* Tool: top_error_messages
* Mapping: GET /analytics/top-messages → analytics.routes.ts:302
* Upstream Zod: TopMessagesSchema (take, from, to, +filters).
*
* Defaults: take=20.
*/
export const topErrorMessagesInputShape = {
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),
dedupeBy: z.enum(['message', 'fingerprint']).default('fingerprint'),
};
export const topErrorMessagesToolDef = {
name: 'top_error_messages',
title: 'Top error messages by occurrence',
description: [
'Returns most-frequent error messages (deduplicated) for a given period.',
'',
'WHEN TO USE:',
' - Onboarding a new service - answer "what hurts most right now?".',
' - Weekly / daily reports - top offenders to prioritise fixes.',
' - Pre-merge sanity check - did this branch add any new top-message?',
].join('\n'),
inputShape: topErrorMessagesInputShape,
};
export async function handleTopErrorMessages(args, client) {
try {
const params = {
take: args.take,
from: args.from,
to: args.to,
levels: args.level?.join(','),
serviceName: args.serviceName?.join(','),
};
const { data, elsRequestId } = await client.topErrorMessages(params);
const meta = {
elsRequestId,
cached: false,
ttlSec: 60,
redactionApplied: false,
};
const items = Array.isArray(data?.data) ? data.data : [];
return {
structuredContent: {
take: args.take,
data: items,
dedupeBy: args.dedupeBy,
nextCursor: null,
_meta: meta,
},
content: [
{
type: 'text',
text: `Top ${items.length} error message groups (dedupeBy=${args.dedupeBy}).`,
},
],
};
}
catch (err) {
if (err instanceof ToolError)
return err.toToolResult();
throw err;
}
}
//# sourceMappingURL=topErrorMessages.js.map