MCPcopy Create free account
hub / github.com/Noumena-Network/code / reregisterChannelHandlerAfterReconnect

Function reregisterChannelHandlerAfterReconnect

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

4818 * check.
4819 */
4820function reregisterChannelHandlerAfterReconnect(
4821 connection: MCPServerConnection,
4822): void {
4823 if (!(feature('KAIROS') || feature('KAIROS_CHANNELS'))) return
4824 if (connection.type !== 'connected') return
4825
4826 const gate = gateChannelServer(
4827 connection.name,
4828 connection.capabilities,
4829 connection.config.pluginSource,
4830 )
4831 if (gate.action !== 'register') return
4832
4833 const entry = findChannelEntry(connection.name, getAllowedChannels())
4834 const pluginId =
4835 entry?.kind === 'plugin'
4836 ? (`${entry.name}@${entry.marketplace}` as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
4837 : undefined
4838
4839 logMCPDebug(
4840 connection.name,
4841 'Channel notifications re-registered after reconnect',
4842 )
4843 connection.client.setNotificationHandler(
4844 ChannelMessageNotificationSchema(),
4845 async notification => {
4846 const { content, meta } = notification.params
4847 logMCPDebug(
4848 connection.name,
4849 `notifications/claude/channel: ${content.slice(0, 80)}`,
4850 )
4851 logEvent('ncode_mcp_channel_message', {
4852 content_length: content.length,
4853 meta_key_count: Object.keys(meta ?? {}).length,
4854 entry_kind:
4855 entry?.kind as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
4856 is_dev: entry?.dev ?? false,
4857 plugin: pluginId,
4858 })
4859 enqueue({
4860 mode: 'prompt',
4861 value: wrapChannelMessage(connection.name, content, meta),
4862 priority: 'next',
4863 isMeta: true,
4864 origin: { kind: 'channel', server: connection.name },
4865 skipSlashCommands: true,
4866 })
4867 },
4868 )
4869}
4870
4871/**
4872 * 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
enqueueFunction · 0.85
wrapChannelMessageFunction · 0.85
keysMethod · 0.80
logEventFunction · 0.50

Tested by

no test coverage detected