UTCP communication protocol plugin for wrapping local command-line tools.
Project description
UTCP CLI Plugin
Command-line interface plugin for UTCP, enabling integration with command-line tools and processes.
Features
- Command Execution: Run any command-line tool as a UTCP tool
- Environment Variables: Secure credential and configuration passing
- Working Directory Control: Execute commands in specific directories
- Input/Output Handling: Support for stdin, stdout, stderr processing
- Cross-Platform: Works on Windows, macOS, and Linux
- Timeout Management: Configurable execution timeouts
- Argument Validation: Optional input sanitization
Installation
pip install utcp-cli
Quick Start
from utcp.utcp_client import UtcpClient
# Basic CLI tool
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "file_tools",
"call_template_type": "cli",
"command_name": "ls -la ${path}"
}]
})
result = await client.call_tool("file_tools.list", {"path": "/home"})
Configuration Examples
Basic Command
{
"name": "file_ops",
"call_template_type": "cli",
"command_name": "ls -la ${path}",
"working_dir": "/tmp"
}
With Environment Variables
{
"name": "python_script",
"call_template_type": "cli",
"command_name": "python script.py ${input}",
"env_vars": {
"PYTHONPATH": "/custom/path",
"API_KEY": "${API_KEY}"
}
}
Processing JSON with jq
{
"name": "json_processor",
"call_template_type": "cli",
"command_name": "jq '.data'",
"stdin": "${json_input}",
"timeout": 10
}
Git Operations
{
"name": "git_tools",
"call_template_type": "cli",
"command_name": "git ${operation} ${args}",
"working_dir": "${repo_path}",
"env_vars": {
"GIT_AUTHOR_NAME": "${author_name}",
"GIT_AUTHOR_EMAIL": "${author_email}"
}
}
Security Considerations
- Commands run in isolated subprocesses
- Environment variables provide secure credential passing
- Working directory restrictions limit file system access
- Input validation prevents command injection
{
"name": "safe_grep",
"call_template_type": "cli",
"command_name": "grep ${pattern} ${file}",
"working_dir": "/safe/directory",
"allowed_args": {
"pattern": "^[a-zA-Z0-9_-]+$",
"file": "^[a-zA-Z0-9_./-]+\\.txt$"
}
}
Error Handling
from utcp.exceptions import ToolCallError
import subprocess
try:
result = await client.call_tool("cli_tool.command", {"arg": "value"})
except ToolCallError as e:
if isinstance(e.__cause__, subprocess.CalledProcessError):
print(f"Command failed with exit code {e.__cause__.returncode}")
print(f"stderr: {e.__cause__.stderr}")
Common Use Cases
- File Operations: ls, find, grep, awk, sed
- Data Processing: jq, sort, uniq, cut
- System Monitoring: ps, top, df, netstat
- Development Tools: git, npm, pip, docker
- Custom Scripts: Python, bash, PowerShell scripts
Testing CLI Tools
import pytest
from utcp.utcp_client import UtcpClient
@pytest.mark.asyncio
async def test_cli_tool():
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "test_cli",
"call_template_type": "cli",
"command_name": "echo ${message}"
}]
})
result = await client.call_tool("test_cli.echo", {"message": "hello"})
assert "hello" in result["stdout"]
Related Documentation
Examples
For complete examples, see the UTCP examples repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
utcp_cli-1.0.2.tar.gz
(15.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
utcp_cli-1.0.2-py3-none-any.whl
(10.2 kB
view details)
File details
Details for the file utcp_cli-1.0.2.tar.gz.
File metadata
- Download URL: utcp_cli-1.0.2.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df27b80c7545f0ab7eca9c8f0e3530ebdddff8f19430122d04ff702a626fa4ca
|
|
| MD5 |
5612a9fe2d98fd57b954f553aadd84de
|
|
| BLAKE2b-256 |
57fefeca5e73d24cb6b294bc293728a6ce59f5c6665e3f9ee5ca1300c81cba44
|
File details
Details for the file utcp_cli-1.0.2-py3-none-any.whl.
File metadata
- Download URL: utcp_cli-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a571e6cf250e499d25f3cacc927e3a7598a47e9fef7cf20da24fa8057c16edf7
|
|
| MD5 |
4419fb320e40e20726913823ba7b89d4
|
|
| BLAKE2b-256 |
076068a866e6c2cab6f310a47b0851febe062d2b0aa4f4475287cd8a14e13756
|