Skip to main content
Glama
nanameru

URL-Context-MCP MCP

by nanameru

google_search

Search the web using Google Search via Gemini API to find information with sources and citations. Process results with optional instructions for analysis.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query to find information on the web
instructionNoOptional instruction for processing search results
modelNoGemini model id (e.g., gemini-2.5-flash)

Implementation Reference

  • MCP CallTool request handler specifically for the 'google_search' tool. Extracts and validates input arguments, invokes the callGoogleSearch helper, and formats the response as MCP content.
    if (name === "google_search") {
      const {
        query,
        instruction,
        model,
      } = (args ?? {}) as {
        query?: string;
        instruction?: string;
        model?: string;
      };
      if (!query || typeof query !== "string" || query.trim() === "") {
        throw new Error("'query' must be provided as a non-empty string");
      }
      const text = await callGoogleSearch({
        query: query.trim(),
        instruction,
        model,
      });
      return { content: [{ type: "text", text }] };
    }
  • Helper function that executes the Google Search logic: builds a specialized prompt, calls the Gemini API with 'google_search' and 'url_context' tools enabled, processes the response to extract text output and appends search queries and source metadata.
    async function callGoogleSearch(params: GoogleSearchParams): Promise<string> {
      const apiKey = process.env.GOOGLE_API_KEY;
      if (!apiKey) {
        throw new Error("GOOGLE_API_KEY is not set");
      }
    
      const model = params.model ?? "gemini-2.5-flash";
      const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(model)}:generateContent`;
    
      const promptText = `Role: You are a meticulous web researcher.\n\nPrimary directive:\n- If the user provides explicit URLs in the request, SKIP web search and use URL Context to analyze ONLY those URLs.\n- Otherwise, perform grounded Google Search and for ANY URL you cite, you MUST fetch it via URL Context and synthesize findings.\n- Prefer authoritative, up-to-date sources.\n- If coverage is insufficient, refine the query and continue internally up to 5 rounds. Stop once adequate.\n\nTask:${params.instruction ? `\n${params.instruction}` : ``}\n\nResearch focus: ${params.query}`;
    
      const tools: any[] = [{ google_search: {} }, { url_context: {} }];
    
      const body = {
        contents: [
          {
            parts: [{ text: promptText }],
          },
        ],
        tools,
      } as const;
    
      const response = await fetch(endpoint + `?key=${encodeURIComponent(apiKey)}`, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify(body),
      });
    
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`Gemini API error ${response.status}: ${text}`);
      }
    
      const json = (await response.json()) as any;
      // Try to get the primary text output
      const candidate = json?.candidates?.[0];
      const textOut = candidate?.content?.parts?.map((p: any) => p?.text).filter(Boolean).join("\n");
      
      // Collect grounding metadata for search results
      const groundingMeta = candidate?.grounding_metadata;
      const searchQueries = groundingMeta?.web_search_queries || [];
      const groundingChunks = groundingMeta?.grounding_chunks || [];
      
      let sourcesSection = "";
      if (searchQueries.length > 0) {
        sourcesSection += "\n\nSearch Queries:\n" + searchQueries.map((q: string) => `- ${q}`).join("\n");
      }
      if (groundingChunks.length > 0) {
        sourcesSection += "\n\nSources (Google Search):\n" +
          groundingChunks
            .map((chunk: any) => `- ${chunk.web?.title || "(no title)"}: ${chunk.web?.uri || "(no URL)"})`)
            .join("\n");
      }
    
      if (textOut) {
        return textOut + sourcesSection;
      }
      // Fallback: return raw JSON if text not found
      return JSON.stringify(json, null, 2);
    }
  • src/index.ts:204-227 (registration)
    Registers the 'google_search' tool in the MCP tools list, including name, description, and input schema. This is returned in response to ListTools requests.
      {
        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 id (e.g., gemini-2.5-flash)",
            },
          },
          required: ["query"],
        },
      },
    ];
  • Input schema definition for the 'google_search' tool, specifying required 'query' parameter and optional 'instruction' and 'model'.
    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 id (e.g., gemini-2.5-flash)",
        },
      },
      required: ["query"],
    },
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 of behavioral disclosure. It mentions that the tool 'Provides search results with sources and citations,' which adds some context about output format. However, it lacks critical behavioral details such as rate limits, authentication requirements, error handling, or whether it's a read-only operation (though implied by 'Search'). For a tool with no annotations, this is insufficient.

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 highly concise and front-loaded: two sentences that directly state the tool's function and output. Every word earns its place, with no redundant or vague phrasing. It efficiently communicates the core purpose without unnecessary details.

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 three parameters) and lack of annotations and output schema, the description is minimally adequate. It covers the basic purpose and output format but misses behavioral context and usage guidelines. For a search tool without structured output documentation, it should ideally explain result structure 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 the schema already documents all three parameters (query, instruction, model) with descriptions. The description adds no parameter-specific semantics beyond what's in the schema. It implies the tool processes search results but doesn't elaborate on how parameters interact. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/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: 'Search the web using Google Search grounding via Gemini API.' It specifies the verb ('Search') and resource ('the web'), and mentions the mechanism ('via Gemini API'). However, it doesn't explicitly differentiate from its sibling tool 'analyze_urls' (which likely analyzes specific URLs rather than performing web searches).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'analyze_urls' or any other search-related tools, nor does it specify prerequisites, constraints, or typical use cases. The agent must infer usage from the purpose alone.

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/nanameru/url-context-mcp'

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