core: a client can register its own communication protocol instance
Why
UtcpClient copies the global CommunicationProtocol.communicationProtocols registry into a private per-client map at construction, and nothing public could change that map afterwards. A caller that needs a protocol instance that is not shared across clients ā one MCP session per user, one connection per pooled entry ā had to reach into _registeredCommProtocols directly, which any minor release could rename out from under it.
What
client.registerCommunicationProtocol(type, protocol) ā sets the instance this client uses for a call template type.
- Applies to this client only: the global registry and every other client are untouched.
close()closes the instances the client holds at that time (so a per-client instance is closed with its client).- Call before
registerManual; a manual already registered through the previous instance keeps its connection there ā documented on the method and in the README's plugin-registration section.
No version bump in this PR, per the repo's separate chore: bump convention.
Tests
Three new tests in tests/utcp_client.test.ts, mirroring the existing allowed_communication_protocols block's save/restore of the global registry: calls route to the instance the client was given; the global registry and a client created afterwards are unaffected; close() closes the per-client instance. Full file 11/11 green.
š¤ Generated with Claude Code
Summary by cubic
Adds UtcpClient.registerCommunicationProtocol() so a client can use its own protocol instance instead of the process-wide registry copied at construction.
- Previously, callers needing per-client protocol state had to reach into the private
_registeredCommProtocolsmap. - The instance applies only to that client; the global registry and other clients are untouched.
close()closes the instances the client holds at that time.- Call it before
registerManual; manuals registered through the previous instance keep their connection there. - Adds tests for routing, isolation from the global registry, and
close()behavior.