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

Function handleChannelEnable

src/cli/print.ts:4696–4802  ·  view source on GitHub ↗

* IDE-triggered channel enable. Derives the ChannelEntry from the connection's * pluginSource (IDE can't spoof kind/marketplace — we only take the server * name), appends it to session allowedChannels, and runs the full gate. On * gate failure, rolls back the append. On success, registers a notif

(
  requestId: string,
  serverName: string,
  connectionPool: readonly MCPServerConnection[],
  output: Stream<StdoutMessage>,
)

Source from the content-addressed store, hash-verified

4694 * interactive either.)
4695 */
4696function handleChannelEnable(
4697 requestId: string,
4698 serverName: string,
4699 connectionPool: readonly MCPServerConnection[],
4700 output: Stream<StdoutMessage>,
4701): void {
4702 const respondError = (error: string) =>
4703 output.enqueue({
4704 type: 'control_response',
4705 response: { subtype: 'error', request_id: requestId, error },
4706 })
4707
4708 if (!(feature('KAIROS') || feature('KAIROS_CHANNELS'))) {
4709 return respondError('channels feature not available in this build')
4710 }
4711
4712 // Only a 'connected' client has .capabilities and .client to register the
4713 // handler on. The pool spread at the call site matches mcp_status.
4714 const connection = connectionPool.find(
4715 c => c.name === serverName && c.type === 'connected',
4716 )
4717 if (!connection || connection.type !== 'connected') {
4718 return respondError(`server ${serverName} is not connected`)
4719 }
4720
4721 const pluginSource = connection.config.pluginSource
4722 const parsed = pluginSource ? parsePluginIdentifier(pluginSource) : undefined
4723 if (!parsed?.marketplace) {
4724 // No pluginSource or @-less source — can never pass the {plugin,
4725 // marketplace}-keyed allowlist. Short-circuit with the same reason the
4726 // gate would produce.
4727 return respondError(
4728 `server ${serverName} is not plugin-sourced; channel_enable requires a marketplace plugin`,
4729 )
4730 }
4731
4732 const entry: ChannelEntry = {
4733 kind: 'plugin',
4734 name: parsed.name,
4735 marketplace: parsed.marketplace,
4736 }
4737 // Idempotency: don't double-append on repeat enable.
4738 const prior = getAllowedChannels()
4739 const already = prior.some(
4740 e =>
4741 e.kind === 'plugin' &&
4742 e.name === entry.name &&
4743 e.marketplace === entry.marketplace,
4744 )
4745 if (!already) setAllowedChannels([...prior, entry])
4746
4747 const gate = gateChannelServer(
4748 serverName,
4749 connection.capabilities,
4750 pluginSource,
4751 )
4752 if (gate.action === 'skip') {
4753 // Rollback — only remove the entry we appended.

Callers 1

runHeadlessStreamingFunction · 0.85

Calls 11

respondErrorFunction · 0.85
parsePluginIdentifierFunction · 0.85
getAllowedChannelsFunction · 0.85
setAllowedChannelsFunction · 0.85
gateChannelServerFunction · 0.85
logMCPDebugFunction · 0.85
enqueueFunction · 0.85
wrapChannelMessageFunction · 0.85
keysMethod · 0.80
logEventFunction · 0.50
enqueueMethod · 0.45

Tested by

no test coverage detected