Validate that the client supports sampling tools if tools are being used. Args: client_caps: The client's declared capabilities tools: The tools list, if provided tool_choice: The tool choice setting, if provided Raises: MCPError: If tools/tool_choice are pr
(
client_caps: ClientCapabilities | None,
tools: list[Tool] | None,
tool_choice: ToolChoice | None,
)
| 27 | |
| 28 | |
| 29 | def validate_sampling_tools( |
| 30 | client_caps: ClientCapabilities | None, |
| 31 | tools: list[Tool] | None, |
| 32 | tool_choice: ToolChoice | None, |
| 33 | ) -> None: |
| 34 | """Validate that the client supports sampling tools if tools are being used. |
| 35 | |
| 36 | Args: |
| 37 | client_caps: The client's declared capabilities |
| 38 | tools: The tools list, if provided |
| 39 | tool_choice: The tool choice setting, if provided |
| 40 | |
| 41 | Raises: |
| 42 | MCPError: If tools/tool_choice are provided but client doesn't support them |
| 43 | """ |
| 44 | if tools is not None or tool_choice is not None: |
| 45 | if not check_sampling_tools_capability(client_caps): |
| 46 | raise MCPError(code=INVALID_PARAMS, message="Client does not support sampling tools capability") |
| 47 | |
| 48 | |
| 49 | def validate_tool_use_result_messages(messages: list[SamplingMessage]) -> None: |