Skip to main content
Glama
divslingerx

Memory Store MCP Server

by divslingerx

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
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • 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),
          },
        ],
      };
    });
  • 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
          },
        },
      ],
    }));
  • 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
    },
Install Server

Other 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