How the UTCP CLI Plugin works
mainThe UTCP CLI plugin allows you to define a sequence of commands that execute within a single subprocess. This ensures that state, such as directory changes (cd) and environment variables, persists across the entire command chain.
Key features include:
- State Preservation: Changes to the working directory or environment persist between commands in the sequence.
- Argument Substitution: Use the
UTCP_ARG_argname_UTCP_ENDplaceholder to inject tool arguments into commands. - Output Referencing: Access the output of any previous command in the sequence using
$CMD_N_OUTPUT(whereNis the zero-based index of the command). - Output Control: Use
append_to_final_output: falseon specific commands to prevent their output from being included in the final tool result returned to the client. - Cross-Platform Support: Automatically generates appropriate scripts (PowerShell for Windows, Bash for Unix/Linux/macOS).
from utcp.utcp_client import UtcpClient
# Example of a multi-step tool definition
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "file_analysis",
"call_template_type": "cli",
"commands": [
{
"command": "cd UTCP_ARG_target_dir_UTCP_END",
"append_to_final_output": false
},
{
"command": "find . -type f -name '*.py' | wc -l"
}
]
}]
})
result = await client.call_tool("file_analysis.count_python_files", {"target_dir": "/project"})