77from mcp .shared .session import BaseSession
88from mcp .types import (
99 METHOD_NOT_FOUND ,
10+ TASK_FORBIDDEN ,
11+ TASK_REQUIRED ,
1012 ClientCapabilities ,
1113 ErrorData ,
1214 RequestId ,
@@ -54,12 +56,13 @@ def validate_task_mode(
5456 Validate that the request is compatible with the tool's task execution mode.
5557
5658 Per MCP spec:
57- - "always ": Clients MUST invoke as task. Server returns -32601 if not.
58- - "never " (or None): Clients MUST NOT invoke as task. Server returns -32601 if they do.
59+ - "required ": Clients MUST invoke as task. Server returns -32601 if not.
60+ - "forbidden " (or None): Clients MUST NOT invoke as task. Server returns -32601 if they do.
5961 - "optional": Either is acceptable.
6062
6163 Args:
62- tool_task_mode: The tool's execution.task value ("never", "optional", "always", or None)
64+ tool_task_mode: The tool's execution.taskSupport value
65+ ("forbidden", "optional", "required", or None)
6366 raise_error: If True, raises McpError on validation failure. If False, returns ErrorData.
6467
6568 Returns:
@@ -69,16 +72,16 @@ def validate_task_mode(
6972 McpError: If invalid and raise_error=True
7073 """
7174
72- mode = tool_task_mode or "never"
75+ mode = tool_task_mode or TASK_FORBIDDEN
7376
7477 error : ErrorData | None = None
7578
76- if mode == "always" and not self .is_task :
79+ if mode == TASK_REQUIRED and not self .is_task :
7780 error = ErrorData (
7881 code = METHOD_NOT_FOUND ,
7982 message = "This tool requires task-augmented invocation" ,
8083 )
81- elif mode == "never" and self .is_task :
84+ elif mode == TASK_FORBIDDEN and self .is_task :
8285 error = ErrorData (
8386 code = METHOD_NOT_FOUND ,
8487 message = "This tool does not support task-augmented invocation" ,
@@ -107,24 +110,24 @@ def validate_for_tool(
107110 Returns:
108111 None if valid, ErrorData if invalid and raise_error=False
109112 """
110- mode = tool .execution .task if tool .execution else None
113+ mode = tool .execution .taskSupport if tool .execution else None
111114 return self .validate_task_mode (mode , raise_error = raise_error )
112115
113116 def can_use_tool (self , tool_task_mode : TaskExecutionMode | None ) -> bool :
114117 """
115118 Check if this client can use a tool with the given task mode.
116119
117120 Useful for filtering tool lists or providing warnings.
118- Returns False if tool requires "always " but client doesn't support tasks.
121+ Returns False if tool requires "required " but client doesn't support tasks.
119122
120123 Args:
121- tool_task_mode: The tool's execution.task value
124+ tool_task_mode: The tool's execution.taskSupport value
122125
123126 Returns:
124127 True if the client can use this tool, False otherwise
125128 """
126- mode = tool_task_mode or "never"
127- if mode == "always" and not self .client_supports_tasks :
129+ mode = tool_task_mode or TASK_FORBIDDEN
130+ if mode == TASK_REQUIRED and not self .client_supports_tasks :
128131 return False
129132 return True
130133
0 commit comments