Skip to content

Fix HTTP session inefficiency by sharing MultiIndexRunner across sessions#17

Open
augment-app-staging[bot] wants to merge 1 commit intomainfrom
fix/http-session-runner-sharing
Open

Fix HTTP session inefficiency by sharing MultiIndexRunner across sessions#17
augment-app-staging[bot] wants to merge 1 commit intomainfrom
fix/http-session-runner-sharing

Conversation

@augment-app-staging
Copy link

Problem

Currently in src/clients/mcp-http-server.ts, every new HTTP client session creates a fresh MultiIndexRunner instance via createMCPServer(). This causes redundant store.list() + store.loadSearch() calls for every index on every session, which is wasteful especially for S3-backed stores.

Solution

Share a single MultiIndexRunner instance across all HTTP sessions while maintaining per-session MCP Server instances (required by MCP protocol).

Changes

Modified src/clients/mcp-server.ts:

  • Added optional runner?: MultiIndexRunner field to the MCPServerConfig interface
  • Updated createMCPServer() function to:
    • Accept the optional runner parameter from config
    • If config.runner is provided, use it instead of creating a new one
    • If not provided, create a new MultiIndexRunner as before (backward compatible)
  • Added comment explaining the optional runner parameter is for sharing across sessions
  • Added comment explaining that updateClientUserAgent updates the shared runner for all sessions (last writer wins)

Modified src/clients/mcp-http-server.ts:

  • In createMCPHttpServer() function, create a single shared MultiIndexRunner instance during server initialization (before the session handling logic)
  • Pass this shared runner to each per-session createMCPServer() call via the config
  • Added comment explaining the shared runner optimization and the updateClientUserAgent behavior

Benefits

  • HTTP sessions no longer redundantly call store.list() and store.loadSearch() for every session
  • Single MultiIndexRunner instance is created once and shared across all HTTP sessions
  • Stdio MCP server continues to work unchanged
  • All tests pass
  • Code includes clear comments explaining the optimization

Testing

  • All existing tests pass (193 passed)
  • Build succeeds without errors
  • Backward compatibility maintained - stdio MCP server works without providing a runner

Related

Slack discussion: https://slack.com/archives/C0ACX5SLML7/p1770850068455299

…ions

Currently, every new HTTP client session creates a fresh MultiIndexRunner
instance via createMCPServer(). This causes redundant store.list() and
store.loadSearch() calls for every index on every session, which is wasteful
especially for S3-backed stores.

This change shares a single MultiIndexRunner instance across all HTTP sessions
while maintaining per-session MCP Server instances (required by MCP protocol).

Changes:
- Add optional 'runner' field to MCPServerConfig interface
- Update createMCPServer() to use provided runner if available, otherwise create new one
- Modify createMCPHttpServer() to create shared runner once and pass to all sessions
- Add comments explaining the optimization and updateClientUserAgent behavior

The shared MultiIndexRunner is safe because it already has lazy client caching.
All existing tests pass and backward compatibility is maintained.

Related: https://slack.com/archives/C0ACX5SLML7/p1770850068455299
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.

0 participants