-
Notifications
You must be signed in to change notification settings - Fork 1.4k
aws-network-mcp-server : Error calling tool 'get_vpc_network': 'PublicIp' #2836
Description
Describe the bug
In vcp_details.py at line 251-253, the process_nat_gateways function assumes NatGatewayAddresses always exists and contains PublicIp:
for address in nat['NatGatewayAddresses']:
gw.private_ips.append(address['PrivateIp'])
gw.public_ips.append(address['PublicIp']) # <-- KeyError: 'PublicIp'
The issue is that when a NAT Gateway is in a private subnet (not assigned a public IP), the PublicIp field may not be present in the response. The code should check if the key exists before accessing it.
Looking at line 251, the code iterates over nat['NatGatewayAddresses'] without checking if it exists or is not None. If the VPC has a NAT Gateway without addresses configured (or the field is missing), this would
also cause an error.
The fix would be to change lines 251-253 to:
251 + for address in nat.get('NatGatewayAddresses', []):
252 + if 'PrivateIp' in address:
253 + gw.private_ips.append(address['PrivateIp'])
254 + if 'PublicIp' in address:
255 + gw.public_ips.append(address['PublicIp'])
Expected Behavior
Should return all info as per the function intended.
Current Behavior
get_vpc_network doesn't work.
Reproduction Steps
"Get VPC network details for vpc-xxxxxxxxx in us-east-1"
Possible Solution
See above.
Additional Information/Context
No response
OS
linux
Server
other
Server Version
No response
Region experiencing the issue
Any
Other information
No response
Service quota
- I have reviewed the service quotas for this construct
Metadata
Metadata
Assignees
Labels
Type
Projects
Status