gemini-mcp-tool
Version:
MCP server for Gemini CLI integration
36 lines • 2.28 kB
JavaScript
import { z } from 'zod';
import { executeGeminiCLI, processChangeModeOutput } from '../utils/geminiExecutor.js';
import { ERROR_MESSAGES, STATUS_MESSAGES } from '../constants.js';
const askGeminiArgsSchema = z.object({
prompt: z.string().min(1).describe("Analysis request. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions"),
model: z.string().optional().describe("Optional model to use (e.g., 'gemini-2.5-flash'). If not specified, uses the default model (gemini-2.5-pro)."),
sandbox: z.boolean().default(false).describe("Use sandbox mode (-s flag) to safely test code changes, execute scripts, or run potentially risky operations in an isolated environment"),
changeMode: z.boolean().default(false).describe("Enable structured change mode - formats prompts to prevent tool errors and returns structured edit suggestions that Claude can apply directly"),
chunkIndex: z.union([z.number(), z.string()]).optional().describe("Which chunk to return (1-based)"),
chunkCacheKey: z.string().optional().describe("Optional cache key for continuation"),
});
export const askGeminiTool = {
name: "ask-gemini",
description: "model selection [-m], sandbox [-s], and changeMode:boolean for providing edits",
zodSchema: askGeminiArgsSchema,
prompt: {
description: "Execute 'gemini -p <prompt>' to get Gemini AI's response. Supports enhanced change mode for structured edit suggestions.",
},
category: 'gemini',
execute: async (args, onProgress) => {
const { prompt, model, sandbox, changeMode, chunkIndex, chunkCacheKey } = args;
if (!prompt?.trim()) {
throw new Error(ERROR_MESSAGES.NO_PROMPT_PROVIDED);
}
if (changeMode && chunkIndex && chunkCacheKey) {
return processChangeModeOutput('', // empty for cache...
chunkIndex, chunkCacheKey, prompt);
}
const result = await executeGeminiCLI(prompt, model, !!sandbox, !!changeMode, onProgress);
if (changeMode) {
return processChangeModeOutput(result, args.chunkIndex, undefined, prompt);
}
return `${STATUS_MESSAGES.GEMINI_RESPONSE}\n${result}`; // changeMode false
}
};
//# sourceMappingURL=ask-gemini.tool.js.map