Skip to main content
Glama
saidsef

GitHub PR Issue Analyser

by saidsef

get_ipv4_info

Retrieve IPv4 address information for network analysis and troubleshooting in GitHub repository management workflows.

Instructions

Get information about an IPv4 address. :return: A dictionary containing the IPv4 information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the get_ipv4_info tool. It fetches IPv4 information from the configured API endpoint (default: https://ipinfo.io/json) using an HTTP GET request and returns the JSON data or an error dictionary.
    def get_ipv4_info(self) -> Dict[str, Any]:
        """
        Get information about an IPv4 address.
        :return: A dictionary containing the IPv4 information.
        """
        try:
            ipv4 = self.get_info(self.ipv4_api_url)
            if not ipv4:
                logging.error("No IPv4 information found.")
                return {}
            return ipv4
        except requests.RequestException as e:
            logging.error(f"Error fetching IPv4 info: {e}")
            logging.debug(e)
            traceback.print_exc()
            return {"error": str(e)}
  • Dynamic registration of tools from IPIntegration (self.ip) instance. The register_tools method iterates over public methods of the instance and adds them to the MCP server using mcp.add_tool, including get_ipv4_info.
    def _register_tools(self):
        self.register_tools(self.gi)
        self.register_tools(self.ip)
    
    def register_tools(self, methods: Any = None) -> None:
        for name, method in inspect.getmembers(methods):
            if (inspect.isfunction(method) or inspect.ismethod(method)) and not name.startswith("_"):
                self.mcp.add_tool(method)
  • Instantiation of the IPIntegration class instance (self.ip) whose methods are registered as MCP tools.
    self.gi = GI()
    self.ip = IP()
  • Import of the IPIntegration class containing the get_ipv4_info handler.
    from .ip_integration import IPIntegration as IP
  • Helper method used by get_ipv4_info to perform the HTTP request and handle errors.
    def get_info(self, url: str) -> Dict[str, Any]:
      """
      Fetches information from the specified URL using an HTTP GET request.
      Args:
          url (str): The URL to send the GET request to.
      Returns:
          Dict[str, Any]: The JSON response parsed into a dictionary if the request is successful.
          Returns an empty dictionary if the request fails or an exception occurs.
      Error Handling:
          Logs an error message and stack trace if a requests.RequestException is raised during the HTTP request.
      """
        
      try:
          response = requests.get(url, timeout=TIMEOUT)
          response.raise_for_status()
          return response.json()
      except requests.RequestException as e:
          logging.error(f"Error fetching IP info: {e}")
          logging.debug(e)
          traceback.print_exc()
          return {"error": str(e)}

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/saidsef/mcp-github-pr-issue-analyser'

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