_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.
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
Requirements
Flows
protocol_version
str clew.mcp_server._sdk.protocol_version(Any session)
The protocol revision a session's connection negotiated, or "".
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
Requirements
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.
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)