get_asn_info
Retrieve detailed information about an Autonomous System Number (ASN), including network prefixes, peer connections, and organizational details for network analysis and intelligence.
Instructions
Get information about an Autonomous System Number (ASN).
Args: asn: The ASN number (without 'AS' prefix)
Returns: ASN information including prefixes, peers, and network details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asn | Yes |
Implementation Reference
- src/mcp_ipinfo/server.py:146-162 (handler)The main handler function for the 'get_asn_info' tool, decorated with @mcp.tool() for automatic registration. It retrieves the IPInfo client and calls client.get_asn(asn) to fetch ASN details.@mcp.tool() async def get_asn_info(asn: int, ctx: Context[Any, Any, Any]) -> AsnResponse: """Get information about an Autonomous System Number (ASN). Args: asn: The ASN number (without 'AS' prefix) Returns: ASN information including prefixes, peers, and network details. """ client = get_client(ctx) try: return await client.get_asn(asn) except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/api_models.py:23-38 (schema)Pydantic model defining the output schema for the get_asn_info tool response.class AsnResponse(BaseModel): asn: str = Field(..., description="ASN identifier") name: str = Field(..., description="Name of the ASN") country: str | None = Field(None, description="Country code") allocated: str | None = Field(None, description="Allocation date") registry: str | None = Field(None, description="Registry name") domain: str = Field(..., description="Domain") num_ips: int | None = Field(None, description="Number of IPs") route: str | None = Field(None, description="Route") type: CompanyType = Field(..., description="Type of organization") prefixes: list[dict[str, Any]] | None = Field(None) prefixes6: list[dict[str, Any]] | None = Field(None) peers: list[str] | None = Field(None) upstreams: list[str] | None = Field(None) downstreams: list[str] | None = Field(None)
- src/mcp_ipinfo/api_client.py:181-185 (helper)Helper method in IPInfoClient that makes the actual HTTP GET request to the IPInfo API for ASN data and parses it into AsnResponse.async def get_asn(self, asn: int) -> AsnResponse: """Get information about an ASN.""" data = await self._request("GET", f"/AS{asn}") return AsnResponse(**data)
- src/mcp_ipinfo/server.py:29-38 (helper)Utility function to lazily initialize and retrieve the shared IPInfoClient instance used by all tools including get_asn_info.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