Skip to content

Commit 1d5746f

Browse files
araujofrakdutta1
authored andcommitted
fix: local network address translation in discovery module (IBM#767)
Signed-off-by: Frederico Araujo <[email protected]>
1 parent ebb9749 commit 1d5746f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mcpgateway/federation/discovery.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import asyncio
6666
from dataclasses import dataclass
6767
from datetime import datetime, timedelta, timezone
68+
import ipaddress
6869
import os
6970
import socket
7071
from typing import Dict, List, Optional
@@ -219,8 +220,10 @@ def _get_local_addresses(self) -> List[str]:
219220
# Get all network interfaces
220221
for iface in socket.getaddrinfo(socket.gethostname(), None):
221222
addr = iface[4][0]
222-
# Skip localhost
223-
if not addr.startswith("127."):
223+
ip_obj = ipaddress.ip_address(addr)
224+
is_ipv4 = isinstance(ip_obj, ipaddress.IPv4Address)
225+
# Skip localhost and non ipv4 addresses
226+
if is_ipv4 and not addr.startswith("127."):
224227
addresses.append(addr)
225228
except Exception as e:
226229
logger.warning(f"Failed to get local addresses: {e}")

0 commit comments

Comments
 (0)