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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_github/ip_integration.py:73-88 (handler)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)}
- src/mcp_github/issues_pr_analyser.py:105-113 (registration)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)
- src/mcp_github/issues_pr_analyser.py:67-68 (registration)Instantiation of the IPIntegration class instance (self.ip) whose methods are registered as MCP tools.self.gi = GI() self.ip = IP()
- src/mcp_github/issues_pr_analyser.py:28-28 (registration)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)}