get_ip_org
Retrieve the organization and ASN details for any IP address to identify network ownership and internet service providers.
Instructions
Get just the organization/ASN for an IP address.
Args: ip: IP address to lookup. If None, returns current organization.
Returns: ASN and organization name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | No |
Implementation Reference
- src/mcp_ipinfo/server.py:519-537 (handler)The primary MCP tool handler for 'get_ip_org', decorated with @mcp.tool() for registration. Handles input parameter 'ip' and delegates to IPInfoClient for organization lookup.@mcp.tool() async def get_ip_org(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the organization/ASN for an IP address. Args: ip: IP address to lookup. If None, returns current organization. Returns: ASN and organization name. """ client = get_client(ctx) try: if ip: return await client.get_org_by_ip(ip) else: return await client.get_current_org() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/server.py:29-37 (helper)Utility function to retrieve or lazily initialize the shared IPInfoClient instance used by all tools.def get_client(ctx: Context[Any, Any, Any]) -> IPInfoClient: """Get or create the API client instance.""" global _client if _client is None: api_token = os.environ.get("IPINFO_API_TOKEN") if not api_token: ctx.warning("IPINFO_API_TOKEN is not set - some features may be limited") _client = IPInfoClient(api_token=api_token) return _client
- src/mcp_ipinfo/api_client.py:398-406 (helper)Core API client methods that perform the HTTP requests to IPInfo.io /org endpoint to fetch the organization string for current IP or specific IP.async def get_current_org(self) -> str: """Get current ASN organization.""" data = await self._request("GET", "/org") return str(data.get("result", "")) async def get_org_by_ip(self, ip: str) -> str: """Get ASN organization for an IP.""" data = await self._request("GET", f"/{ip}/org") return str(data.get("result", ""))