Skip to main content
Glama
georgejeffers

Gemini MCP Server

Generate with Search

generate_with_search
Read-only

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,
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, openWorldHint=true, and destructiveHint=false, covering the safety and scope profile. The description adds useful context about search grounding and citation behavior, but doesn't elaborate on rate limits, authentication needs, or what specific search results are used. With annotations providing core behavioral traits, the description adds moderate value.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. Every word earns its place: 'Generate text' establishes the action, 'with Google Search grounding' specifies the method, and 'for up-to-date, cited responses' explains the value proposition. There's zero waste or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (search-augmented generation) and rich annotations covering safety and scope, the description is reasonably complete. It explains the search grounding and citation aspects well. The main gap is the lack of output schema, but the description doesn't need to explain return values. It could benefit from more detail about search behavior or limitations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are well-documented in the schema itself. The description doesn't add any parameter-specific information beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even without parameter details in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Generate text') and resources ('with Google Search grounding'), distinguishing it from siblings like generate_text by emphasizing search-based, cited responses. It explicitly mentions the key differentiator of providing 'up-to-date, cited responses' which sets it apart from basic text generation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('for up-to-date, cited responses'), implying it should be used when current information or citations are needed. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools, though the context suggests it's preferred over generate_text for factual queries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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