execute_composed_code
Run Python code to orchestrate MCP tools from multiple servers, automating sequential or heuristic workflows with loops and error handling.
Instructions
Execute Python code that orchestrates tools from multiple MCP servers.
Used to automate a heuristic search or sequential execution using loops and error handling.
Example: ```python from unified_api import *
items = ["item_a", "item_b", "item_c"]
results = []
for item in items:
server__prepare(target=item, mode="sim")
result = server__execute_action(name=item, value=123, mode="sim")
if result.get("result") != "success":
server__restore_state()
continue
server__finalize(item=item)
results.append({"item": item, "status": "success"})
print(f"Processed {len(results)}/{len(items)} successfully")
```Returns: output: stdout/stderr from execution (partial results if aborted/timed out) returncode: 0=success, 1=error, -1=timeout status: "success" | "failed" | "aborted" | "timeout" session_id: present when persistent=True and status="success" session_vars: list of saved variable names, present with session_id reason: present when status="aborted" — user cancelled operation. Do not retry. tool: present when status="aborted" — which tool was cancelled
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to execute. Has access to all MCP tools via 'from unified_api import *'. Tools are called as Python functions: server_name__tool_name(param=value). Replace dashes with underscores in server names. | |
| persistent | No | If True, variables from this execution are saved and restored on the next call with the same session_id. Useful for multi-step workflows where later calls need results from earlier ones. | |
| session_id | No | Session identifier for persistent execution. Use the same ID across calls to share state between executions. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |