Skip to main content
Glama
hunter-arton

Google Search MCP Server

by hunter-arton

google_image_search

Find and retrieve relevant images using Google's Custom Search API. Search by keywords, get image URLs, titles, and thumbnails to enhance visual reference or research tasks.

Instructions

Searches for images using Google's Custom Search API. Best for finding images related to specific terms, concepts, or objects. Returns image URLs, titles, and thumbnails. Use this when needing to find relevant images or visual references.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of results (1-10, default 5)
queryYesImage search query
startNoPagination start index (default 1)

Implementation Reference

  • The core handler function that performs the Google Custom Search API call for images, applies rate limiting, parses the response, and formats the results into a readable text output.
    async function performImageSearch(query: string, count: number = 5, start: number = 1) {
      checkRateLimit();
      
      const url = new URL('https://www.googleapis.com/customsearch/v1');
      url.searchParams.set('key', GOOGLE_API_KEY);
      url.searchParams.set('cx', GOOGLE_CSE_ID);
      url.searchParams.set('q', query);
      url.searchParams.set('num', Math.min(count, 10).toString());
      url.searchParams.set('start', start.toString());
      url.searchParams.set('searchType', 'image');
    
      const response = await fetch(url, {
        headers: {
          'Accept': 'application/json',
        }
      });
    
      if (!response.ok) {
        throw new Error(`Google API error: ${response.status} ${response.statusText}\n${await response.text()}`);
      }
    
      const data = await response.json() as GoogleImageSearchResult;
      
      if (data.error) {
        throw new Error(`Google API error: ${data.error.code} ${data.error.message}`);
      }
    
      if (!data.items || data.items.length === 0) {
        return "No image results found for your query.";
      }
    
      // Format the image results
      return data.items.map((item, index) => 
        `[${index + 1}] Title: ${item.title}\nDescription: ${item.snippet || 'No description'}\nImage URL: ${item.link}\n${item.image?.thumbnailLink ? `Thumbnail: ${item.image.thumbnailLink}` : ''}`
      ).join('\n\n');
    }
  • src/index.ts:45-72 (registration)
    Defines and registers the 'google_image_search' tool, including its name, description, and input schema for the MCP server.
    const IMAGE_SEARCH_TOOL: Tool = {
      name: "google_image_search",
      description:
        "Searches for images using Google's Custom Search API. " +
        "Best for finding images related to specific terms, concepts, or objects. " +
        "Returns image URLs, titles, and thumbnails. " +
        "Use this when needing to find relevant images or visual references.",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Image search query"
          },
          count: {
            type: "number",
            description: "Number of results (1-10, default 5)",
            default: 5
          },
          start: {
            type: "number",
            description: "Pagination start index (default 1)",
            default: 1
          },
        },
        required: ["query"]
      }
    };
  • TypeScript interface defining the structure of the Google Image Search API response.
    interface GoogleImageSearchResult {
      kind: string;
      items?: Array<{
        title: string;
        link: string;
        snippet: string;
        image?: {
          contextLink: string;
          height: number;
          width: number;
          thumbnailLink: string;
          thumbnailHeight: number;
          thumbnailWidth: number;
        };
      }>;
      error?: {
        code: number;
        message: string;
      };
    }
  • Type guard function for validating input arguments to the google_image_search tool.
    function isGoogleImageSearchArgs(args: unknown): args is { query: string; count?: number; start?: number } {
      return (
        typeof args === "object" &&
        args !== null &&
        "query" in args &&
        typeof (args as { query: string }).query === "string"
      );
    }
  • Dispatch case in the main CallToolRequestHandler that validates args and calls the performImageSearch handler.
    case "google_image_search": {
      if (!isGoogleImageSearchArgs(args)) {
        throw new Error("Invalid arguments for google_image_search");
      }
      const { query, count = 5, start = 1 } = args;
      const results = await performImageSearch(query, count, start);
      return {
        content: [{ type: "text", text: results }],
        isError: false,
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the API source and return values (image URLs, titles, thumbnails) but lacks details on rate limits, authentication needs, error handling, or whether this is a read-only operation. For a search tool with external API dependencies, this leaves significant behavioral gaps.

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 appropriately sized and front-loaded: it starts with the core purpose, adds context about best use cases, specifies return values, and ends with usage guidance. Every sentence adds value without redundancy, making it efficient and well-structured.

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 (external API search with 3 parameters) and no annotations or output schema, the description is partially complete. It covers purpose, usage, and returns but lacks behavioral details like rate limits or error handling. It's adequate for basic use but insufficient for robust agent operation without additional context.

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?

The schema description coverage is 100%, so the schema already documents all three parameters (count, query, start) with their types, defaults, and constraints. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high schema coverage.

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: 'Searches for images using Google's Custom Search API' with specific resources (image URLs, titles, thumbnails) and distinguishes it from the sibling google_web_search by focusing on images rather than general web content. However, it doesn't explicitly name the sibling for comparison.

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 provides implied usage guidance: 'Best for finding images related to specific terms, concepts, or objects' and 'Use this when needing to find relevant images or visual references.' It suggests when to use it but doesn't explicitly mention when not to use it or directly compare it to the sibling google_web_search.

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

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/hunter-arton/google_search_mcp_server'

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