fix empty error issue

This commit is contained in:
Kent Wang committed 2026-10-08 14:28:34 +08:00
1 parent 98f172fe89
commit 3ac6e38819
3 files changed
+10 -14

No files matched your search

+4 -12
View File
@@ -32,11 +32,11 @@ const incomingResult = (method: string, id: number, result: unknown): McpEvent =
data: { jsonrpc: '2.0', id, result },
}) as McpEvent;
const incomingErrorEvent = (id: number, message: string): McpEvent =>
const incomingErrorEvent = (id: number, title: string, message: string): McpEvent =>
({
...BASE,
type: 'error',
message,
message: title,
error: { code: -32_601, requestId: id, message },
}) as McpEvent;
@@ -87,17 +87,9 @@ describe('findLatestListResult', () => {
});
it('surfaces a JSON-RPC error response as an error', () => {
const events = [outgoing(METHOD_LIST_TOOLS, 1), incomingErrorEvent(1, 'Method not found')];
const events = [outgoing(METHOD_LIST_TOOLS, 1), incomingErrorEvent(1, 'Error', 'Method not found')];
expect(findLatestListResult(events, METHOD_LIST_TOOLS)).toEqual({ error: { title: 'Method not found' } });
});
it('falls back to a default message when the error event carries none', () => {
const events = [outgoing(METHOD_LIST_TOOLS, 1), incomingErrorEvent(1, '')];
expect(findLatestListResult(events, METHOD_LIST_TOOLS)).toEqual({
error: { title: `MCP server returned an error for ${METHOD_LIST_TOOLS}` },
});
expect(findLatestListResult(events, METHOD_LIST_TOOLS)).toEqual({ error: { title: 'Error: Method not found' } });
});
it('returns the result untouched when it matches the schema', () => {
+5 -1
View File
@@ -353,7 +353,11 @@ export const findLatestListResult = (mcpEvents: McpEvent[], method: string): Mcp
return undefined;
}
if (incomingEvent.type === 'error') {
return { error: { title: incomingEvent.message || `MCP server returned an error for ${method}` } };
return {
error: {
title: `${incomingEvent.message || 'Error'}: ${incomingEvent.error?.message || `MCP server returned an error for ${method}`}`,
},
};
}
if (incomingEvent.type !== 'message') {
return undefined;
@@ -69,7 +69,7 @@ const emptyPrimitiveErrors: Partial<Record<McpServerPrimitiveTypes, McpListValid
const ITEM_ROW_HEIGHT = 32;
// A whole-response failure has no per-entry breakdown, just a one-line title, so it needs far less
// room than a partial failure's scrollable list of dropped entries.
const ERROR_PANEL_HEIGHT_TITLE_ONLY = 80;
const ERROR_PANEL_HEIGHT_TITLE_ONLY = 100;
const ERROR_PANEL_HEIGHT_WITH_ENTRIES = 120;
const getErrorPanelHeight = (error: McpListValidationError | undefined): number =>