Skip to main content
Glama

Memory Store MCP Server

by divslingerx

search_web

Execute web searches via Google using a lightweight, stateless MCP server. Input a query to retrieve structured JSON results, enabling easy integration with MCP-enabled systems.

Instructions

Search the web using Google

Input Schema

NameRequiredDescriptionDefault
queryYesSearch query

Input Schema (JSON Schema)

{ "properties": { "query": { "description": "Search query", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • The MCP CallToolRequest handler for 'search_web' tool execution. Validates tool name and arguments, uses Puppeteer to perform Google search, extracts h3 titles and links, returns JSON stringified results.
    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), }, ], }; });
  • Registers the 'search_web' tool via ListToolsRequestSchema handler, including name, description, and input schema.
    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 }, }, ], }));
  • Type interface for individual search results (title and url), matching the structure extracted by the handler.
    interface SearchResult { title: string | null; // Title of the search result url: string | undefined; // URL of the search result }

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/divslingerx/mcp-server'

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