Skip to main content
Glama
georgejeffers

Gemini MCP Server

generate_with_search

Generate text responses grounded in current Google Search results to provide up-to-date, cited information for user queries.

Instructions

Generate text with Google Search grounding for up-to-date, cited responses.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe prompt to search and answer
modelNoGemini model to usegemini-2.5-flash
temperatureNoSampling temperature
maxOutputTokensNoMaximum output tokens

Implementation Reference

  • Main implementation of generate_with_search tool. Contains the register function that defines the tool with its schema, annotations, and the async handler function that calls Google GenAI's generateContent with Google Search grounding.
    export function register(server: McpServer, ai: GoogleGenAI): void { server.registerTool( 'generate_with_search', { title: 'Generate with Search', description: 'Generate text with Google Search grounding for up-to-date, cited responses.', inputSchema: { prompt: z.string().min(1).describe('The prompt to search and answer'), model: TextModel.default('gemini-2.5-flash').describe('Gemini model to use'), temperature: z.number().min(0).max(2).optional().describe('Sampling temperature'), maxOutputTokens: z.number().min(1).optional().describe('Maximum output tokens'), }, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true, }, }, async ({ prompt, model, temperature, maxOutputTokens }) => { try { const response = await ai.models.generateContent({ model, contents: prompt, config: { temperature, maxOutputTokens, tools: [{ googleSearch: {} }], }, }); return { content: [{ type: 'text' as const, text: response.text ?? '' }] }; } catch (error) { return formatToolError(error); } }, ); }
  • TextModel schema definition used by generate_with_search tool's input validation. Defines the allowed Gemini model options for text generation.
    export const TextModel = z.enum([ 'gemini-2.5-flash', 'gemini-2.5-pro', 'gemini-3-flash-preview', 'gemini-3-pro-preview', 'gemini-3.1-pro-preview', ]); export type TextModel = z.infer<typeof TextModel>;
  • src/index.ts:6-27 (registration)
    Registration of generate_with_search tool. Imports the register function and calls it to register the tool with the MCP server instance.
    import { register as registerGenerateWithSearch } from './tools/generate-with-search.js'; import { register as registerCodeExecution } from './tools/code-execution.js'; import { register as registerGenerateImage } from './tools/generate-image.js'; import { register as registerEditImage, registerMulti as registerEditImageMulti } from './tools/edit-image.js'; const GEMINI_API_KEY = process.env.GEMINI_API_KEY; if (!GEMINI_API_KEY) { console.error('GEMINI_API_KEY environment variable is required'); process.exit(1); } const ai = createClient(GEMINI_API_KEY); const server = new McpServer( { name: 'gemini', version: '2.0.0' }, { capabilities: { logging: {} } }, ); // Register all 7 tools registerGenerateText(server, ai); registerChat(server, ai); registerGenerateWithSearch(server, ai);
  • Utility function used by generate_with_search handler to format errors consistently. Called in the catch block to return error responses.
    export function formatToolError(error: unknown) { const text = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text' as const, text }], isError: true, }; }

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/georgejeffers/gemini-mcp-server'

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