Skip to content

fix: reuse TCP connection instead of reconnecting on every tool call#1

Open
Alex647648 wants to merge 1 commit intodimensionalOS:masterfrom
Alex647648:fix/reuse-tcp-connection
Open

fix: reuse TCP connection instead of reconnecting on every tool call#1
Alex647648 wants to merge 1 commit intodimensionalOS:masterfrom
Alex647648:fix/reuse-tcp-connection

Conversation

@Alex647648
Copy link

Summary

  • Introduce a persistent connection pool (McpConnection) keyed by host:port that initializes the MCP session once and reuses it for all subsequent tools/call requests
  • Use incrementing request IDs to correctly multiplex concurrent requests over a single connection
  • Auto-recover when the connection is closed or errors out (next call transparently reconnects)

Motivation

Previously every callTool invocation opened a new TCP socket and ran the full initializetools/call handshake. For robot control workloads that issue frequent tool calls, this added ~2 round-trips of unnecessary latency per call and wasted server resources.

Test plan

  • Start DimOS MCP server, run multiple agent tool calls in sequence — verify only one TCP connection is established
  • Kill the MCP server mid-session, issue another tool call — verify it reconnects automatically
  • Run concurrent tool calls — verify responses are correctly routed via request IDs

Previously each callTool invocation opened a new TCP connection and
re-ran the MCP initialize handshake. For robot control workloads with
frequent tool calls this added significant latency. This change
introduces a persistent connection pool keyed by host:port that
initializes once and multiplexes subsequent requests with incrementing
IDs. Connections auto-recover on close/error.
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