* 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, )
| 4818 | * check. |
| 4819 | */ |
| 4820 | function 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. |
no test coverage detected