XjjdZddlmZddlZddlmZddlmZmZm Z m Z m Z m Z ddl mZddlmZddlmZe d e ZGd d eeeZGd deZGddeZeeezezZGddeZeezezZeeeefZddZddZ ddZ! d ddZ" d ddZ#y)z&Elicitation utilities for MCP servers.) annotationsN)Sequence)GenericLiteralTypeVarUnionget_args get_origin) BaseModel) ServerSession) RequestIdElicitSchemaModelT)boundc*eZdZUdZdZded<ded<y)AcceptedElicitationz)Result when user accepts the elicitation.acceptLiteral['accept']actionrdataN__name__ __module__ __qualname____doc__r__annotations__j/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/mcp/server/elicitation.pyrrs3 (F ( rrc eZdZUdZdZded<y)DeclinedElicitationz*Result when user declines the elicitation.declinezLiteral['decline']rNrrrrr r s4!*F *rr c eZdZUdZdZded<y)CancelledElicitationz)Result when user cancels the elicitation.cancelzLiteral['cancel']rNrrrrr#r#s3 (F (rr#c eZdZUdZdZded<y)AcceptedUrlElicitationz0Result when user accepts a URL mode elicitation.rrrNrrrrr&r&'s: (F (rr&c|jjD]S\}}|j}||tjur't |r3t |r?td|dtdy)zCValidate that a Pydantic model only contains primitive field types.NzElicitation schema field 'z' must be a primitive type zw, a sequence of strings (list[str], etc.), or Optional of these types. Nested models and complex types are not allowed.) model_fieldsitems annotationtypesNoneType_is_primitive_field_is_string_sequence TypeError_ELICITATION_PRIMITIVE_TYPES)schema field_name field_infor*s r_validate_elicitation_schemar44s"("5"5";";"= J**  u~~!=   ,   , ,ZL8S/01_` rct|}|r9 t|tr&t|}t |dk(xr |dt uS yy#t $rYywxYw)zMCheck if annotation is a sequence of strings (list[str], Sequence[str], etc).rF)r issubclassrr lenstrr/r*originargss rr.r.Gsd  #F  &(+ +4yA~8$q'S.8,     s5A AAc|tvryt|}|tus|tjurt |}t d|DSy)zDCheck if a field is a primitive type allowed in elicitation schemas.Tc3nK|]-}|tjuxs|tvxs t|/ywN)r+r,r0r.).0args r z&_is_primitive_field..bs8 ilC5>> ! dS,H%H dL_`cLd d s35F)r0r rr+ UnionTyper allr:s rr-r-WsW11 #F &EOO3 # pt    rcKt||j}|j|||d{}|jdk(r3|j'|j |j}t |S|jdk(r tS|jdk(r tStd|j7w)a)Elicit information from the client/user with schema validation (form mode). This method can be used to interactively ask for additional information from the client within a tool's execution. The client might display the message to the user and collect a response according to the provided schema. Or in case a client is an agent, it might decide how to handle the elicitation -- either by asking the user or automatically generating a response. For sensitive data like credentials or OAuth flows, use elicit_url() instead. )messagerequestedSchemarelated_request_idNr)rr!r$Unexpected elicitation action: ) r4model_json_schema elicit_formrcontentmodel_validaterr r# ValueError)sessionrFr1rH json_schemaresultvalidated_datas relicit_with_validationrSis"!(**,K&&#-'F }} V^^%?..v~~>"77 ) #"$$ ( "#%%:6==/JKK!s3CCBCcK|j||||d{}|jdk(r tS|jdk(r tS|jdk(r t St d|j7gw)a[Elicit information from the user via out-of-band URL navigation (URL mode). This method directs the user to an external URL where sensitive interactions can occur without passing data through the MCP client. Use this for: - Collecting sensitive credentials (API keys, passwords) - OAuth authorization flows with third-party services - Payment and subscription flows - Any interaction where data should not pass through the LLM context The response indicates whether the user consented to navigate to the URL. The actual interaction happens out-of-band. When the elicitation completes, the server should send an ElicitCompleteNotification to notify the client. Args: session: The server session message: Human-readable explanation of why the interaction is needed url: The URL the user should navigate to elicitation_id: Unique identifier for tracking this elicitation related_request_id: Optional ID of the request that triggered this elicitation Returns: UrlElicitationResult indicating accept, decline, or cancel )rFurlelicitation_idrHNrr!r$rI) elicit_urlrr&r r#rN)rOrFrUrVrHrQs rrWrWs<%% %- &F}} %'' ) #"$$ ( "#%%:6==/JKKsBBA(B)r1ztype[BaseModel]returnNone)r*typerXboolr?) rOr rFr9r1ztype[ElicitSchemaModelT]rHRequestId | NonerXz%ElicitationResult[ElicitSchemaModelT]) rOr rFr9rUr9rVr9rHr\rXUrlElicitationResult)$r __future__rr+collections.abcrtypingrrrrr r pydanticr mcp.server.sessionr mcp.typesr rrr r#ElicitationResultr&r]r9intfloatr[r0r4r.r-rSrWrrrrgs<," $II,1C)W-?%@+)+ )9) ((:;>QQThh)Y) .0CCFZZ!$S%6&  ,,0 %L %L %L %%L) %L + %LZ,0 -L -L -L -L -L ) -L  -Lr