xjgdZddlmZddlmZmZmZmZddlm Z ddl m Z ddl m Z mZddlmZmZddlmZdd lmZdd lmZed e ZGd de eeZGdde ZGdde ZedeeezezefZGdde ZeezezZGddeZddZ ddZ! d d!dZ" d d"dZ#y)#z&Elicitation utilities for MCP servers.) annotations)AnyGenericLiteralTypeVar) RequestId)PrimitiveSchemaDefinition) BaseModelValidationError)GenerateJsonSchemaJsonSchemaValue) core_schema) TypeAliasType) ServerSessionElicitSchemaModelT)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/sandbox/mcp-query/venv/lib/python3.12/site-packages/mcp/server/elicitation.pyrrs3 (F ( r rc eZdZUdZdZded<y)DeclinedElicitationz*Result when user declines the elicitation.declinezLiteral['decline']rNrrr r!r#r#s4!*F *r r#c eZdZUdZdZded<y)CancelledElicitationz)Result when user cancels the elicitation.cancelzLiteral['cancel']rNrrr r!r&r&"s3 (F (r r&ElicitationResult) type_paramsc eZdZUdZdZded<y)AcceptedUrlElicitationz0Result when user accepts a URL mode elicitation.rrrNrrr r!r+r+/s: (F (r r+c,eZdZdZddZdfd ZxZS)_ElicitationJsonSchemaa#JSON-Schema generator that flattens `T | None` to `T` and drops `None` defaults. The spec's `PrimitiveSchemaDefinition` admits no `anyOf` or null type; an optional field is expressed by leaving it out of `required`, which pydantic already does for any field with a default. c*|j|dS)Nschema)generate_inner)selfr/s r!nullable_schemaz&_ElicitationJsonSchema.nullable_schema@s""6(#344r clt||}|jd|jdd|S)Ndefault)superdefault_schemagetpop)r1r/result __class__s r!r6z%_ElicitationJsonSchema.default_schemaCs4'/ ::i ( JJy$ ' r )r/zcore_schema.NullableSchemareturnr )r/zcore_schema.WithDefaultSchemar;r )rrrrr2r6 __classcell__)r:s@r!r-r-8s5r r-c |jdijD]\}} tj|y#t$rt d|d|ddwxYw)zReject any `properties` entry the spec's `PrimitiveSchemaDefinition` won't accept. Catches whatever the renderer let through that isn't spec-valid: bare `list[str]` (no enum), multi-primitive unions, nested models. propertieszElicitation schema field z rendered as z0, which is not a valid PrimitiveSchemaDefinitionN)r7itemsr model_validater TypeError) json_schema field_nameprops r!_validate_rendered_propertiesrEJs| (OOL"=CCE D  % 4 4T : +J>thOAB  s AAcH|jt}t||S)zRender a model as the spec-valid `requested_schema` for an elicitation. Raises: TypeError: If a field renders as something the spec's `PrimitiveSchemaDefinition` does not accept. )schema_generator)model_json_schemar-rE)r/rBs r!render_elicitation_schemarIZs&**> !OP P #226>>BN #77 }} !"$$  !!% d  s3#B:B*B:B,0B: B7& B22B77B:cK|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 )rKurlelicitation_idrMNrr$r'zUnexpected elicitation action: ) elicit_urlrr+r#r&rP)rQrKrVrWrMr9s r!rXrXs<%% %- &F}} %'' ) #"$$ ( "#%%:6==/JKKsBBA(B)rBdict[str, Any]r;None)r/ztype[BaseModel]r;rY)N) rQrrKstrr/ztype[ElicitSchemaModelT]rMRequestId | Noner;z%ElicitationResult[ElicitSchemaModelT]) rQrrKr[rVr[rWr[rMr\r;UrlElicitationResult)$r __future__rtypingrrrr mcp_typesrmcp_types._v2025_11_25r pydanticr r pydantic.json_schemar r pydantic_corertyping_extensionsrmcp.server.sessionrrrr#r&r(r+r]r-rErIrTrXrr r!rgsF,"11=/D%+,1C)W-?%@+)+ )9) "*+.AADXX#%)Y) .0CCFZZ/$   ,0 (" (" (" %(") (" + ("`,0 -L -L -L -L -L ) -L  -Lr