+
    wi !                         R t ^ RIHtHt ^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHtHtHtHtHtHtHtHtHtHt ] ! R
 R4      4       tR# )a	  
Experimental request context features.

This module provides the Experimental class which gives access to experimental
features within a request context, such as task-augmented request handling.

WARNING: These APIs are experimental and may change without notice.
)	AwaitableCallable)	dataclassfield)Any)ServerTaskContext)TaskSupport)ServerSession)McpError)MODEL_IMMEDIATE_RESPONSE_KEYis_terminal)
METHOD_NOT_FOUNDTASK_FORBIDDENTASK_REQUIREDClientCapabilitiesCreateTaskResult	ErrorDataResultTaskExecutionModeTaskMetadataToolc                     a  ] tR t^!t o RtRt]! RRR7      t]! RRR7      t]! RRR7      t	]
V 3R lR l4       t]
V 3R lR l4       tR	R
/V 3R lR lltR	R
/V 3R lR lltV 3R lR ltRRRR/V 3R lR lltV 3R ltRtV tR# )Experimentalz
Experimental features context for task-augmented requests.

Provides helpers for validating task execution compatibility and
running tasks with automatic lifecycle management.

WARNING: This API is experimental and may change without notice.
NF)defaultreprc                    < V ^8  d   QhRS[ /#    returnbool)format__classdict__s   "[/home/ubuntu/.local/lib/python3.14/site-packages/mcp/server/experimental/request_context.py__annotate__Experimental.__annotate__2   s     . . .    c                    V P                   RJ# )z(Check if this request is task-augmented.N)task_metadataselfs   &r#   is_taskExperimental.is_task1   s     !!--r&   c                    < V ^8  d   QhRS[ /# r   r   )r!   r"   s   "r#   r$   r%   7   s     ; ;t ;r&   c                R    V P                   f   R# V P                   P                  RJ# )z*Check if the client declared task support.NF)_client_capabilitiestasksr)   s   &r#   client_supports_tasks"Experimental.client_supports_tasks6   s*     $$,((..d::r&   raise_errorTc                H   < V ^8  d   QhRS[ R,          RS[RS[R,          /# )r   tool_task_modeNr3   r   )r   r    r   )r!   r"   s   "r#   r$   r%   =   s3     , ,)D0, 	,
 
T	,r&   c                  T;'       g    \         pRpV\        8X  d%   V P                  '       g   \        \        RR7      pM.V\         8X  d$   V P                  '       d   \        \        RR7      pVe   V'       d   \        V4      hV# )a|  
Validate that the request is compatible with the tool's task execution mode.

Per MCP spec:
- "required": Clients MUST invoke as task. Server returns -32601 if not.
- "forbidden" (or None): Clients MUST NOT invoke as task. Server returns -32601 if they do.
- "optional": Either is acceptable.

Args:
    tool_task_mode: The tool's execution.taskSupport value
        ("forbidden", "optional", "required", or None)
    raise_error: If True, raises McpError on validation failure. If False, returns ErrorData.

Returns:
    None if valid, ErrorData if invalid and raise_error=False

Raises:
    McpError: If invalid and raise_error=True
Nz,This tool requires task-augmented invocation)codemessagez4This tool does not support task-augmented invocation)r   r   r+   r   r   r
   )r*   r5   r3   modeerrors   &&$  r#   validate_task_modeExperimental.validate_task_mode=   sq    4 //"&= %FE ^#%NE
 5/!r&   c                :   < V ^8  d   QhRS[ RS[RS[R,          /# )r   toolr3   r   N)r   r    r   )r!   r"   s   "r#   r$   r%   k   s3     F FF 	F
 
T	Fr&   c               z    VP                   '       d   VP                   P                  MRpV P                  W2R7      # )a?  
Validate that the request is compatible with the given tool.

Convenience wrapper around validate_task_mode that extracts the mode from a Tool.

Args:
    tool: The Tool definition
    raise_error: If True, raises McpError on validation failure.

Returns:
    None if valid, ErrorData if invalid and raise_error=False
N)r3   )	executiontaskSupportr;   )r*   r>   r3   r9   s   &&$ r#   validate_for_toolExperimental.validate_for_toolk   s1    $ .2^^^t~~))&&t&EEr&   c                4   < V ^8  d   QhRS[ R,          RS[/# )r   r5   Nr   )r   r    )r!   r"   s   "r#   r$   r%      s!      +<t+C  r&   c                d    T;'       g    \         pV\        8X  d   V P                  '       g   R# R# )aI  
Check if this client can use a tool with the given task mode.

Useful for filtering tool lists or providing warnings.
Returns False if tool requires "required" but client doesn't support tasks.

Args:
    tool_task_mode: The tool's execution.taskSupport value

Returns:
    True if the client can use this tool, False otherwise
FT)r   r   r1   )r*   r5   r9   s   && r#   can_use_toolExperimental.can_use_tool   s*     //= )C)C)Cr&   task_idmodel_immediate_responsec                v   < V ^8  d   QhRS[ S[.S[S[,          3,          RS[R,          RS[R,          RS[/# )r   workrH   NrI   r   )r   r   r   r   strr   )r!   r"   s   "r#   r$   r%      sZ     \N \N)*If,==>\N t	\N
 #&*\N 
\Nr&   c               ,  aa	"   V P                   f   \        R4      hV P                  f   \        R4      hV P                  f   \        R4      hV P                   pVP                  pVP
                  P                  V P                  V4      G Rj  xL
 p\        VVP
                  V P                  VP                  VP                  R7      o	R V	V3R llpVP                  V4       RpVe	   \        V/p\        R
RV/V'       d   R	V/B # / B #  L5i)a[  
Create a task, spawn background work, and return CreateTaskResult immediately.

This is the recommended way to handle task-augmented tool calls. It:
1. Creates a task in the store
2. Spawns the work function in a background task
3. Returns CreateTaskResult immediately

The work function receives a ServerTaskContext with:
- elicit() for sending elicitation requests
- create_message() for sampling requests
- update_status() for progress updates
- complete()/fail() for finishing the task

When work() returns a Result, the task is auto-completed with that result.
If work() raises an exception, the task is auto-failed.

Args:
    work: Async function that does the actual work
    task_id: Optional task ID (generated if not provided)
    model_immediate_response: Optional string to include in _meta as
        io.modelcontextprotocol/model-immediate-response

Returns:
    CreateTaskResult to return to the client

Raises:
    RuntimeError: If task support is not enabled or task_metadata is missing

Example:
    @server.call_tool()
    async def handle_tool(name: str, args: dict):
        ctx = server.request_context

        async def work(task: ServerTaskContext) -> CallToolResult:
            result = await task.elicit(
                message="Are you sure?",
                requestedSchema={"type": "object", ...}
            )
            confirmed = result.content.get("confirm", False)
            return CallToolResult(content=[TextContent(text="Done" if confirmed else "Cancelled")])

        return await ctx.experimental.run_task(work)

WARNING: This API is experimental and may change without notice.
NzHTask support not enabled. Call server.experimental.enable_tasks() first.zSession not available.zgRequest is not task-augmented (no task field in params). The client must send a task-augmented request.)taskstoresessionqueuehandlerc                    V ^8  d   QhRR/# )r   r   N )r!   s   "r#   r$   +Experimental.run_task.<locals>.__annotate__   s     	0 	0t 	0r&   c                    <"    S! S4      G R j  xL
 p \        SP                  P                  4      '       g   SP                  V 4      G R j  xL
  R # R #  LF L
  \         dZ   p\        SP                  P                  4      '       g*   SP                  \        T4      4      G R j  xL 
   R p?R #  R p?R # R p?ii ; i5i)N)r   rN   statuscomplete	ExceptionfailrL   )resultetask_ctxrK   s     r#   execute&Experimental.run_task.<locals>.execute   s     0#H~-"8==#7#788"++F333 9 .3 0"8==#7#788"--A/// 90s]   CA A=A AA CA A B?&AB:(B+)B:.C:B??CrN   _metarT   )_task_supportRuntimeError_sessionr(   
task_grouprO   create_taskr   rQ   rR   
start_soonr   r   )
r*   rK   rH   rI   supportrd   rN   r^   metar]   s
   &f$$     @r#   run_taskExperimental.run_task   s    j %ijj== 788%A 
 $$''
]]..t/A/A7KK$--MM--OO
	0 	0 	g&&*#/02JKDMTMgt_MM"MM3 Ls   BDDBDc                   < V ^8  d   Qh/ S[ R,          ;R&   S[R,          ;R&   S[R,          ;R&   S[R,          ;R&   # )r   Nr(   r/   rc   ra   )r   r   r	   r   )r!   r"   s   "r#   r$   r%   !   sM       $&-  -t3U  d"D  %G r&   rT   )__name__
__module____qualname____firstlineno____doc__r(   r   r/   rc   ra   propertyr+   r1   r;   rB   rF   ri   __annotate_func____static_attributes____classdictcell__)r"   s   @r#   r   r   !   s      *.M6;Du6U%*4e%DH(-d(GM. . ; ;, !	, ,\F !	F F* $\N #	\N
 04\N \Nc  r&   r   N) rp   collections.abcr   r   dataclassesr   r   typingr   $mcp.server.experimental.task_contextr   $mcp.server.experimental.task_supportr   mcp.server.sessionr	   mcp.shared.exceptionsr
   %mcp.shared.experimental.tasks.helpersr   r   	mcp.typesr   r   r   r   r   r   r   r   r   r   r   rT   r&   r#   <module>r~      sR    0 (  B < , * [   LN LN LNr&   