Added /mcp command support and cleaned up broken tests (#817)

This commit is contained in:
Bryan Morgan
2025-06-07 15:06:18 -04:00
committed by GitHub
parent 6ea4479064
commit 28ff62e7b1
9 changed files with 449 additions and 33 deletions

View File

@@ -9,7 +9,7 @@ import { type PartListUnion } from '@google/genai';
import open from 'open';
import process from 'node:process';
import { UseHistoryManagerReturn } from './useHistoryManager.js';
import { Config } from '@gemini-code/core';
import { Config, MCPServerStatus, getMCPServerStatus } from '@gemini-code/core';
import { Message, MessageType, HistoryItemWithoutId } from '../types.js';
import { createShowMemoryAction } from './useShowMemoryCommand.js';
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
@@ -137,10 +137,75 @@ export const useSlashCommandProcessor = (
openThemeDialog();
},
},
{
name: 'mcp',
description: 'list configured MCP servers and tools',
action: async (_mainCommand, _subCommand, _args) => {
const toolRegistry = await config?.getToolRegistry();
if (!toolRegistry) {
addMessage({
type: MessageType.ERROR,
content: 'Could not retrieve tool registry.',
timestamp: new Date(),
});
return;
}
const mcpServers = config?.getMcpServers() || {};
const serverNames = Object.keys(mcpServers);
if (serverNames.length === 0) {
addMessage({
type: MessageType.INFO,
content: 'No MCP servers configured.',
timestamp: new Date(),
});
return;
}
let message = 'Configured MCP servers and tools:\n\n';
for (const serverName of serverNames) {
const serverTools = toolRegistry.getToolsByServer(serverName);
const status = getMCPServerStatus(serverName);
// Add status indicator
let statusDot = '';
switch (status) {
case MCPServerStatus.CONNECTED:
statusDot = '🟢'; // Green dot for connected
break;
case MCPServerStatus.CONNECTING:
statusDot = '🟡'; // Yellow dot for connecting
break;
case MCPServerStatus.DISCONNECTED:
default:
statusDot = '🔴'; // Red dot for disconnected
break;
}
message += `${statusDot} ${serverName} (${serverTools.length} tools):\n`;
if (serverTools.length > 0) {
serverTools.forEach((tool) => {
message += ` - ${tool.name}\n`;
});
} else {
message += ' No tools available\n';
}
message += '\n';
}
addMessage({
type: MessageType.INFO,
content: message,
timestamp: new Date(),
});
},
},
{
name: 'memory',
description:
'Manage memory. Usage: /memory <show|refresh|add> [text for add]',
'manage memory. Usage: /memory <show|refresh|add> [text for add]',
action: (mainCommand, subCommand, args) => {
switch (subCommand) {
case 'show':
@@ -163,7 +228,7 @@ export const useSlashCommandProcessor = (
},
{
name: 'tools',
description: 'list available tools',
description: 'list available Gemini CLI tools',
action: async (_mainCommand, _subCommand, _args) => {
const toolRegistry = await config?.getToolRegistry();
const tools = toolRegistry?.getAllTools();
@@ -175,10 +240,14 @@ export const useSlashCommandProcessor = (
});
return;
}
const toolList = tools.map((tool) => tool.name);
// Filter out MCP tools by checking if they have a serverName property
const geminiTools = tools.filter((tool) => !('serverName' in tool));
const geminiToolList = geminiTools.map((tool) => tool.name);
addMessage({
type: MessageType.INFO,
content: `Available tools:\n\n${toolList.join('\n')}`,
content: `Available Gemini CLI tools:\n\n${geminiToolList.join('\n')}`,
timestamp: new Date(),
});
},
@@ -191,7 +260,7 @@ export const useSlashCommandProcessor = (
},
{
name: 'about',
description: 'Show version info',
description: 'show version info',
action: (_mainCommand, _subCommand, _args) => {
const osVersion = process.platform;
let sandboxEnv = 'no sandbox';
@@ -214,7 +283,7 @@ export const useSlashCommandProcessor = (
},
{
name: 'bug',
description: 'Submit a bug report.',
description: 'submit a bug report',
action: (_mainCommand, _subCommand, args) => {
let bugDescription = _subCommand || '';
if (args) {