get_public_ip
Retrieve the public IP address of the current machine. Useful for network diagnostics and connectivity checks.
Instructions
Get the public IP address of this machine.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_public_ip"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/sounding/server.py:505-513 (handler)The tool handler that fetches the public IP from httpbin.org/ip and returns it as {"public_ip": ...} or {"error": ...} on failure.
async def get_public_ip() -> dict: """Get the public IP address of this machine.""" try: async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get("https://httpbin.org/ip") data = response.json() return {"public_ip": data.get("origin", "unknown")} except Exception as exc: return {"error": str(exc)} - src/sounding/server.py:504-505 (schema)No explicit schema – input takes no arguments, output is a free-form dict (either {"public_ip": str} or {"error": str}).
@mcp.tool() async def get_public_ip() -> dict: - src/sounding/server.py:504-505 (registration)Registered as an MCP tool via the @mcp.tool() decorator on line 504.
@mcp.tool() async def get_public_ip() -> dict: - tests/test_tools.py:242-258 (helper)Mocked unit test for get_public_ip success case.
async def test_get_public_ip_mocked(): """get_public_ip should return the IP from httpbin without hitting the network.""" from unittest.mock import MagicMock mock_response = MagicMock() mock_response.json.return_value = {"origin": "203.0.113.42"} mock_client_instance = AsyncMock() mock_client_instance.get = AsyncMock(return_value=mock_response) mock_client_instance.__aenter__ = AsyncMock(return_value=mock_client_instance) mock_client_instance.__aexit__ = AsyncMock(return_value=False) with patch("sounding.server.httpx.AsyncClient", return_value=mock_client_instance): result = await get_public_ip() assert result == {"public_ip": "203.0.113.42"} mock_client_instance.get.assert_awaited_once_with("https://httpbin.org/ip") - tests/test_tools.py:262-272 (helper)Mocked unit test for get_public_ip error/exception case.
async def test_get_public_ip_mocked_error(): """get_public_ip should return an error dict on failure.""" mock_client_instance = AsyncMock() mock_client_instance.get = AsyncMock(side_effect=httpx.ConnectError("Connection refused")) mock_client_instance.__aenter__ = AsyncMock(return_value=mock_client_instance) mock_client_instance.__aexit__ = AsyncMock(return_value=False) with patch("sounding.server.httpx.AsyncClient", return_value=mock_client_instance): result = await get_public_ip() assert "error" in result