forked from google-gemini/gemini-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMcpStatus.tsx
More file actions
370 lines (349 loc) · 12.8 KB
/
McpStatus.tsx
File metadata and controls
370 lines (349 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { MCPServerStatus, type MCPServerConfig } 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,
JsonMcpPrompt,
JsonMcpResource,
JsonMcpSkill,
JsonMcpTool,
} from '../../types.js';
interface McpStatusProps {
servers: Record<string, MCPServerConfig>;
tools: JsonMcpTool[];
prompts: JsonMcpPrompt[];
resources: JsonMcpResource[];
skills?: JsonMcpSkill[];
blockedServers: Array<{ name: string; extensionName: string }>;
serverStatus: (serverName: string) => MCPServerStatus;
authStatus: HistoryItemMcpStatus['authStatus'];
enablementState: HistoryItemMcpStatus['enablementState'];
errors: Record<string, string>;
discoveryInProgress: boolean;
connectingServers: string[];
showDescriptions: boolean;
showSchema: boolean;
}
export const McpStatus: React.FC<McpStatusProps> = ({
servers,
tools,
prompts,
resources,
skills = [],
blockedServers,
serverStatus,
authStatus,
enablementState,
errors,
discoveryInProgress,
connectingServers,
showDescriptions,
showSchema,
}) => {
const serverNames = Object.keys(servers).filter(
(serverName) =>
!blockedServers.some(
(blockedServer) => blockedServer.name === serverName,
),
);
if (serverNames.length === 0 && blockedServers.length === 0) {
return (
<Box flexDirection="column">
<Text>No MCP servers configured.</Text>
<Text>
Please view MCP documentation in your browser:{' '}
<Text color={theme.text.link}>
https://goo.gle/gemini-cli-docs-mcp
</Text>{' '}
or use the cli /docs command
</Text>
</Box>
);
}
return (
<Box flexDirection="column">
{discoveryInProgress && (
<Box flexDirection="column" marginBottom={1}>
<Text color={theme.status.warning}>
⏳ MCP servers are starting up ({connectingServers.length}{' '}
initializing)...
</Text>
<Text color={theme.text.primary}>
Note: First startup may take longer. Tool availability will update
automatically.
</Text>
</Box>
)}
<Text bold>Configured MCP servers:</Text>
<Box height={1} />
{serverNames.map((serverName) => {
const server = servers[serverName];
const serverTools = tools.filter(
(tool) => tool.serverName === serverName,
);
const serverPrompts = prompts.filter(
(prompt) => prompt.serverName === serverName,
);
const serverResources = resources.filter(
(resource) => resource.serverName === serverName,
);
const serverSkills = skills.filter(
(skill) => skill.serverName === serverName,
);
const originalStatus = serverStatus(serverName);
const hasCachedItems =
serverTools.length > 0 ||
serverPrompts.length > 0 ||
serverResources.length > 0 ||
serverSkills.length > 0;
const status =
originalStatus === MCPServerStatus.DISCONNECTED && hasCachedItems
? MCPServerStatus.CONNECTED
: originalStatus;
let statusIndicator = '';
let statusText = '';
let statusColor = theme.text.primary;
// Check enablement state
const serverEnablement = enablementState[serverName];
const isDisabled = serverEnablement && !serverEnablement.enabled;
if (isDisabled) {
statusIndicator = '⏸️';
statusText = serverEnablement.isSessionDisabled
? 'Disabled (session)'
: 'Disabled';
statusColor = theme.text.secondary;
} else {
switch (status) {
case MCPServerStatus.CONNECTED:
statusIndicator = '🟢';
statusText = 'Ready';
statusColor = theme.status.success;
break;
case MCPServerStatus.CONNECTING:
statusIndicator = '🔄';
statusText = 'Starting... (first startup may take longer)';
statusColor = theme.status.warning;
break;
case MCPServerStatus.DISCONNECTED:
default:
statusIndicator = '🔴';
statusText = 'Disconnected';
statusColor = theme.status.error;
break;
}
}
let serverDisplayName = serverName;
if (server.extension?.name) {
serverDisplayName += ` (from ${server.extension?.name})`;
}
const toolCount = serverTools.length;
const promptCount = serverPrompts.length;
const resourceCount = serverResources.length;
const parts = [];
if (toolCount > 0) {
parts.push(`${toolCount} ${toolCount === 1 ? 'tool' : 'tools'}`);
}
if (promptCount > 0) {
parts.push(
`${promptCount} ${promptCount === 1 ? 'prompt' : 'prompts'}`,
);
}
if (resourceCount > 0) {
parts.push(
`${resourceCount} ${resourceCount === 1 ? 'resource' : 'resources'}`,
);
}
const skillCount = serverSkills.length;
if (skillCount > 0) {
parts.push(`${skillCount} ${skillCount === 1 ? 'skill' : 'skills'}`);
}
const serverAuthStatus = authStatus[serverName];
let authStatusNode: React.ReactNode = null;
if (serverAuthStatus === 'authenticated') {
authStatusNode = <Text> (OAuth)</Text>;
} else if (serverAuthStatus === 'expired') {
authStatusNode = (
<Text color={theme.status.error}> (OAuth expired)</Text>
);
} else if (serverAuthStatus === 'unauthenticated') {
authStatusNode = (
<Text color={theme.status.warning}> (OAuth not authenticated)</Text>
);
}
return (
<Box key={serverName} flexDirection="column" marginBottom={1}>
<Box>
<Text color={statusColor}>{statusIndicator} </Text>
<Text bold>{serverDisplayName}</Text>
<Text>
{' - '}
{statusText}
{status === MCPServerStatus.CONNECTED &&
parts.length > 0 &&
` (${parts.join(', ')})`}
</Text>
{authStatusNode}
</Box>
{status === MCPServerStatus.CONNECTING && (
<Text> (tools and prompts will appear when ready)</Text>
)}
{status === MCPServerStatus.DISCONNECTED && toolCount > 0 && (
<Text> ({toolCount} tools cached)</Text>
)}
{errors[serverName] && (
<Box marginLeft={2}>
<Text color={theme.status.error}>
Error: {errors[serverName]}
</Text>
</Box>
)}
{showDescriptions && server?.description && (
<Text color={theme.text.secondary}>
{server.description.trim()}
</Text>
)}
{serverTools.length > 0 && (
<Box flexDirection="column" marginLeft={2}>
<Text color={theme.text.primary}>Tools:</Text>
{serverTools.map((tool) => {
const schemaContent =
showSchema &&
tool.schema &&
(tool.schema.parametersJsonSchema || tool.schema.parameters)
? JSON.stringify(
tool.schema.parametersJsonSchema ??
tool.schema.parameters,
null,
2,
)
: null;
return (
<Box key={tool.name} flexDirection="column">
<Text>
- <Text color={theme.text.primary}>{tool.name}</Text>
</Text>
{showDescriptions && tool.description && (
<Box marginLeft={2}>
<Text color={theme.text.secondary}>
{tool.description.trim()}
</Text>
</Box>
)}
{schemaContent && (
<Box flexDirection="column" marginLeft={4}>
<Text color={theme.text.secondary}>Parameters:</Text>
<Text color={theme.text.secondary}>
{schemaContent}
</Text>
</Box>
)}
</Box>
);
})}
</Box>
)}
{serverPrompts.length > 0 && (
<Box flexDirection="column" marginLeft={2}>
<Text color={theme.text.primary}>Prompts:</Text>
{serverPrompts.map((prompt) => (
<Box key={prompt.name} flexDirection="column">
<Text>
- <Text color={theme.text.primary}>{prompt.name}</Text>
</Text>
{showDescriptions && prompt.description && (
<Box marginLeft={2}>
<Text color={theme.text.primary}>
{prompt.description.trim()}
</Text>
</Box>
)}
</Box>
))}
</Box>
)}
{serverResources.length > 0 && (
<Box flexDirection="column" marginLeft={2}>
<Text color={theme.text.primary}>Resources:</Text>
{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>
)}
{serverSkills.length > 0 && (
<Box flexDirection="column" marginLeft={2}>
<Text color={theme.text.primary}>
Skills (io.modelcontextprotocol/skills):
</Text>
{serverSkills.map((skill) => (
<Box key={skill.name} flexDirection="column">
<Text>
- <Text color={theme.text.primary}>{skill.name}</Text>
<Text
color={theme.text.secondary}
>{` (${skill.uri})`}</Text>
</Text>
{showDescriptions && skill.description && (
<Box marginLeft={2}>
<Text color={theme.text.secondary}>
{skill.description.trim()}
</Text>
</Box>
)}
</Box>
))}
</Box>
)}
</Box>
);
})}
{blockedServers.map((server) => (
<Box key={server.name} marginBottom={1}>
<Text color={theme.status.error}>🔴 </Text>
<Text bold>
{server.name}
{server.extensionName ? ` (from ${server.extensionName})` : ''}
</Text>
<Text> - Blocked</Text>
</Box>
))}
</Box>
);
};