Skip to content

feat: support regex-based AWS profile selection - #448

Open
TOGEP wants to merge 1 commit into
aws:mainfrom
TOGEP:feat/regex-profile-selection
Open

TOGEP wants to merge 1 commit into
aws:mainfrom
TOGEP:feat/regex-profile-selection

Conversation

@TOGEP

@TOGEP TOGEP commented Oct 29, 2026

Copy link
Copy Markdown

Summary

Changes

Add AWS_MCP_PROXY_PROFILE_REGEX to select locally configured AWS profiles using a regular expression.

Matching profiles are added to the explicitly configured profile list at startup, with duplicates removed. The explicit profile order, default profile, and existing configuration precedence are preserved.

Closes #447.

User experience

Previously, users had to list every profile explicitly and update the list whenever profiles were added or removed.

Users can now specify a default profile and automatically include additional profiles based on a naming pattern:

export AWS_MCP_PROXY_PROFILES="dev-ReadOnlyAccess"
export AWS_MCP_PROXY_PROFILE_REGEX=".*-ReadOnlyAccess$"

The regex is matched against entire profile names. Matching profiles become available for per-call switching, while the explicitly configured profile remains the default.

Profile changes take effect after restarting the proxy.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have reviewed the contributing guidelines
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Is this a breaking change? (Y/N)

  • Yes
  • No

Validation

❯ .venv/bin/pytest tests/unit/test_server.py -q --log-cli-level=ERROR --tb=short

tests/unit/test_server.py::TestServer::test_setup_mcp_mode PASSED                                                                                   [  2%]
tests/unit/test_server.py::TestServer::test_setup_mcp_mode_no_retries PASSED                                                                        [  5%]
tests/unit/test_server.py::TestServer::test_setup_mcp_mode_no_metadata_injects_aws_region PASSED                                                    [  8%]
tests/unit/test_server.py::TestServer::test_setup_mcp_mode_metadata_without_aws_region_injects_it PASSED                                            [ 11%]
tests/unit/test_server.py::TestServer::test_add_tool_filtering_middleware PASSED                                                                    [ 13%]
tests/unit/test_server.py::TestServer::test_add_retry_middleware PASSED                                                                             [ 16%]
tests/unit/test_server.py::TestServer::test_parse_args_default PASSED                                                                               [ 19%]
tests/unit/test_server.py::TestServer::test_parse_args_custom PASSED                                                                                [ 22%]
tests/unit/test_server.py::TestServer::test_main_function PASSED                                                                                    [ 25%]
tests/unit/test_server.py::TestServer::test_main_error_handling PASSED                                                                              [ 27%]
tests/unit/test_server.py::TestServer::test_validate_service_name_service_parsing PASSED                                                            [ 30%]
tests/unit/test_server.py::TestServer::test_create_sigv4_client PASSED                                                                              [ 33%]
tests/unit/test_server.py::TestServer::test_create_sigv4_client_no_credentials PASSED                                                               [ 36%]
tests/unit/test_server.py::TestServer::test_main_module_execution PASSED                                                                            [ 38%]
tests/unit/test_server.py::TestProfileDedup::test_duplicate_profiles_are_deduped PASSED                                                             [ 41%]
tests/unit/test_server.py::TestProfileDedup::test_default_profile_included_in_allowed_list PASSED                                                   [ 44%]
tests/unit/test_server.py::TestProfileDedup::test_single_profile_no_middleware PASSED                                                               [ 47%]
tests/unit/test_server.py::TestRegexProfiles::test_profile_selection[preserves-default-and-explicit-order] PASSED                                   [ 50%]
tests/unit/test_server.py::TestRegexProfiles::test_profile_selection[full-name-match] PASSED                                                        [ 52%]
tests/unit/test_server.py::TestRegexProfiles::test_profile_selection[deduplication] PASSED                                                          [ 55%]
tests/unit/test_server.py::TestRegexProfiles::test_profile_selection[default-only] PASSED                                                           [ 58%]
tests/unit/test_server.py::TestRegexProfiles::test_explicit_default_overrides_missing_aws_profile[None-env] PASSED                                  [ 61%]
tests/unit/test_server.py::TestRegexProfiles::test_explicit_default_overrides_missing_aws_profile[None-cli] PASSED                                  [ 63%]
tests/unit/test_server.py::TestRegexProfiles::test_explicit_default_overrides_missing_aws_profile[deleted-profile-env] PASSED                       [ 66%]
tests/unit/test_server.py::TestRegexProfiles::test_explicit_default_overrides_missing_aws_profile[deleted-profile-cli] PASSED                       [ 69%]
tests/unit/test_server.py::TestRegexProfiles::test_no_regex_does_not_load_profiles[None] PASSED                                                     [ 72%]
tests/unit/test_server.py::TestRegexProfiles::test_no_regex_does_not_load_profiles[] PASSED                                                         [ 75%]
tests/unit/test_server.py::TestRegexProfiles::test_configuration_errors[[-profiles0-Invalid AWS_MCP_PROXY_PROFILE_REGEX] PASSED                     [ 77%]
tests/unit/test_server.py::TestRegexProfiles::test_configuration_errors[.*-None-requires an explicit default profile] PASSED                        [ 80%]
tests/unit/test_server.py::TestRegexProfiles::test_configuration_errors[missing-.*-profiles2-did not match any available AWS profiles] PASSED       [ 83%]
tests/unit/test_server.py::TestEnvVarProfiles::test_env_var_parsed_when_no_profile_flag PASSED                                                      [ 86%]
tests/unit/test_server.py::TestEnvVarProfiles::test_env_var_takes_precedence_over_profile_flag PASSED                                               [ 88%]
tests/unit/test_server.py::TestEnvVarProfiles::test_empty_env_var_ignored PASSED                                                                    [ 91%]
tests/unit/test_server.py::TestEnvVarProfiles::test_env_var_handles_extra_whitespace PASSED                                                         [ 94%]
tests/unit/test_server.py::TestFix2EnvVarPrecedence::test_env_var_profiles_wins_over_aws_profile PASSED                                             [ 97%]
tests/unit/test_server.py::TestEnvVarActivatesMiddleware::test_env_var_activates_profile_middleware PASSED                                          [100%]

=================================================================== 36 passed in 0.55s ====================================================================

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@TOGEP
TOGEP requested a review from a team as a code owner October 29, 2026 10:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support regex-based AWS profile selection

1 participant