Summary
In src/services/ConnectionManager.ts, the instances: Map<string, InstanceState> retains a GraphQLClient, SchemaIntrospector, version/schema data, and scope info for every normalized URL added during the process lifetime. Successful entries are only reclaimed by reinitialize() or reset(). In multi-instance OAuth traffic with many tenants, this means memory grows unboundedly.
In practice, MCP servers typically handle 1–3 instances (default + OAuth-switched), so the impact is low for the common case. However, a TTL/LRU eviction mechanism would make the implementation safe for high-cardinality deployments.
Proposed Work
- Add a
removeInstance(url: string) method that:
- Removes the entry from
instances, initializePromises, and introspectionPromises
- Clears the matching entry from the static
introspectionCache (and related CacheEntry)
- Tears down any
GraphQLClient/SchemaIntrospector resources if they require explicit cleanup
- Add an LRU eviction policy (e.g., max N entries) and/or a TTL-based prune routine (using
CACHE_TTL as a hint) to automatically drop stale entries
- Wire session/registry cleanup paths to call
removeInstance(normalizedUrl) when a session or tenant is torn down
- Consider a periodic
evictExpiredInstances() routine callable by HealthMonitor or a scheduler
Context
Summary
In
src/services/ConnectionManager.ts, theinstances: Map<string, InstanceState>retains aGraphQLClient,SchemaIntrospector, version/schema data, and scope info for every normalized URL added during the process lifetime. Successful entries are only reclaimed byreinitialize()orreset(). In multi-instance OAuth traffic with many tenants, this means memory grows unboundedly.In practice, MCP servers typically handle 1–3 instances (default + OAuth-switched), so the impact is low for the common case. However, a TTL/LRU eviction mechanism would make the implementation safe for high-cardinality deployments.
Proposed Work
removeInstance(url: string)method that:instances,initializePromises, andintrospectionPromisesintrospectionCache(and relatedCacheEntry)GraphQLClient/SchemaIntrospectorresources if they require explicit cleanupCACHE_TTLas a hint) to automatically drop stale entriesremoveInstance(normalizedUrl)when a session or tenant is torn downevictExpiredInstances()routine callable byHealthMonitoror a schedulerContext