MCPcopy Create free account
hub / github.com/oboard/claude-code-rev / reregisterChannelHandlerAfterReconnect

Function reregisterChannelHandlerAfterReconnect

src/cli/print.ts:4791–4840  ·  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

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

Callers 2

drainCommandQueueFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 8

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