From e78956b35ae6a86c1f61d67839d144473721e82c Mon Sep 17 00:00:00 2001 From: Frederico Araujo Date: Sun, 17 Aug 2025 14:30:35 -0400 Subject: [PATCH] fix: local network address translation in discovery module Signed-off-by: Frederico Araujo --- mcpgateway/federation/discovery.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mcpgateway/federation/discovery.py b/mcpgateway/federation/discovery.py index 2ecc90ceb..debcbb118 100644 --- a/mcpgateway/federation/discovery.py +++ b/mcpgateway/federation/discovery.py @@ -65,6 +65,7 @@ import asyncio from dataclasses import dataclass from datetime import datetime, timedelta, timezone +import ipaddress import os import socket from typing import Dict, List, Optional @@ -219,8 +220,10 @@ def _get_local_addresses(self) -> List[str]: # Get all network interfaces for iface in socket.getaddrinfo(socket.gethostname(), None): addr = iface[4][0] - # Skip localhost - if not addr.startswith("127."): + ip_obj = ipaddress.ip_address(addr) + is_ipv4 = isinstance(ip_obj, ipaddress.IPv4Address) + # Skip localhost and non ipv4 addresses + if is_ipv4 and not addr.startswith("127."): addresses.append(addr) except Exception as e: logger.warning(f"Failed to get local addresses: {e}")