fix(aws-network-mcp-server): handle Regional NAT Gateways in process_nat_gateways#3525
Open
Garou11 wants to merge 1 commit into
Open
fix(aws-network-mcp-server): handle Regional NAT Gateways in process_nat_gateways#3525Garou11 wants to merge 1 commit into
Garou11 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_vpc_network(and any other tool that callsprocess_nat_gateways) raisesKeyError: 'SubnetId'— and in async contexts can manifest as a complete hang — for any VPC that contains a Regional NAT Gateway. This PR makesprocess_nat_gatewaysregional-NAT-safe with three small defensive changes.Background
Regional NAT Gateway is a 2026 addition to the EC2 API. Unlike the original ("zonal") NAT Gateway:
SubnetIdfield. It binds to a route table viaRouteTableIdand auto-provisions ENIs across AZs.NatGatewayAddressesfor regional NATs may legitimately omitPrivateIp/PublicIpwhile addresses are being provisioned.The current
process_nat_gatewaysinawslabs/aws_network_mcp_server/utils/vcp_details.pymakes three assumptions that don't hold for regional NATs:Plus the strict pydantic dataclass:
This PR fixes all four together so callers see a clean response with
subnet_id=Nonefor regional NATs instead of an exception (which, depending on how a downstream framework propagates the resultingToolError, can manifest to MCP clients as an indefinite hang on the affected VPC).Changes
src/aws-network-mcp-server/awslabs/aws_network_mcp_server/utils/vcp_details.py:NatGatewayDict.subnet_id: str→Optional[str]— a regional NAT genuinely has no subnet, so the field has to admitNone. (Optionalis already imported.)nat['SubnetId']→nat.get('SubnetId')— surfaceNoneinstead ofKeyError.nat['NatGatewayAddresses']→nat.get('NatGatewayAddresses', [])and per-keyif 'PrivateIp' in address/if 'PublicIp' in addressguards — same defensive shape as fix(aws-network-mcp-server): handle missing PublicIp in NAT gateway addresses #2876, applied here together so we don't end up with a half-fix.Diff is ~14 lines.
Relationship to existing work
'PublicIp'KeyError report — same root cause, narrower symptom).PrivateIp/PublicIp, leaving theSubnetIdandOptional[str]parts of the bug intact). I'm happy to either rebase this on top of fix(aws-network-mcp-server): handle missing PublicIp in NAT gateway addresses #2876 if it lands first, or close fix(aws-network-mcp-server): handle missing PublicIp in NAT gateway addresses #2876 in favor of this if a reviewer prefers the bundled fix.Test plan
Reproduction (without the fix):
aws ec2 create-nat-gateway --route-table-id rtb-… …)get_vpc_networkagainst that VPCNoneforsubnet_ideven if you guard the dict access.With the fix:
vpc_networkdocument, with the regional NAT'ssubnet_idset tonull..get()returns the existing string; the dataclass still accepts it).NatGatewayAddresses— or addresses lacking either key — no longer crashes;private_ips/public_ipssimply skip the missing entries.I can add a unit test against
process_nat_gatewayswith synthetic zonal + regional + provisioning-in-progress inputs if reviewers prefer; happy to do that in this PR or as a follow-up.Notes for downstream
Consumers that read
subnet_idshould already handleNone(regional NATs are a property ofaws ec2 describe-nat-gatewaysoutput and exist whether or not this MCP server reflects them). For downstream that wants to surface where a regional NAT lives, theRouteTableIdfield on the upstream NAT entry is the equivalent. That's out of scope for this PR — happy to add it as a follow-up if useful.