Skip to main content
Glama

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
NameRequiredDescriptionDefault
modelNoThe model to use (default: gemini-1.5-flash-latest)gemini-1.5-flash-latest
promptYesThe prompt to send to Gemini
temperatureNoTemperature for response generation (0-1)

Implementation Reference

  • 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'); } } }
  • 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);
  • 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'); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fakoli/mcp-ai-bridge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server