fix(aws-network-mcp-server): detect_tgw_inspection KeyError on VpcId#4291
Open
arimu1 wants to merge 2 commits into
Open
fix(aws-network-mcp-server): detect_tgw_inspection KeyError on VpcId#4291arimu1 wants to merge 2 commits into
arimu1 wants to merge 2 commits into
Conversation
list_firewalls() only returns FirewallName/FirewallArn, never VpcId, so any account with at least one AWS Network Firewall made detect_tgw_inspection() crash with KeyError: 'VpcId' regardless of the Transit Gateway's attachment mix. VpcId is only available from describe_firewall(), so look it up there instead. Closes awslabs#4286
arimu1
requested review from
a team,
NetDevAutomate and
juhala-aws
as code owners
July 21, 2026 02:25
test_vpc_firewall_detection already fails pre-fix now that sample_firewalls matches the real ListFirewalls shape (no VpcId), so the separate no_vpc_id regression test duplicated it with a one-off inline dict. Drop it in favor of the existing test carrying regression coverage. Also convert _describe_firewall_side_effect from a staticmethod to a fixture, matching every other shared value in this test class.
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
detect_tgw_inspectionraised an unhandledKeyError: 'VpcId'any time the account/region had at least one AWS Network Firewall — regardless of the Transit Gateway's attachment mix.Root cause:
nfw_client.list_firewalls()['Firewalls']items only ever containFirewallName/FirewallArn/TransitGatewayAttachmentId(see the ListFirewalls API reference) —VpcIdis never present there.VpcIdonly shows up in the DescribeFirewall response. The unguardedfw['VpcId']access at line 68 ofdetect_transit_gateway_inspection.pytherefore failed on every call that returned any firewalls, independent of the TGW's attachment types — the TGW-attachment filtering code (ResourceType/ResourceId) was already correct and unaffected.Fix
Look up each listed firewall's
VpcIdviadescribe_firewall()(the same call already used a few lines down for TGW network-function attachments), guarding with.get('VpcId')so non-VPC firewalls or describe failures degrade gracefully instead of crashing the whole tool call.Closes #4286
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.
Test plan
test_vpc_firewall_detection_no_vpc_id_on_list_firewalls) that mockslist_firewalls()with the real API shape (noVpcId) and asserts the tool still correctly finds the VPC-attached firewall viadescribe_firewall().list_firewalls()returnsVpcId.ToolError: Error detecting firewall attachments: 'VpcId'.) against the pre-fix code, and passes after the fix.uv run pytest tests/— 245 passeduv run ruff check/uv run ruff format --checkon changed files — clean