Skip to content

feat: make httpx connection pool size configurable via flags and env#307

Open
valter-silva-au wants to merge 1 commit into
aws:mainfrom
valter-silva-au:feat/configurable-httpx-pool-size
Open

feat: make httpx connection pool size configurable via flags and env#307
valter-silva-au wants to merge 1 commit into
aws:mainfrom
valter-silva-au:feat/configurable-httpx-pool-size

Conversation

@valter-silva-au

@valter-silva-au valter-silva-au commented Jun 8, 2026

Copy link
Copy Markdown

Problem

The single shared httpx.AsyncClient that serves every proxied MCP tool call is constructed with a hardcoded httpx.Limits(max_keepalive_connections=1, max_connections=5), and nothing (CLI flag, env var, config) exposes it. MCP clients that fan out parallel aws_* 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:

  • New CLI flags --max-connections (default 5, must be >= 1) and --max-keepalive-connections (default 1, must be >= 0), validated via an integer range validator.
  • Environment fallbacks MCP_PROXY_MAX_CONNECTIONS / MCP_PROXY_MAX_KEEPALIVE_CONNECTIONS; explicit flags take precedence over env vars.
  • The two values are threaded 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, the httpx.Limits passed to the client is byte-for-byte identical to the previous hardcoded value. A dedicated test asserts limits == 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

  • Added unit tests for the new create_sigv4_client params (default + override) and the CLI flags (defaults, parsing, env fallback, cli-overrides-env, range validation).
  • Full suite: uv run pytest tests/unit → 224 → 232 passed.
  • ruff check + ruff format --check clean; pyright reports 0 errors/warnings.
  • Verified --help renders both flags and an end-to-end smoke test confirms env fallback and defaults resolve to int.

Note: env var names (MCP_PROXY_MAX_CONNECTIONS / MCP_PROXY_MAX_KEEPALIVE_CONNECTIONS) follow the prefix used in the issue; the existing profiles env var uses AWS_MCP_PROXY_PROFILES. Easy to rename for consistency if you prefer.

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.

@valter-silva-au valter-silva-au requested a review from a team as a code owner June 8, 2026 06:06
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
@valter-silva-au valter-silva-au force-pushed the feat/configurable-httpx-pool-size branch from 85a08ed to bd384a2 Compare June 11, 2026 12:21
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.

Hardcoded httpx pool size limits parallel tool-call fanout

1 participant