vllm_mlx.mcp.executor¶
Tool executor for handling tool calls from model responses.
View the complete module source at #L1-L500.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.mcp.executor
¶
Tool executor for handling tool calls from model responses.
vllm_mlx.mcp.executor.ToolArgumentValidationError
¶
Bases: Exception
Raised when tool arguments fail validation against schema.
vllm_mlx.mcp.executor.ToolExecutor
¶
ToolExecutor(manager: MCPClientManager, max_parallel: int = 5, default_timeout: Optional[float] = None, validate_arguments: bool = True, sandbox: Optional[ToolSandbox] = None)
Handles execution of tool calls from model responses.
Provides utilities for: - Extracting tool calls from responses - Executing multiple tool calls (parallel or sequential) - Formatting results for conversation - Validating tool arguments against schemas
Initialize tool executor.
Parameters:
-
manager(MCPClientManager) –MCP client manager
-
max_parallel(int, default:5) –Maximum parallel tool executions
-
default_timeout(Optional[float], default:None) –Default timeout for tool calls
-
validate_arguments(bool, default:True) –If True, validate arguments against tool schemas
-
sandbox(Optional[ToolSandbox], default:None) –Optional tool sandbox for security controls. Uses global if None.
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor.default_timeout
instance-attribute
¶
vllm_mlx.mcp.executor.ToolExecutor.validate_arguments
instance-attribute
¶
vllm_mlx.mcp.executor.ToolExecutor.execute_tool_calls
async
¶
execute_tool_calls(tool_calls: List[Dict[str, Any]], parallel: bool = True) -> List[Tuple[MCPToolResult, str]]
Execute multiple tool calls.
Parameters:
-
tool_calls(List[Dict[str, Any]]) –List of OpenAI tool call objects
-
parallel(bool, default:True) –Execute in parallel (True) or sequential (False)
Returns:
-
List[Tuple[MCPToolResult, str]]–List of (MCPToolResult, tool_call_id) tuples
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._get_tool_by_name
¶
_get_tool_by_name(full_name: str) -> Optional[MCPTool]
Get a tool by its full name (server__tool or just tool).
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._validate_tool_call
¶
Validate a tool call's arguments against the tool's schema.
Returns:
-
Optional[str]–Error message if validation fails, None if valid
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._validate_sandbox
¶
Validate tool execution against sandbox policy.
Returns:
-
Optional[str]–Error message if blocked, None if allowed
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._get_server_for_tool
¶
Extract server name from full tool name or find it.
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._execute_parallel
async
¶
_execute_parallel(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]]
Execute tool calls in parallel with concurrency limit.
Source code in vllm_mlx/mcp/executor.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
vllm_mlx.mcp.executor.ToolExecutor._execute_sequential
async
¶
_execute_sequential(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]]
Execute tool calls sequentially.
Source code in vllm_mlx/mcp/executor.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
vllm_mlx.mcp.executor.ToolExecutor.execute_and_format
async
¶
Execute tool calls and format results as messages.
Parameters:
-
tool_calls(List[Dict[str, Any]]) –List of OpenAI tool call objects
-
parallel(bool, default:True) –Execute in parallel
Returns:
-
List[Dict[str, Any]]–List of tool result messages ready for conversation
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor.extract_and_validate
¶
Extract tool calls from response and validate them.
Parameters:
-
response(Dict[str, Any]) –Model response in OpenAI format
Returns:
-
Tuple[List[Dict[str, Any]], bool]–Tuple of (tool_calls, all_valid)
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.ToolExecutor._tool_exists
¶
Check if a tool exists in any connected server.
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.validate_tool_arguments
¶
validate_tool_arguments(tool: MCPTool, arguments: Dict[str, Any], strict: bool = True) -> None
Validate tool arguments against the tool's input schema.
Parameters:
-
tool(MCPTool) –The MCP tool with input_schema
-
arguments(Dict[str, Any]) –Arguments to validate
-
strict(bool, default:True) –If True, raise exception on validation failure
Raises:
-
ToolArgumentValidationError–If validation fails and strict=True
Source code in vllm_mlx/mcp/executor.py
vllm_mlx.mcp.executor.execute_single_tool
async
¶
execute_single_tool(manager: MCPClientManager, tool_name: str, arguments: Dict[str, Any], timeout: Optional[float] = None) -> MCPToolResult
Convenience function to execute a single tool.
Parameters:
-
manager(MCPClientManager) –MCP client manager
-
tool_name(str) –Full tool name (server__tool)
-
arguments(Dict[str, Any]) –Tool arguments
-
timeout(Optional[float], default:None) –Optional timeout
Returns:
-
MCPToolResult–MCPToolResult
Source code in vllm_mlx/mcp/executor.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.mcp.executor.ToolArgumentValidationError · class
Raised when tool arguments fail validation against schema.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.mcp.executor.ToolArgumentValidationError
Exceptions and behavior
Class ToolArgumentValidationError derives from Exception and declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.validate_tool_arguments · function
vllm_mlx.mcp.executor.validate_tool_arguments(tool: MCPTool, arguments: Dict[str, Any], strict: bool = True) -> None
Validate tool arguments against the tool's input schema.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool |
MCPTool |
yes |
none |
The MCP tool with input_schema |
arguments |
Dict[str, Any] |
yes |
none |
Arguments to validate |
strict |
bool |
no |
True |
If True, raise exception on validation failure |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Function validate_tool_arguments calls logger.debug, jsonschema.validate, '.'.join, str; can raise ToolArgumentValidationError; returns None.
Directly raised exceptions: ToolArgumentValidationError.
vllm_mlx.mcp.executor.ToolExecutor · class
vllm_mlx.mcp.executor.ToolExecutor(manager: MCPClientManager, max_parallel: int = 5, default_timeout: Optional[float] = None, validate_arguments: bool = True, sandbox: Optional[ToolSandbox] = None)
Handles execution of tool calls from model responses.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
manager |
MCPClientManager |
yes |
none |
MCP client manager |
max_parallel |
int |
no |
5 |
Maximum parallel tool executions |
default_timeout |
Optional[float] |
no |
None |
Default timeout for tool calls |
validate_arguments |
bool |
no |
True |
If True, validate arguments against tool schemas |
sandbox |
Optional[ToolSandbox] |
no |
None |
Optional tool sandbox for security controls. Uses global if None. |
Returns
- Constructs:
vllm_mlx.mcp.executor.ToolExecutor
Exceptions and behavior
Class ToolExecutor declares 11 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor.__init__ · method
vllm_mlx.mcp.executor.ToolExecutor.__init__(manager: MCPClientManager, max_parallel: int = 5, default_timeout: Optional[float] = None, validate_arguments: bool = True, sandbox: Optional[ToolSandbox] = None) -> not annotated
Initialize tool executor.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
manager |
MCPClientManager |
yes |
none |
MCP client manager |
max_parallel |
int |
no |
5 |
Maximum parallel tool executions |
default_timeout |
Optional[float] |
no |
None |
Default timeout for tool calls |
validate_arguments |
bool |
no |
True |
If True, validate arguments against tool schemas |
sandbox |
Optional[ToolSandbox] |
no |
None |
Optional tool sandbox for security controls. Uses global if None. |
Returns
- Type:
not annotated
Exceptions and behavior
Method ToolExecutor.__init__ updates self.manager, self.max_parallel, self.default_timeout, self.validate_arguments; calls get_sandbox.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor.execute_tool_calls · method
async vllm_mlx.mcp.executor.ToolExecutor.execute_tool_calls(tool_calls: List[Dict[str, Any]], parallel: bool = True) -> List[Tuple[MCPToolResult, str]]
Execute multiple tool calls.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
List[Dict[str, Any]] |
yes |
none |
List of OpenAI tool call objects |
parallel |
bool |
no |
True |
Execute in parallel (True) or sequential (False) |
Returns
- Type:
List[Tuple[MCPToolResult, str]] - Direct return expressions:
[];await self._execute_parallel(tool_calls);await self._execute_sequential(tool_calls)
Exceptions and behavior
Method ToolExecutor.execute_tool_calls calls self._execute_parallel, self._execute_sequential; awaits asynchronous work; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._get_tool_by_name · method
Get a tool by its full name (server__tool or just tool).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
full_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[MCPTool] - Direct return expressions:
tool;None
Exceptions and behavior
Method ToolExecutor._get_tool_by_name calls self.manager.get_all_tools; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._validate_tool_call · method
Validate a tool call's arguments against the tool's schema.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_call |
Dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[str] - Direct return expressions:
None;f"Invalid JSON in arguments for tool '{name}'";str(e)
Exceptions and behavior
Method ToolExecutor._validate_tool_call calls tool_call.get, func.get, isinstance, json.loads; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._validate_sandbox · method
vllm_mlx.mcp.executor.ToolExecutor._validate_sandbox(tool_name: str, server_name: str, arguments: Dict[str, Any]) -> Optional[str]
Validate tool execution against sandbox policy.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_name |
str |
yes |
none |
Required positional or keyword input. |
server_name |
str |
yes |
none |
Required positional or keyword input. |
arguments |
Dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[str] - Direct return expressions:
None;str(e)
Exceptions and behavior
Method ToolExecutor._validate_sandbox calls self.sandbox.validate_tool_execution, str; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._get_server_for_tool · method
Extract server name from full tool name or find it.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
full_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
full_name.split('__')[0];tool.server_name;'unknown'
Exceptions and behavior
Method ToolExecutor._get_server_for_tool calls full_name.split, self.manager.get_all_tools; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._execute_parallel · method
async vllm_mlx.mcp.executor.ToolExecutor._execute_parallel(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]]
Execute tool calls in parallel with concurrency limit.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
List[Dict[str, Any]] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
List[Tuple[MCPToolResult, str]] - Direct return expressions:
processed
Exceptions and behavior
Method ToolExecutor._execute_parallel calls asyncio.Semaphore, execute_with_semaphore, asyncio.gather, enumerate; awaits asynchronous work; returns processed.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._execute_parallel.execute_with_semaphore · nested function
async vllm_mlx.mcp.executor.ToolExecutor._execute_parallel.execute_with_semaphore(tool_call: Dict[str, Any]) -> not annotated
Nested Function ToolExecutor._execute_parallel.execute_with_semaphore calls tool_call.get, func.get, isinstance, json.loads; awaits asynchronous work; has 3 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_call |
Dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
(MCPToolResult(tool_name=name, content=None, is_error=True, error_message=validation_error), call_id);(MCPToolResult(tool_name=name, content=None, is_error=True, error_message=sandbox_error), call_id);(result, call_id)
Exceptions and behavior
Nested Function ToolExecutor._execute_parallel.execute_with_semaphore calls tool_call.get, func.get, isinstance, json.loads; awaits asynchronous work; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._execute_sequential · method
async vllm_mlx.mcp.executor.ToolExecutor._execute_sequential(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]]
Execute tool calls sequentially.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
List[Dict[str, Any]] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
List[Tuple[MCPToolResult, str]] - Direct return expressions:
results
Exceptions and behavior
Method ToolExecutor._execute_sequential calls tool_call.get, func.get, isinstance, json.loads; awaits asynchronous work; returns results.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor.execute_and_format · method
async vllm_mlx.mcp.executor.ToolExecutor.execute_and_format(tool_calls: List[Dict[str, Any]], parallel: bool = True) -> List[Dict[str, Any]]
Execute tool calls and format results as messages.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
List[Dict[str, Any]] |
yes |
none |
List of OpenAI tool call objects |
parallel |
bool |
no |
True |
Execute in parallel |
Returns
- Type:
List[Dict[str, Any]] - Direct return expressions:
[format_tool_result(result, call_id) for result, call_id in results]
Exceptions and behavior
Method ToolExecutor.execute_and_format calls self.execute_tool_calls, format_tool_result; awaits asynchronous work; returns [format_tool_result(result, call_id) for result, call_id in results].
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor.extract_and_validate · method
vllm_mlx.mcp.executor.ToolExecutor.extract_and_validate(response: Dict[str, Any]) -> Tuple[List[Dict[str, Any]], bool]
Extract tool calls from response and validate them.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
response |
Dict[str, Any] |
yes |
none |
Model response in OpenAI format |
Returns
- Type:
Tuple[List[Dict[str, Any]], bool] - Direct return expressions:
([], True);(tool_calls, all_valid)
Exceptions and behavior
Method ToolExecutor.extract_and_validate calls extract_tool_calls, tc.get, func.get, self._tool_exists; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.ToolExecutor._tool_exists · method
Check if a tool exists in any connected server.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
full_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
True;False
Exceptions and behavior
Method ToolExecutor._tool_exists calls self.manager.get_all_tools; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mcp.executor.execute_single_tool · function
async vllm_mlx.mcp.executor.execute_single_tool(manager: MCPClientManager, tool_name: str, arguments: Dict[str, Any], timeout: Optional[float] = None) -> MCPToolResult
Convenience function to execute a single tool.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
manager |
MCPClientManager |
yes |
none |
MCP client manager |
tool_name |
str |
yes |
none |
Full tool name (server__tool) |
arguments |
Dict[str, Any] |
yes |
none |
Tool arguments |
timeout |
Optional[float] |
no |
None |
Optional timeout |
Returns
- Type:
MCPToolResult - Direct return expressions:
await manager.execute_tool(tool_name, arguments, timeout)
Exceptions and behavior
Function execute_single_tool calls manager.execute_tool; awaits asynchronous work; returns await manager.execute_tool(tool_name, arguments, timeout).
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
ToolArgumentValidationError |
class | ToolArgumentValidationError() |
Raised when tool arguments fail validation against schema. | #L22-L25 |
validate_tool_arguments |
function | validate_tool_arguments(tool: MCPTool, arguments: Dict[str, Any], strict: bool = True) -> None |
Validate tool arguments against the tool's input schema. | #L28-L61 |
ToolExecutor |
class | ToolExecutor(manager: MCPClientManager, max_parallel: int = 5, default_timeout: Optional[float] = None, validate_arguments: bool = True, sandbox: Optional[ToolSandbox] = None) |
Handles execution of tool calls from model responses. | #L64-L479 |
ToolExecutor.__init__ |
method | ToolExecutor.__init__(manager: MCPClientManager, max_parallel: int = 5, default_timeout: Optional[float] = None, validate_arguments: bool = True, sandbox: Optional[ToolSandbox] = None) -> not annotated |
Initialize tool executor. | #L75-L97 |
ToolExecutor.execute_tool_calls |
method | async ToolExecutor.execute_tool_calls(tool_calls: List[Dict[str, Any]], parallel: bool = True) -> List[Tuple[MCPToolResult, str]] |
Execute multiple tool calls. | #L99-L120 |
ToolExecutor._get_tool_by_name |
method | ToolExecutor._get_tool_by_name(full_name: str) -> Optional[MCPTool] |
Get a tool by its full name (server__tool or just tool). | #L122-L132 |
ToolExecutor._validate_tool_call |
method | ToolExecutor._validate_tool_call(tool_call: Dict[str, Any]) -> Optional[str] |
Validate a tool call's arguments against the tool's schema. | #L134-L165 |
ToolExecutor._validate_sandbox |
method | ToolExecutor._validate_sandbox(tool_name: str, server_name: str, arguments: Dict[str, Any]) -> Optional[str] |
Validate tool execution against sandbox policy. | #L167-L183 |
ToolExecutor._get_server_for_tool |
method | ToolExecutor._get_server_for_tool(full_name: str) -> str |
Extract server name from full tool name or find it. | #L185-L193 |
ToolExecutor._execute_parallel |
method | async ToolExecutor._execute_parallel(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]] |
Execute tool calls in parallel with concurrency limit. | #L195-L305 |
ToolExecutor._execute_parallel.execute_with_semaphore |
nested function | async ToolExecutor._execute_parallel.execute_with_semaphore(tool_call: Dict[str, Any]) -> not annotated |
Nested Function ToolExecutor._execute_parallel.execute_with_semaphore calls tool_call.get, func.get, isinstance, json.loads; awaits asynchronous work; has 3 explicit return paths. |
#L202-L281 |
ToolExecutor._execute_sequential |
method | async ToolExecutor._execute_sequential(tool_calls: List[Dict[str, Any]]) -> List[Tuple[MCPToolResult, str]] |
Execute tool calls sequentially. | #L307-L415 |
ToolExecutor.execute_and_format |
method | async ToolExecutor.execute_and_format(tool_calls: List[Dict[str, Any]], parallel: bool = True) -> List[Dict[str, Any]] |
Execute tool calls and format results as messages. | #L417-L433 |
ToolExecutor.extract_and_validate |
method | ToolExecutor.extract_and_validate(response: Dict[str, Any]) -> Tuple[List[Dict[str, Any]], bool] |
Extract tool calls from response and validate them. | #L435-L464 |
ToolExecutor._tool_exists |
method | ToolExecutor._tool_exists(full_name: str) -> bool |
Check if a tool exists in any connected server. | #L466-L479 |
execute_single_tool |
function | async execute_single_tool(manager: MCPClientManager, tool_name: str, arguments: Dict[str, Any], timeout: Optional[float] = None) -> MCPToolResult |
Convenience function to execute a single tool. | #L482-L500 |