search_web
Perform web searches via Google to retrieve structured JSON results for integration with MCP-enabled systems.
Instructions
Search the web using Google
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query |
Implementation Reference
- src/memory-store.ts:75-141 (handler)MCP CallToolRequestSchema handler that validates the tool name 'search_web', launches Puppeteer browser if needed, navigates to Google search, extracts top results (titles and URLs), and returns them as formatted JSON text content.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { // Validate requested tool name if (request.params.name !== "search_web") { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } // Initialize Puppeteer browser if not already running if (!this.browser) { this.browser = await puppeteer.launch(); } // Create new browser page const page = await this.browser.newPage(); // Validate request arguments if ( !request.params.arguments || typeof request.params.arguments !== "object" ) { throw new McpError( ErrorCode.InvalidParams, "Invalid arguments provided" ); } const args = request.params.arguments; if ( !args || typeof args !== "object" || !("query" in args) || typeof args.query !== "string" ) { throw new McpError( ErrorCode.InvalidParams, "Query parameter is required and must be a string" ); } // Perform Google search using Puppeteer await page.goto( `https://www.google.com/search?q=${encodeURIComponent(args.query)}` ); // Extract search results from page const results = await page.evaluate(() => { return Array.from(document.querySelectorAll("h3")).map((el) => ({ title: el.textContent, url: el.closest("a")?.href, })); }); // Clean up browser page await page.close(); // Return results as JSON return { content: [ { type: "text", text: JSON.stringify(results, null, 2), }, ], }; });
- src/memory-store.ts:55-72 (registration)Tool registration in ListToolsRequestSchema handler, defining 'search_web' tool with description and input schema requiring a 'query' string.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: "search_web", // Tool name description: "Search the web using Google", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, }, required: ["query"], // Query parameter is mandatory }, }, ], }));
- src/memory-store.ts:60-69 (schema)Input schema for 'search_web' tool, specifying an object with required 'query' string property.inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, }, required: ["query"], // Query parameter is mandatory },