_sdk.py

clew/mcp_server/_sdk.py

The ONE place that imports the MCP SDK's server class, and names the module it needs.

lowlevel

Any clew.mcp_server._sdk.lowlevel(Any server)

The low-level Server behind an SDK server instance.

clew/mcp_server/_sdk.py:97

Source · 18 lines
def lowlevel(server: Any) -> Any:
    """Fails LOUDLY and by name if the attribute is gone: a private hook that vanishes
    should stop the server, not silently drop the capability that makes tier-1
    discoverable.

    @brief Reach the low-level server through its private attribute.
    @return The low-level Server.
    @version 2
    """
    try:
        return getattr(server, LOWLEVEL_ATTR)
    except AttributeError as exc:  # pragma: no cover — a future SDK generation
        raise AttributeError(
            f"the installed mcp SDK has no {LOWLEVEL_ATTR!r}; "
            "clew.mcp_server._sdk needs updating for this version"
        ) from exc

Activity · 4 steps
lines 106–106trylines 107–107return getattr(server, LOWLEVEL_ATTR)lines 108–108except AttributeError as exc: # pragma: no cover — a future SDK generationlines 109–112raise AttributeError( f"the installed mcp SDK has no {LOWLEVEL_ATTR!r}; " "clew.mcp_server._sdk needs updating for this version" ) from exc

Requirements

REQ-DDB-MCP-001

Flows

protocol_version

str clew.mcp_server._sdk.protocol_version(Any session)

The protocol revision a session's connection negotiated, or "".

clew/mcp_server/_sdk.py:144

Show on the map →

Called by send

Calls none

Source · 6 lines
def protocol_version(session: Any) -> str:
    """@brief Negotiated revision. @return Text."""
    connection = getattr(session, "_connection", None)
    return str(getattr(connection, "protocol_version", "") or "")

Activity · 2 steps
lines 146–146connection = getattr(session, "_connection", None)lines 147–147return str(getattr(connection, "protocol_version", "") or "")

Requirements

REQ-DDB-WIKI-054

raw_notify

None clew.mcp_server._sdk.raw_notify(Any session, str method, dict[str, Any] params)

Send a notification the SDK has no type for, on a session's connection.

clew/mcp_server/_sdk.py:122

Show on the map →

Called by send

Calls none

Source · 17 lines
async def raw_notify(session: Any, method: str, params: dict[str, Any]) -> None:
    """THE SECOND REACH THROUGH THE SDK'S PRIVACY, kept here beside the first (`lowlevel`). The
    typed `send_notification` takes only the SDK's own notification union, and Claude Code's
    `notifications/claude/channel` (2.1 wiki comments) is not in it; the session's connection
    carries the raw `notify` the typed path itself ends in. Fails by name if a future SDK drops it.

    @brief Raw notify.
    @return None.
    """
    connection = getattr(session, "_connection", None)
    if connection is None:  # pragma: no cover — a future SDK generation
        raise AttributeError(
            "the installed mcp SDK's session has no _connection; update clew.mcp_server._sdk"
        )
    await connection.outbound.notify(method, params)

Activity · 4 steps
lines 131–131connection = getattr(session, "_connection", None)lines 132–132◇ if connection is None: # pragma: no cover — a future SDK generationlines 133–135raise AttributeError( "the installed mcp SDK's session has no _connection; update clew.mcp_server._sdk" )lines 136–136await connection.outbound.notify(method, params)

Requirements

REQ-DDB-WIKI-054