Skip to main content
Glama

search_google

Execute a Google search directly through the Google Toolbox MCP server to retrieve formatted results. Specify your query and number of results for precise, actionable data.

Instructions

Perform a Google search and return formatted results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
num_resultsNo
queryYes

Implementation Reference

  • The primary handler function for the 'search_google' tool. It is decorated with @mcp.tool which registers it, uses Google Custom Search API (requires GOOGLE_API_KEY and GOOGLE_CSE_ID env vars), performs the search, formats results with title/link/snippet, and returns structured dict with success flag.
    @mcp.tool(
        name="search_google",
        description="Perform a Google search and return formatted results",
    )
    async def search_google(query: str, num_results: int = 5) -> Dict[str, Any]:
        """
        Perform a Google search and return formatted results.
        
        This function uses Google Custom Search API to search the web based on the provided query.
        It formats the results into a consistent structure and handles potential errors.
        
        Args:
            query (str): The search query string
            num_results (int, optional): Number of search results to return. Defaults to 5.
            
        Returns:
            Dict[str, Any]: A dictionary containing:
                - success (bool): Whether the search was successful
                - results (list): List of dictionaries with title, link, and snippet
                - total_results (str): Total number of results found (when successful)
                - error (str): Error message (when unsuccessful)
        """
        try:
            # Initialize Google Custom Search API
            service = build("customsearch", "v1", developerKey=GOOGLE_API_KEY)
            
            # Execute the search
            # pylint: disable=no-member
            result = service.cse().list(
                q=query,
                cx=GOOGLE_CSE_ID,
                num=num_results
            ).execute()
            
            # Format the search results
            formatted_results = []
            if "items" in result:
                for item in result["items"]:
                    formatted_results.append({
                        "title": item.get("title", ""),
                        "link": item.get("link", ""),
                        "snippet": item.get("snippet", "")
                    })
            
            return {
                "success": True,
                "results": formatted_results,
                "total_results": result.get("searchInformation", {}).get("totalResults", "0")
            }
        
        except HttpError as error:
            logger.error(f"API 오류 발생: {error}")
            return {
                "success": False,
                "error": f"API Error: {str(error)}",
                "results": []
            }
        except Exception as error:  # pylint: disable=broad-exception-caught
            logger.error(f"예상치 못한 오류 발생: {error}")
            return {
                "success": False,
                "error": str(error),
                "results": []
            }
  • server.py:200-204 (registration)
    The 'search_google' tool is listed in the available_google_tools array returned by the get_available_google_tools resource, indicating it is one of the available tools on this MCP server.
    available_google_tools = [
        "list_emails", "search_emails", "send_email", "modify_email",
        "list_events", "create_event", "update_event", "delete_event",
        "search_google", "read_gdrive_file", "search_gdrive"
    ]

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

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/jikime/py-mcp-google-toolbox'

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