channel.py

clew/mcp_server/channel.py

Push a wiki comment into the Claude Code session as a channel event (2.1, opt-in).

attach_loop

None clew.mcp_server.channel.Channel.attach_loop(self)

Take the running event loop's token (call from inside the loop).

clew/mcp_server/channel.py:96

Show on the map →

Called by none

Calls none

Source · 4 lines
    def attach_loop(self) -> None:
        """@brief Loop token. @return None."""
        self.token = anyio.lowlevel.current_token()
Activity · 1 steps
lines 98–98self.token = anyio.lowlevel.current_token()

Requirements

REQ-DDB-WIKI-054

enabled

bool clew.mcp_server.channel.enabled()

Whether the server was started with the channel switch on.

clew/mcp_server/channel.py:53

Source · 5 lines
def enabled() -> bool:
    """@brief Switch. @return Bool."""
    return os.environ.get(CHANNEL_ENV) == "1"

Activity · 1 steps
lines 55–55return os.environ.get(CHANNEL_ENV) == "1"

Requirements

REQ-DDB-WIKI-054

experimental_capabilities

dict[str, dict[str, Any]] clew.mcp_server.channel.experimental_capabilities()

The experimental capabilities to declare at initialize.

clew/mcp_server/channel.py:62

Source · 5 lines
def experimental_capabilities() -> dict[str, dict[str, Any]]:
    """@brief Capabilities. @return Dict."""
    return {CAPABILITY: {}} if enabled() else {}

Activity · 1 steps
lines 64–64return {CAPABILITY: {}} if enabled() else {}

Requirements

REQ-DDB-WIKI-054

push_from_thread

bool clew.mcp_server.channel.Channel.push_from_thread(self, str repo, dict[str, Any] comment)

Push from a non-loop thread (the hub's), never raising.

clew/mcp_server/channel.py:106

Show on the map →

Called by none

Calls none

Source · 18 lines
    def push_from_thread(self, repo: str, comment: dict[str, Any]) -> bool:
        """A FAILED PUSH COSTS A LOG LINE, NEVER THE COMMENT: it is already stored, and the hook and
        `index(action='comments')` deliver it regardless.

        @brief Push from a thread.
        @return Sent.
        """
        if self.token is None:
            logger.info(
                "wiki comment %s: channel push skipped, no event loop attached", comment.get("id")
            )
            return False
        try:
            return bool(anyio.from_thread.run(self.send, repo, comment, token=self.token))
        except Exception as exc:  # noqa: BLE001 — a push must never fail the HTTP request
            logger.warning("wiki comment %s: channel push failed: %s", comment.get("id"), exc)
            return False
Activity · 8 steps
lines 113–113◇ if self.token is Nonelines 114–116logger.info( "wiki comment %s: channel push skipped, no event loop attached", comment.get("id") )lines 117–117return Falselines 118–118trylines 119–119return bool(anyio.from_thread.run(self.send, repo, comment, token=self.token))lines 120–120except Exception as exc: # noqa: BLE001 — a push must never fail the HTTP requestlines 121–121logger.warning("wiki comment %s: channel push failed: %s", comment.get("id"), exc)lines 122–122return False

Requirements

REQ-DDB-WIKI-054

remember

None clew.mcp_server.channel.Channel.remember(self, Any ctx)

Remember the session a tool call carried.

clew/mcp_server/channel.py:86

Show on the map →

Called by none

Calls none

Source · 6 lines
    def remember(self, ctx: Any) -> None:
        """@brief Remember. @return None."""
        session = getattr(ctx, "session", None)
        if session is not None:
            self.session = session
Activity · 3 steps
lines 88–88session = getattr(ctx, "session", None)lines 89–89◇ if session is not Nonelines 90–90self.session = session

Requirements

REQ-DDB-WIKI-054

send

bool clew.mcp_server.channel.Channel.send(self, str repo, dict[str, Any] comment)

Send one comment as a channel notification, when the session can receive it.

clew/mcp_server/channel.py:130

Show on the map →

Called by none

Calls _params, protocol_version, raw_notify

Source · 25 lines
    async def send(self, repo: str, comment: dict[str, Any]) -> bool:
        """`meta` KEYS ARE LETTERS, DIGITS AND UNDERSCORES: Claude Code drops any other key silently.

        @brief Send.
        @return Sent.
        """
        if self.session is None:
            logger.info(
                "wiki comment %s: channel push skipped, no session seen yet", comment.get("id")
            )
            return False
        version = protocol_version(self.session)
        if version in MODERN_PROTOCOL_VERSIONS:
            logger.info(
                "wiki comment %s: channel inactive on MCP %s (Claude Code registers channels only on "
                "earlier revisions); the hook and index(action='comments') still deliver it",
                comment.get("id"),
                version,
            )
            return False
        await raw_notify(self.session, METHOD, _params(repo, comment))
        logger.info("wiki comment %s pushed on the channel", comment.get("id"))
        return True

Activity · 10 steps
lines 136–136◇ if self.session is Nonelines 137–139logger.info( "wiki comment %s: channel push skipped, no session seen yet", comment.get("id") )lines 140–140return Falselines 141–141version = protocol_version(self.session)lines 142–142◇ if version in MODERN_PROTOCOL_VERSIONSlines 143–148logger.info( "wiki comment %s: channel inactive on MCP %s (Claude Code registers channels only on " "earlier revisions); the hook and index(action='comments') still deliver it", comment.get("id"), version, )lines 149–149return Falselines 150–150await raw_notify(self.session, METHOD, _params(repo, comment))lines 151–151logger.info("wiki comment %s pushed on the channel", comment.get("id"))lines 152–152return True

Requirements

REQ-DDB-WIKI-054