Skip to content

aws-network-mcp-server : Error calling tool 'get_vpc_network': 'PublicIp' #2836

@tanvp112

Description

@tanvp112

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

No one assigned

    Labels

    bugSomething isn't workingneeds-triageThis needs to be handled, it is the first automatically assigned label to issues.

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions