xj UdZddlmZddlmZmZmZddlmZddl m Z m Z m Z m Z mZmZmZddlmZmZmZmZddlmZddlmZmZmZdd lmZdd lmZe rdd l m!Z!gd Z"e#d hZ$de%d< e#ddhZ&de%d< d'dZ'edeZ(edeZ)eddGddZ*eddGdde e(Z+Gdde,Z-eddGdd e e)Z.Gd!d"Z/Gd#d$e/Z0d(d)d&Z1y%)*zOpt-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()`. ) annotations) AwaitableCallableSequence) dataclass) TYPE_CHECKINGAnyFinalGenericLiteralTypeVarget_args)CORE_RESULT_TYPESCallToolResultInputRequiredResultResult)MODERN_PROTOCOL_VERSIONS) AliasChoices AliasPath BaseModel) FieldInfo)validate_extension_identifier) ClientSession) ClaimContextClientExtensionNotificationBinding ResultClaimUnexpectedClaimedResult advertise tools/callzFinal[frozenset[str]]_CLAIM_METHODS requestState inputRequests_RESERVED_WIRE_ALIASEScn|jxs|h}|jr|j|j|j}t |t r |j n|g}|D]C}t |tr|jd}t |ts3|j|Et|S)z>Every top-level wire key this field can read from or write to.r) aliasserialization_aliasaddvalidation_alias isinstancerchoicesrpathstr frozenset)namefieldkeysr)r+choices h/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/mcp/client/extension.py _wire_keysr4(s KK 4 D    **+--*45E|*T&&[kZlG fi ([[^F fc " HHV   T?ClaimedT)bound NotifyParamsTT)frozenkw_onlyc0eZdZUdZded<ded<ded<y) rz9Host-injected context for one `ResultClaim.resolve` call.rsessionr- tool_namez float | Noneread_timeout_secondsN__name__ __module__ __qualname____doc____annotations__r5r3rr;sC N&&r5rcTeZdZUdZded<ded<ded<dZd ed <d Zd ed <ddZy )raOne 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. r- result_typeztype[ClaimedT]modelz=Callable[[ClaimedT, ClaimContext], Awaitable[CallToolResult]]resolver zLiteral['tools/call']methodNzfrozenset[str] | Noneprotocol_versionsc |jtvr(tdttd|j|jt vrtd|jdt |jjvr"t|jjdt|jttzr td|jjjD]M\}}tt||t zD])}t|jjd|d|d O|jjj#d }|#t%|j&|jfk7r/t|jjd |jd |j(|j(s td |j(W|j(j+t,s7t|j(j/t,}td|dyy)Nzclaims attach to z only; got method z resultType z is core protocol vocabularyz must subclass mcp_types.Resultz0claim models must not subclass core result types.z aliases zv, a typed field of the core result surface; a colliding value would fail core validation before the claim adapter runsrGz.result_type must be Literal[]z>empty protocol_versions could never activate; use None for allzprotocol_versions zy are not modern protocol revisions; claimed shapes cannot be delivered on a legacy wire (None means every modern version))rJr! ValueErrorsortedrGrrrH__mro__r@ issubclassrr model_fieldsitemsr4r$getr annotationrKissubsetr difference)selfr/ model_fieldclashr0 unrecognizeds r3 __post_init__zResultClaim.__post_init__Ts ;;n ,01G0HHZ[_[f[fZijk k   0 0{4+;+;*>>Z[\ \ ++ + 3 344STU U djj.3F"F GOP P!%!8!8!>!>!@  D+ 4 =@V VW  zz**+1TF)E9E))   ''++M: =HU%5%564;K;K:MM 3 344QRVRbRbQeefgh h  ! ! -d6L6L]^ ^  ! ! -d6L6L6U6UVn6o!$"8"8"C"CD\"]^L$\N3YY 7p -r5)returnNone)r@rArBrCrDrJrKr]rEr5r3rrDs7  JJ$0F !0/3,3r5rc$eZdZdZdfd ZxZS)rzA 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`. c`t|dt|jd||_y)Nz"Server returned a claimed result (z); pass the owning extension to Client(extensions=[...]) for transparent resolution, or call with allow_claimed=True and handle the shape. The carried result may reference server-side state needing cleanup.)super__init__typer@result)rYre __class__s r3rcz UnexpectedClaimedResult.__init__xs8 0f1F1F0GHh h  r5)rerr^r_)r@rArBrCrc __classcell__rfs@r3rrqs r5rc0eZdZUdZded<ded<ded<y) raDeliver 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. r-rJztype[NotifyParamsT] params_typez*Callable[[NotifyParamsT], Awaitable[None]]handlerNr?rEr5r3rrs K$$ 77r5rcHeZdZUdZded<dfd Zd dZd dZd dZxZ S) rzBase class for an opt-in client extension; override only what you need. The surface is declarative, fixed at construction, and never receives the client. r- identifierc t|di||jjdx}t ||j yy)NrmownerrE)rb__init_subclass____dict__rUrr@)clskwargsrmrfs r3rqz!ClientExtension.__init_subclass__sA !+F+,,**<8 8J E )*CLL I Fr5ciS)aPer-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. rErYs r3settingszClientExtension.settingss  r5cy)z@Extra result shapes this extension claims, with their resolvers.rErErvs r3claimszClientExtension.claimsr5cy)z-Server notifications this extension observes.rErErvs r3 notificationszClientExtension.notificationsrzr5)rtr r^r_r^dict[str, Any])r^zSequence[ResultClaim[Any]])r^z"Sequence[NotificationBinding[Any]]) r@rArBrCrDrqrwryr|rgrhs@r3rrs$ OJ r5rc eZdZdZddZddZy)_AdvertiseOnlyz,Ad-only extension returned by `advertise()`.c ||_||_yN)rm _settings)rYrmrws r3rcz_AdvertiseOnly.__init__s$!r5c|jSr)rrvs r3rwz_AdvertiseOnly.settingss ~~r5N)rmr-rwr~r^r_r})r@rArBrCrcrwrEr5r3rrs6"r5rNcDt|dt||iS|S)zAdvertise 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. rro)rr)rmrws r3rrs( "*K@ *H,rs*#99!QQQTT677%>0 )2<.(A%A^09>?:[0\-\_  :V ,y9  $%''&' $%)'(#)&)X l   $% 8'-0 8& 8B_Lr5