chore: limit MCP resources display to 10 by default (#15489)

This commit is contained in:
Jack Wotherspoon
2025-12-23 14:39:35 -05:00
committed by GitHub
parent b6b0727e28
commit 5f28614760
3 changed files with 52 additions and 22 deletions

View File

@@ -184,4 +184,18 @@ describe('McpStatus', () => {
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('truncates resources when exceeding limit', () => {
const manyResources = Array.from({ length: 25 }, (_, i) => ({
serverName: 'server-1',
name: `resource-${i + 1}`,
uri: `file:///tmp/resource-${i + 1}.txt`,
}));
const { lastFrame, unmount } = render(
<McpStatus {...baseProps} resources={manyResources} />,
);
expect(lastFrame()).toContain('15 resources hidden');
unmount();
});
});

View File

@@ -8,6 +8,7 @@ import type { MCPServerConfig } from '@google/gemini-cli-core';
import { MCPServerStatus } from '@google/gemini-cli-core';
import { Box, Text } from 'ink';
import type React from 'react';
import { MAX_MCP_RESOURCES_TO_SHOW } from '../../constants.js';
import { theme } from '../../semantic-colors.js';
import type {
HistoryItemMcpStatus,
@@ -251,28 +252,40 @@ export const McpStatus: React.FC<McpStatusProps> = ({
{serverResources.length > 0 && (
<Box flexDirection="column" marginLeft={2}>
<Text color={theme.text.primary}>Resources:</Text>
{serverResources.map((resource, index) => {
const label = resource.name || resource.uri || 'resource';
return (
<Box
key={`${resource.serverName}-resource-${index}`}
flexDirection="column"
>
<Text>
- <Text color={theme.text.primary}>{label}</Text>
{resource.uri ? ` (${resource.uri})` : ''}
{resource.mimeType ? ` [${resource.mimeType}]` : ''}
</Text>
{showDescriptions && resource.description && (
<Box marginLeft={2}>
<Text color={theme.text.secondary}>
{resource.description.trim()}
</Text>
</Box>
)}
</Box>
);
})}
{serverResources
.slice(0, MAX_MCP_RESOURCES_TO_SHOW)
.map((resource, index) => {
const label = resource.name || resource.uri || 'resource';
return (
<Box
key={`${resource.serverName}-resource-${index}`}
flexDirection="column"
>
<Text>
- <Text color={theme.text.primary}>{label}</Text>
{resource.uri ? ` (${resource.uri})` : ''}
{resource.mimeType ? ` [${resource.mimeType}]` : ''}
</Text>
{showDescriptions && resource.description && (
<Box marginLeft={2}>
<Text color={theme.text.secondary}>
{resource.description.trim()}
</Text>
</Box>
)}
</Box>
);
})}
{serverResources.length > MAX_MCP_RESOURCES_TO_SHOW && (
<Text color={theme.text.secondary}>
{' '}...{' '}
{serverResources.length - MAX_MCP_RESOURCES_TO_SHOW}{' '}
{serverResources.length - MAX_MCP_RESOURCES_TO_SHOW === 1
? 'resource'
: 'resources'}{' '}
hidden
</Text>
)}
</Box>
)}
</Box>

View File

@@ -25,3 +25,6 @@ export const TOOL_STATUS = {
CANCELED: '-',
ERROR: 'x',
} as const;
// Maximum number of MCP resources to display per server before truncating
export const MAX_MCP_RESOURCES_TO_SHOW = 10;