MCPcopy
hub / github.com/codeaashu/claude-code / reregisterChannelHandlerAfterReconnect

Function reregisterChannelHandlerAfterReconnect

src/cli/print.ts:4786–4835  ·  view source on GitHub ↗

* Re-register the channel notification handler after mcp_reconnect / * mcp_toggle creates a new client. handleChannelEnable bound the handler to * the OLD client object; allowedChannels survives the reconnect but the * handler binding does not. Without this, channel messages silently drop * afte

(
  connection: MCPServerConnection,
)

Source from the content-addressed store, hash-verified

4784 * check.
4785 */
4786function reregisterChannelHandlerAfterReconnect(
4787 connection: MCPServerConnection,
4788): void {
4789 if (!(feature('KAIROS') || feature('KAIROS_CHANNELS'))) return
4790 if (connection.type !== 'connected') return
4791
4792 const gate = gateChannelServer(
4793 connection.name,
4794 connection.capabilities,
4795 connection.config.pluginSource,
4796 )
4797 if (gate.action !== 'register') return
4798
4799 const entry = findChannelEntry(connection.name, getAllowedChannels())
4800 const pluginId =
4801 entry?.kind === 'plugin'
4802 ? (`${entry.name}@${entry.marketplace}` as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
4803 : undefined
4804
4805 logMCPDebug(
4806 connection.name,
4807 'Channel notifications re-registered after reconnect',
4808 )
4809 connection.client.setNotificationHandler(
4810 ChannelMessageNotificationSchema(),
4811 async notification => {
4812 const { content, meta } = notification.params
4813 logMCPDebug(
4814 connection.name,
4815 `notifications/claude/channel: ${content.slice(0, 80)}`,
4816 )
4817 logEvent('tengu_mcp_channel_message', {
4818 content_length: content.length,
4819 meta_key_count: Object.keys(meta ?? {}).length,
4820 entry_kind:
4821 entry?.kind as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
4822 is_dev: entry?.dev ?? false,
4823 plugin: pluginId,
4824 })
4825 enqueue({
4826 mode: 'prompt',
4827 value: wrapChannelMessage(connection.name, content, meta),
4828 priority: 'next',
4829 isMeta: true,
4830 origin: { kind: 'channel', server: connection.name },
4831 skipSlashCommands: true,
4832 })
4833 },
4834 )
4835}
4836
4837/**
4838 * Emits an error message in the correct format based on outputFormat.

Callers 2

drainCommandQueueFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 9

featureFunction · 0.85
gateChannelServerFunction · 0.85
findChannelEntryFunction · 0.85
getAllowedChannelsFunction · 0.85
logMCPDebugFunction · 0.85
logEventFunction · 0.85
enqueueFunction · 0.85
wrapChannelMessageFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected