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

Function reregisterChannelHandlerAfterReconnect

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

5019 * check.
5020 */
5021function reregisterChannelHandlerAfterReconnect(
5022 connection: MCPServerConnection,
5023): void {
5024 // Channels always available — feature flag guard removed
5025 if (connection.type !== 'connected') return
5026
5027 const gate = gateChannelServer(
5028 connection.name,
5029 connection.capabilities,
5030 connection.config.pluginSource,
5031 )
5032 if (gate.action !== 'register') return
5033
5034 const entry = findChannelEntry(connection.name, getAllowedChannels())
5035 const pluginId =
5036 entry?.kind === 'plugin'
5037 ? (`${entry.name}@${entry.marketplace}` as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
5038 : undefined
5039
5040 logMCPDebug(
5041 connection.name,
5042 'Channel notifications re-registered after reconnect',
5043 )
5044 connection.client.setNotificationHandler(
5045 ChannelMessageNotificationSchema() as any,
5046 async notification => {
5047 const { content, meta } = notification.params
5048 logMCPDebug(
5049 connection.name,
5050 `notifications/claude/channel: ${content.slice(0, 80)}`,
5051 )
5052 logEvent('tengu_mcp_channel_message', {
5053 content_length: content.length,
5054 meta_key_count: Object.keys(meta ?? {}).length,
5055 entry_kind:
5056 entry?.kind as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
5057 is_dev: entry?.dev ?? false,
5058 plugin: pluginId,
5059 })
5060 enqueue({
5061 mode: 'prompt',
5062 value: wrapChannelMessage(connection.name, content, meta),
5063 priority: 'next',
5064 isMeta: true,
5065 origin: {
5066 kind: 'channel',
5067 server: connection.name,
5068 } as unknown as string,
5069 skipSlashCommands: true,
5070 })
5071 },
5072 )
5073}
5074
5075/**
5076 * Emits an error message in the correct format based on outputFormat.

Callers 2

drainCommandQueueFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 9

gateChannelServerFunction · 0.85
getAllowedChannelsFunction · 0.85
logMCPDebugFunction · 0.85
logEventFunction · 0.85
wrapChannelMessageFunction · 0.85
keysMethod · 0.65
findChannelEntryFunction · 0.50
enqueueFunction · 0.50

Tested by

no test coverage detected