get_ip_info
Retrieve detailed IP address information including geolocation, ASN data, company details, and privacy status for network analysis and intelligence gathering.
Instructions
Get comprehensive information about an IP address.
Args: ip: IP address to lookup. If None, returns info about current IP. ctx: MCP context
Returns: Complete IP information including location, ASN, company, privacy, etc.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- src/mcp_ipinfo/server.py:50-70 (handler)The main handler function for the 'get_ip_info' tool, decorated with @mcp.tool() for registration, implementing the core logic by fetching IP information from IPInfoClient.@mcp.tool() async def get_ip_info(ip: str | None, ctx: Context[Any, Any, Any]) -> FullResponse: """Get comprehensive information about an IP address. Args: ip: IP address to lookup. If None, returns info about current IP. ctx: MCP context Returns: Complete IP information including location, ASN, company, privacy, etc. """ client = get_client(ctx) try: if ip: return await client.get_info_by_ip(ip) else: return await client.get_current_info() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/api_models.py:77-94 (schema)Pydantic model defining the output schema returned by the get_ip_info tool.class FullResponse(BaseModel): ip: str = Field(..., description="IP address") bogon: bool | None = Field(None, description="Bogon IP") hostname: str | None = Field(None, description="Hostname") city: str | None = Field(None, description="City") region: str | None = Field(None, description="Region/State") country: str | None = Field(None, description="Country code") loc: str | None = Field(None, description="Location coordinates") postal: str | None = Field(None, description="Postal code") timezone: str | None = Field(None, description="Timezone") org: str | None = Field(None, description="Organization") asn: AsnResponse | None = Field(None, description="ASN details") company: CompanyResponse | None = Field(None, description="Company details") carrier: CarrierResponse | None = Field(None, description="Carrier details") privacy: PrivacyResponse | None = Field(None, description="Privacy detection") domains: DomainsResponse | None = Field(None, description="Hosted domains") abuse: AbuseResponse | None = Field(None, description="Abuse contact")
- src/mcp_ipinfo/server.py:29-38 (helper)Helper function used by get_ip_info to obtain the IPInfoClient instance.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