Skip to main content
Glama
tanamurayuuki

Gemini URL Context & Search MCP Server

google_search

Search the web using Google Search with Gemini API integration to retrieve information with sources and citations for research and verification purposes.

Instructions

Search the web using Google Search grounding via Gemini API. Provides search results with sources and citations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instructionNoOptional instruction for processing search results
modelNoGemini model name to use (optional, defaults to gemini-2.0-flash-exp)
queryYesSearch query to find information on the web

Implementation Reference

  • Core handler function that performs the Google Search by calling the Gemini API with grounding tools (google_search and url_context). This is the exact implementation executing the tool logic.
      async search(input: GoogleSearchInput): Promise<GoogleSearchResponse> {
        const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(input.model)}:generateContent`;
    
        const promptText = `Role: You are a meticulous web researcher.
    
    Primary directive:
    - Perform grounded Google Search and for ANY URL you cite, you MUST fetch it via URL Context and synthesize findings.
    - Prefer authoritative, up-to-date sources.
    - If coverage is insufficient, refine the query and continue internally up to 5 rounds. Stop once adequate.
    
    Task:${input.instruction ? `\n${input.instruction}` : ''}
    
    Research focus: ${input.query}`;
    
        const tools = [{ google_search: {} }, { url_context: {} }];
    
        const body = {
          contents: [
            {
              parts: [{ text: promptText }],
            },
          ],
          tools,
        };
    
        try {
          const response = await fetch(endpoint + `?key=${encodeURIComponent(this.apiKey)}`, {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify(body),
          });
    
          if (!response.ok) {
            const text = await response.text();
            this.mapAndThrowError(new Error(`Gemini API error ${response.status}: ${text}`));
          }
    
          const json = await response.json();
          return this.parseSearchResponse(json);
    
        } catch (error) {
          this.mapAndThrowError(error as Error);
          throw error; // This won't be reached due to mapAndThrowError throwing
        }
      }
  • Use case handler that prepares the input and delegates to the GoogleSearchGenAI implementation.
    export class GoogleSearchUseCase {
      constructor(private readonly googleSearchGenAI: GoogleSearchGenAI) {}
    
      async execute(
        query: string,
        instruction?: string,
        model?: ModelName
      ): Promise<GoogleSearchResponse> {
        const modelName = model || ModelName.create();
        
        const input: GoogleSearchInput = {
          query: query.trim(),
          instruction,
          model: modelName.toString()
        };
    
        return await this.googleSearchGenAI.search(input);
      }
  • MCP CallToolRequest handler dispatch for 'google_search' tool, including validation and response formatting.
    if (request.params.name === 'google_search') {
      try {
        const { query, instruction, model } = request.params.arguments as {
          query?: string;
          instruction?: string;
          model?: string;
        };
    
        if (!query || typeof query !== 'string' || query.trim() === '') {
          throw new McpError(
            ErrorCode.InvalidParams,
            'query must be a non-empty string'
          );
        }
    
        const modelName = model ? ModelName.create(model) : ModelName.create();
        const result = await this.googleSearchUseCase.execute(query.trim(), instruction, modelName);
    
        // Format response similar to other implementation
        let responseText = result.result;
        
        if (result.searchQueries.length > 0) {
          responseText += "\n\nSearch Queries:\n" + result.searchQueries.map(q => `- ${q}`).join("\n");
        }
        
        if (result.sources.length > 0) {
          responseText += "\n\nSources (Google Search):\n" +
            result.sources.map(source => `- ${source.title}: ${source.url}`).join("\n");
        }
    
        return {
          content: [
            {
              type: 'text',
              text: responseText,
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to perform Google search: ${(error as Error).message}`
        );
      }
  • Input schema definition for the 'google_search' tool as exposed in MCP ListTools response.
      name: 'google_search',
      description:
        'Search the web using Google Search grounding via Gemini API. Provides search results with sources and citations.',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query to find information on the web',
          },
          instruction: {
            type: 'string',
            description: 'Optional instruction for processing search results',
          },
          model: {
            type: 'string',
            description: 'Gemini model name to use (optional, defaults to gemini-2.0-flash-exp)',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:227-227 (registration)
    Initialization and registration of the GoogleSearchUseCase instance in the main server class.
    this.googleSearchUseCase = new GoogleSearchUseCase(googleSearchGenAI);
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions that the tool 'Provides search results with sources and citations,' which gives some behavioral context, but does not disclose critical traits such as rate limits, authentication needs, error handling, or pagination. For a web search tool with no annotations, this leaves significant gaps in understanding its operational behavior.

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 front-loaded and efficiently structured in two sentences: the first states the tool's purpose and method, and the second specifies the output. Every sentence adds value without redundancy, making it appropriately sized and easy to parse.

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

Completeness3/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 (web search with 3 parameters), no annotations, and no output schema, the description is partially complete. It covers the basic purpose and output format but lacks details on behavioral traits, error handling, and usage guidelines. This is adequate for a simple tool but has clear gaps in providing a full operational understanding.

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 the schema already documents all parameters (query, instruction, model) with descriptions. The description adds minimal value beyond the schema, as it does not provide additional syntax, format details, or usage examples for the parameters. Baseline 3 is appropriate when the schema handles most of the parameter documentation.

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 specific action ('Search the web') using a specific resource ('Google Search grounding via Gemini API') and distinguishes from the sibling tool 'url_context_extract' by focusing on web search rather than URL extraction. It specifies what the tool provides ('search results with sources and citations').

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

Usage Guidelines3/5

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

The description implies usage for web search tasks but does not explicitly state when to use this tool versus the sibling 'url_context_extract' or other alternatives. It provides basic context (searching the web) but lacks explicit guidance on exclusions or specific scenarios where this tool is preferred.

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/tanamurayuuki/MCP-URLcontext'

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