Skip to content

Clean up McpServer connection-callback surface#220

Merged
caleb2h merged 2 commits into
mainfrom
chore/audit-server-connection-event
Apr 20, 2026
Merged

Clean up McpServer connection-callback surface#220
caleb2h merged 2 commits into
mainfrom
chore/audit-server-connection-event

Conversation

@gophergogo
Copy link
Copy Markdown
Collaborator

Summary

Two small, mechanical follow-ups to PR #219 that trim dead code from the McpServer connection-callback surface now that TCP accepts are properly counted in onNewConnection.

  1. Drop vestigial ConnectionCallbacks inheritance. McpServer inherited from network::ConnectionCallbacks and overrode onEvent, onAboveWriteBufferHighWatermark, and onBelowWriteBufferLowWatermark, but nothing ever registered an McpServer instance as a connection's callbacks. Per-TCP-connection events go through the ConnectionLifecycleCallbacks adapter (which carries the closing connection's identity); the stdio path reaches McpServer::onConnectionEvent through ServerProtocolCallbacks, not through ConnectionCallbacks::onEvent. onConnectionEvent itself stays — it is still the live stats-and-forwarding entry point for stdio transports.
  2. Drop write-only num_connections_ counter. It was a private atomic bumped on accept and decremented on close with no reader anywhere in include/, src/, tests/, or examples/. server_stats_.connections_active is the real, publicly-exposed count via getServerStats() and lives on the same code paths. One source of truth instead of two.

Test plan

  • ctest -R 'McpServer|McpClient|McpInitialize|StdioEcho|TcpEcho' — 12/12 pass

gophergogo added 2 commits April 20, 2026 16:16
McpServer inherited from network::ConnectionCallbacks and overrode
onEvent / onAboveWriteBufferHighWatermark / onBelowWriteBufferLowWatermark,
but nothing ever registered an McpServer instance as a connection's
ConnectionCallbacks. Per-TCP-connection events go through the
ConnectionLifecycleCallbacks adapter added in onNewConnection, which
carries the closing connection's identity. The stdio event path reaches
McpServer::onConnectionEvent through ServerProtocolCallbacks, not through
ConnectionCallbacks::onEvent.

Removing the base and its three overrides deletes dead code and makes
the class interface honest about which callback surfaces it actually
uses. onConnectionEvent itself stays: it is still the stats-and-
forwarding path for stdio transports via ServerProtocolCallbacks.

All McpServer/McpClient/StdioEcho/TcpEcho integration tests still pass.
num_connections_ was a private atomic that tracked accept/close on the
dispatcher thread but was never read -- no member function exposed it,
no test inspected it, and no external caller had a hook to reach it.
The real connection count visible to operators has always been
server_stats_.connections_active, which getServerStats() already
surfaces and which is incremented and decremented on exactly the same
code paths.

Keeping two parallel counters that only differ in reachability is a
maintenance trap: the next time a path changes, one of them drifts.
Removing the shadow counter leaves a single source of truth.

All McpServer/McpClient/StdioEcho/TcpEcho integration tests still pass.
@gophergogo gophergogo force-pushed the chore/audit-server-connection-event branch from afedafc to 18b1dac Compare April 20, 2026 23:16
@caleb2h caleb2h merged commit efee278 into main Apr 20, 2026
1 check passed
caleb2h pushed a commit that referenced this pull request Apr 20, 2026
McpServer inherited from network::ConnectionCallbacks and overrode
onEvent / onAboveWriteBufferHighWatermark / onBelowWriteBufferLowWatermark,
but nothing ever registered an McpServer instance as a connection's
ConnectionCallbacks. Per-TCP-connection events go through the
ConnectionLifecycleCallbacks adapter added in onNewConnection, which
carries the closing connection's identity. The stdio event path reaches
McpServer::onConnectionEvent through ServerProtocolCallbacks, not through
ConnectionCallbacks::onEvent.

Removing the base and its three overrides deletes dead code and makes
the class interface honest about which callback surfaces it actually
uses. onConnectionEvent itself stays: it is still the stats-and-
forwarding path for stdio transports via ServerProtocolCallbacks.

All McpServer/McpClient/StdioEcho/TcpEcho integration tests still pass.
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.

2 participants