extension
Opt-in extension interface for MCP clients.
Subclass ClientExtension, set identifier, override the hooks you need, and
pass instances to Client(extensions=[...]). For an identifier-only
capability ad, use advertise().
ClaimContext
dataclass
Host-injected context for one ResultClaim.resolve call.
Source code in src/mcp/client/extension.py
59 60 61 62 63 64 65 | |
ResultClaim
dataclass
Bases: Generic[ClaimedT]
One extra result shape on one spec verb, keyed by the wire resultType.
Active only while the declaring extension is constructed into the client and
the negotiated protocol version admits it. resolve finishes a claimed
result, may send follow-ups through ctx.session, and must return the
verb's ordinary result. All field constraints are enforced at construction.
Source code in src/mcp/client/extension.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
UnexpectedClaimedResult
Bases: RuntimeError
A claimed (extension) result arrived on a call_tool that did not opt in.
The parsed value is carried as result; the server may already hold state it
references. Opt in via Client(extensions=[...]) or allow_claimed=True.
Source code in src/mcp/client/extension.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
NotificationBinding
dataclass
Bases: Generic[NotifyParamsT]
Deliver server notifications for method (the bare wire name) to handler.
Observation-only: validated params arrive one at a time per binding, in dispatch order, through a bounded queue that drops the oldest with a warning on overflow. Stream transports dispatch each notification independently, so near-simultaneous notifications may be dispatched out of wire order. Methods the negotiated version's core tables handle are never delivered to bindings.
Source code in src/mcp/client/extension.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
ClientExtension
Base class for an opt-in client extension; override only what you need.
The surface is declarative, fixed at construction, and never receives the client.
Source code in src/mcp/client/extension.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
settings
Per-extension settings advertised at ClientCapabilities.extensions[identifier].
Read once at Client construction. A claim-bearing extension is
advertised only at protocol versions where at least one of its claims
is active.
Source code in src/mcp/client/extension.py
160 161 162 163 164 165 166 167 | |
claims
claims() -> Sequence[ResultClaim[Any]]
Extra result shapes this extension claims, with their resolvers.
Source code in src/mcp/client/extension.py
169 170 171 | |
notifications
notifications() -> Sequence[NotificationBinding[Any]]
Server notifications this extension observes.
Source code in src/mcp/client/extension.py
173 174 175 | |
advertise
advertise(
identifier: str, settings: dict[str, Any] | None = None
) -> ClientExtension
Advertise an extension identifier (with optional settings) and nothing else.
Advertising an extension you do not implement asserts wire support you do not have; for behavioral extensions construct the real extension instead.
Source code in src/mcp/client/extension.py
189 190 191 192 193 194 195 196 | |