feat: make httpx connection pool size configurable via flags and env#307
Open
valter-silva-au wants to merge 1 commit into
Open
feat: make httpx connection pool size configurable via flags and env#307valter-silva-au wants to merge 1 commit into
valter-silva-au wants to merge 1 commit into
Conversation
The single shared httpx.AsyncClient that serves all proxied MCP tool calls was constructed with a hardcoded httpx.Limits(max_keepalive_connections=1, max_connections=5). MCP clients that fan out parallel aws_* tool calls per turn (Claude Code, opencode — typically 4-8 concurrent) saturate the 5-connection pool, causing intermittent failures. Expose the pool size via new CLI flags --max-connections / --max-keepalive-connections with environment-variable fallbacks MCP_PROXY_MAX_CONNECTIONS / MCP_PROXY_MAX_KEEPALIVE_CONNECTIONS. The two values are threaded from cli -> server -> create_transport_with_sigv4 -> create_sigv4_client, and through the per-profile override middleware. Defaults are unchanged: max_connections=5, max_keepalive_connections=1, so existing deployments behave byte-for-byte as before. A backward- compat test asserts the default limits equal the original hardcoded Limits object. Scope: pool-sizing knob only. Does not touch the auth-path serialization (_sign_request_hook / next(auth_flow)), which is tracked separately in aws#270. Fixes aws#295
85a08ed to
bd384a2
Compare
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.
Problem
The single shared
httpx.AsyncClientthat serves every proxied MCP tool call is constructed with a hardcodedhttpx.Limits(max_keepalive_connections=1, max_connections=5), and nothing (CLI flag, env var, config) exposes it. MCP clients that fan out parallelaws_*tool calls per turn — Claude Code, opencode, typically 4-8 concurrent — saturate the 5-connection pool and hit intermittent failures.Change
Make the pool size configurable:
--max-connections(default 5, must be>= 1) and--max-keepalive-connections(default 1, must be>= 0), validated via an integer range validator.MCP_PROXY_MAX_CONNECTIONS/MCP_PROXY_MAX_KEEPALIVE_CONNECTIONS; explicit flags take precedence over env vars.cli → server → create_transport_with_sigv4 → create_sigv4_client, and through the per-profile override middleware so multi-account transports share the same pool sizing.Defaults / backward compatibility
Defaults are unchanged:
max_connections=5,max_keepalive_connections=1. With no new flags/env, thehttpx.Limitspassed to the client is byte-for-byte identical to the previous hardcoded value. A dedicated test assertslimits == httpx.Limits(max_keepalive_connections=1, max_connections=5).Scope
Pool-sizing knob only. This PR deliberately does not touch the auth-path serialization (
_sign_request_hook/next(auth_flow)), which is a separate concern tracked in #270.Testing
create_sigv4_clientparams (default + override) and the CLI flags (defaults, parsing, env fallback, cli-overrides-env, range validation).uv run pytest tests/unit→ 224 → 232 passed.ruff check+ruff format --checkclean;pyrightreports 0 errors/warnings.--helprenders both flags and an end-to-end smoke test confirms env fallback and defaults resolve toint.Fixes #295
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.