Skip to content

feat: make maxTotalConnections configurable via env var#280

Open
loris-av wants to merge 1 commit into
metatool-ai:mainfrom
loris-av:feat/configurable-max-connections
Open

feat: make maxTotalConnections configurable via env var#280
loris-av wants to merge 1 commit into
metatool-ai:mainfrom
loris-av:feat/configurable-max-connections

Conversation

@loris-av

@loris-av loris-av commented Apr 9, 2026

Copy link
Copy Markdown

Problem

The McpServerPool constructor hardcodes maxTotalConnections = 100. For deployments with many MCP servers and namespaces, the connection pool saturates at 100 connections, causing new connections to be silently refused with a warning log:

Connection limit reached: 100/100. Refusing to create new connection.

There is no way to raise this limit without modifying the source code.

Solution

Read the limit from the MAX_TOTAL_CONNECTIONS environment variable at startup, falling back to 100 if unset:

maxTotalConnections: number = parseInt(
  process.env.MAX_TOTAL_CONNECTIONS || "100",
  10,
),

This is a one-line change with zero impact on existing deployments (default stays at 100).

Testing

  • Without MAX_TOTAL_CONNECTIONS set: pool behaves exactly as before (limit = 100).
  • With MAX_TOTAL_CONNECTIONS=500: pool allows up to 500 total connections.

loris-av added a commit to loris-av/metamcp that referenced this pull request Apr 14, 2026
The cleanup timer in McpServerPool and MetaMcpServerPool runs every 5
minutes but skips cleanup entirely when getSessionLifetime() returns
null (the default when no DB config is set). This means sessions
accumulate indefinitely, eventually saturating the connection pool.

This adds an env var fallback: when the DB config table has no
SESSION_LIFETIME value, process.env.SESSION_LIFETIME is read instead.
The DB config (via the Settings dashboard) still takes priority.

Example: SESSION_LIFETIME=3600000 (1 hour in ms) enables automatic
cleanup of sessions older than 1 hour.

This follows the same pattern as MAX_TOTAL_CONNECTIONS (PR metatool-ai#280).
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.

1 participant