Skip to main content
Glama

get_ip_hostname

Retrieve the hostname associated with an IP address or get the current system's hostname when no IP is specified.

Instructions

Get just the hostname for an IP address.

Args: ip: IP address to lookup. If None, returns current hostname.

Returns: Hostname.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipNo

Implementation Reference

  • The handler function for the 'get_ip_hostname' tool, decorated with @mcp.tool() for registration. It fetches the hostname for a given IP address (or current IP if none provided) using the IPInfoClient, handling API errors appropriately.
    @mcp.tool() async def get_ip_hostname(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the hostname for an IP address. Args: ip: IP address to lookup. If None, returns current hostname. Returns: Hostname. """ client = get_client(ctx) try: if ip: return await client.get_hostname_by_ip(ip) else: return await client.get_current_hostname() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
  • The @mcp.tool() decorator registers the get_ip_hostname function as an MCP tool.
    @mcp.tool()
  • Helper function to get or initialize the shared IPInfoClient instance, used by get_ip_hostname and other 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

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/NimbleBrainInc/mcp-ipinfo'

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