search_google
Perform Google searches via SearchAPI MCP Server by providing a query string. Retrieve formatted results including titles, snippets, and links, with options for pagination, sorting, and date filtering.
Instructions
Performs a Google search using SearchAPI.site. Requires a search "query" string, can be able to search multiple keywords that separated by commas. Returns formatted search results including titles, snippets, and links.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | No | Start date for filtering results (format: YYYY-MM-DD) | |
| limit | No | Maximum number of results to return (1-100) | |
| offset | No | Offset for pagination | |
| query | Yes | The search query to perform | |
| sort | No | Sort order (e.g., "date:d" for newest first) | |
| to_date | No | End date for filtering results (format: YYYY-MM-DD) |
Implementation Reference
- src/tools/searchapi.tool.ts:20-54 (handler)The MCP tool handler function that performs the core logic for the 'search_google' tool by mapping arguments to controller options, calling the search controller, and formatting the response for MCP protocol.async function handleGoogleSearch(args: GoogleSearchToolArgsType) { const methodLogger = Logger.forContext( 'tools/searchapi.tool.ts', 'handleGoogleSearch', ); methodLogger.debug(`Performing Google search for query: ${args.query}`); try { // Map tool arguments to controller options const controllerOptions = { query: args.query, }; // Call the controller with the mapped options const result = await searchApiController.googleSearch(controllerOptions); methodLogger.debug(`Got the response from the controller`, result); // Format the response for the MCP tool return { content: [ { type: 'text' as const, text: result.content, }, ], }; } catch (error) { methodLogger.error( `Error performing Google search for query: ${args.query}`, error, ); return formatErrorForMcpTool(error); } }
- src/tools/searchapi.tool.ts:160-168 (registration)Registration of the 'search_google' tool on the MCP server instance, specifying name, description, input schema, and handler function.server.tool( 'search_google', `Performs a Google search using SearchAPI.site. Requires a search "query" string, can be able to search multiple keywords that separated by commas. Returns formatted search results including titles, snippets, and links. `, GoogleSearchToolArgs.shape, handleGoogleSearch, );
- src/tools/searchapi.types.ts:11-33 (schema)Zod schema defining the input validation and types for the search_google tool arguments.export const GoogleSearchToolArgs = z.object({ query: z.string().describe('The search query to perform'), // apiKey: z.string().optional().describe('Your SearchAPI.site API key'), limit: z .number() .min(1) .max(100) .optional() .describe('Maximum number of results to return (1-100)'), offset: z.number().min(0).optional().describe('Offset for pagination'), sort: z .string() .optional() .describe('Sort order (e.g., "date:d" for newest first)'), from_date: z .string() .optional() .describe('Start date for filtering results (format: YYYY-MM-DD)'), to_date: z .string() .optional() .describe('End date for filtering results (format: YYYY-MM-DD)'), });