ask_gemini
Query Google Gemini AI models to generate responses using customizable parameters like model type and temperature via the MCP AI Bridge server.
Instructions
Ask Google Gemini AI a question
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | The model to use (default: gemini-1.5-flash-latest) | gemini-1.5-flash-latest |
| prompt | Yes | The prompt to send to Gemini | |
| temperature | No | Temperature for response generation (0-1) |
Implementation Reference
- src/index.js:228-269 (handler)The handler function that executes the 'ask_gemini' tool: validates parameters, initializes the Gemini model, generates content from the prompt, handles the response, and manages errors.async handleGemini(args) { if (!this.gemini) { throw new ConfigurationError(ERROR_MESSAGES.GEMINI_NOT_CONFIGURED); } // Validate inputs const prompt = validatePrompt(args.prompt); const model = validateModel(args.model, 'GEMINI'); const temperature = validateTemperature(args.temperature, 'GEMINI'); try { if (process.env.NODE_ENV !== 'test') logger.debug(`Gemini request - model: ${model}, temperature: ${temperature}`); const geminiModel = this.gemini.getGenerativeModel({ model: model, generationConfig: { temperature: temperature, }, }); const result = await geminiModel.generateContent(prompt); const response = await result.response; const text = response.text(); return { content: [ { type: 'text', text: `🤖 GEMINI RESPONSE (${model}):\n\n${text}`, }, ], }; } catch (error) { if (error.message?.includes('quota')) { throw new APIError('Gemini quota exceeded. Please try again later.', 'Gemini'); } else if (error.message?.includes('API key')) { throw new ConfigurationError('Invalid Gemini API key'); } else { throw new APIError(`Gemini API error: ${error.message}`, 'Gemini'); } } }
- src/index.js:123-145 (schema)The input schema definition for the 'ask_gemini' tool, specifying parameters like prompt (required), model, and temperature with types, defaults, enums, and constraints.inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'The prompt to send to Gemini', }, model: { type: 'string', description: `The model to use (default: ${DEFAULTS.GEMINI.MODEL})`, enum: MODELS.GEMINI, default: DEFAULTS.GEMINI.MODEL, }, temperature: { type: 'number', description: `Temperature for response generation (${DEFAULTS.GEMINI.MIN_TEMPERATURE}-${DEFAULTS.GEMINI.MAX_TEMPERATURE})`, default: DEFAULTS.GEMINI.TEMPERATURE, minimum: DEFAULTS.GEMINI.MIN_TEMPERATURE, maximum: DEFAULTS.GEMINI.MAX_TEMPERATURE, }, }, required: ['prompt'], },
- src/index.js:119-147 (registration)Registration of the 'ask_gemini' tool in the list of available tools (this.tools), conditionally if Gemini client is configured, including name, description, and inputSchema.if (this.gemini) { tools.push({ name: 'ask_gemini', description: 'Ask Google Gemini AI a question', inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'The prompt to send to Gemini', }, model: { type: 'string', description: `The model to use (default: ${DEFAULTS.GEMINI.MODEL})`, enum: MODELS.GEMINI, default: DEFAULTS.GEMINI.MODEL, }, temperature: { type: 'number', description: `Temperature for response generation (${DEFAULTS.GEMINI.MIN_TEMPERATURE}-${DEFAULTS.GEMINI.MAX_TEMPERATURE})`, default: DEFAULTS.GEMINI.TEMPERATURE, minimum: DEFAULTS.GEMINI.MIN_TEMPERATURE, maximum: DEFAULTS.GEMINI.MAX_TEMPERATURE, }, }, required: ['prompt'], }, }); }
- src/index.js:176-177 (registration)Dispatch/registration in the switch statement within the CallToolRequestSchema handler that routes 'ask_gemini' calls to the handleGemini function.case 'ask_gemini': return await this.handleGemini(args);
- src/index.js:71-83 (helper)Initialization of the GoogleGenerativeAI client (this.gemini) required for the 'ask_gemini' tool, using GOOGLE_AI_API_KEY from environment.// Initialize Gemini client if (process.env.GOOGLE_AI_API_KEY) { try { this.gemini = new GoogleGenerativeAI(process.env.GOOGLE_AI_API_KEY); if (process.env.NODE_ENV !== 'test') logger.info('Gemini client initialized'); } catch (error) { if (process.env.NODE_ENV !== 'test') logger.error('Failed to initialize Gemini client:', error.message); this.gemini = null; } } else { this.gemini = null; if (process.env.NODE_ENV !== 'test') logger.warn('Google AI API key not provided'); }