feat: add search_google_images MCP tool with SerpAPI integration
Merged
SI
8mo ago+436+436+012345678901234567890123456789-2-2-0123456789
Problem
Google Images tool (search_google_images) was not working because it was never registered in the API's MCP server.
The tool was defined in the chat project (chat/lib/tools/searchGoogleImages.ts) and listed in chat/lib/tools/getMcpTools.ts, but that file was dead code — never imported anywhere. Since the actual tool serving happens via the API's MCP server, the tool simply didn't exist in the active tool set.
Solution
Created the SerpAPI integration in the API project and registered the tool:
lib/serpapi/config.ts— SerpAPI URL constant and API key retrievallib/serpapi/types.ts— TypeScript interfaces for SerpAPI responseslib/serpapi/searchGoogleImages.ts— Fetch function for Google Images via SerpAPIlib/mcp/tools/registerSearchGoogleImagesTool.ts— MCP tool registrationlib/mcp/tools/index.ts— Added registration call
Tests
9 test cases covering:
- Tool registration
- Successful image search with result mapping
- Passing search options through
- Default limit behavior
- Empty and undefined results handling
- Error handling (API errors and non-Error exceptions)
Note
Ensure SERPAPI_API_KEY is set in the API project's environment variables (should already exist in the chat project's env).
Follow-up
The following dead code in the chat project can be cleaned up in a separate PR:
chat/lib/tools/getMcpTools.ts(never imported)chat/lib/tools/searchGoogleImages.ts(only imported by dead getMcpTools)chat/lib/serpapi/*(only imported by dead searchGoogleImages tool)
Summary by CodeRabbit
-
New Features
- Google Images search with filters for size, type, aspect ratio, pagination, and result limiting.
- Results include rich image metadata: thumbnail and original URLs, dimensions, title, source, and ordered positions.
- Enforced configuration check for the external image search API key with clear error guidance.
-
Refactor
- Consolidated search tool registration into a single, modular registration entry for easier management.