| Crates.io | rs-utcp |
| lib.rs | rs-utcp |
| version | 0.3.0 |
| created_at | 2025-11-25 14:00:39.4804+00 |
| updated_at | 2025-12-02 08:03:37.315008+00 |
| description | Rust implementation of the Universal Tool Calling Protocol (UTCP). |
| homepage | https://github.com/universal-tool-calling-protocol/rs-utcp |
| repository | https://github.com/universal-tool-calling-protocol/rs-utcp |
| max_upload_size | |
| id | 1949815 |
| size | 732,400 |
Universal Tool Calling Protocol Client for Rust
A powerful, async-first Rust implementation of the Universal Tool Calling Protocol (UTCP)
Add rs-utcp to your Cargo.toml:
[dependencies]
rs-utcp = "0.1.8"
tokio = { version = "1.0", features = ["full"] }
Or use cargo add:
cargo add rs-utcp
cargo add tokio --features full
use rs_utcp::{
config::UtcpClientConfig,
repository::in_memory::InMemoryToolRepository,
tag::tag_search::TagSearchStrategy,
UtcpClient, UtcpClientInterface,
};
use std::{collections::HashMap, sync::Arc};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// 1. Configure the client
let config = UtcpClientConfig::new()
.with_manual_path("providers.json".into());
// 2. Set up repository and search
let repo = Arc::new(InMemoryToolRepository::new());
let search = Arc::new(TagSearchStrategy::new(repo.clone(), 1.0));
// 3. Create the client
let client = UtcpClient::create(config, repo, search).await?;
// 4. Discover tools
let tools = client.search_tools("weather", 10).await?;
println!("Found {} tools", tools.len());
// 5. Call a tool
let mut args = HashMap::new();
args.insert("city".to_string(), serde_json::json!("London"));
let result = client.call_tool("weather.get_forecast", args).await?;
println!("Result: {}", serde_json::to_string_pretty(&result)?);
Ok(())
}
providers.json){
"manual_call_templates": [
{
"call_template_type": "http",
"name": "weather_api",
"url": "https://api.weather.example.com/tools",
"http_method": "GET"
},
{
"call_template_type": "mcp",
"name": "file_tools",
"command": "python3",
"args": ["mcp_server.py"]
}
],
"load_variables_from": [
{
"variable_loader_type": "dotenv",
"env_file_path": ".env"
}
]
}
rs-utcp supports a comprehensive range of communication protocols, each with full async support:
| Protocol | Description | Status | Streaming |
|---|---|---|---|
| HTTP | REST APIs with UTCP manifest or OpenAPI | โ Stable | โ |
| MCP | Model Context Protocol (stdio & SSE) | โ Stable | โ |
| WebRTC | P2P data channels with signaling | โ Stable | โ |
| WebSocket | Real-time bidirectional communication | โ Stable | โ |
| CLI | Execute local binaries as tools | โ Stable | โ |
| gRPC | High-performance RPC with TLS & auth metadata | โ Stable | โ |
| GraphQL | Query-based tool calling with type-aware variables | โ Stable | โ |
| SSE | Server-Sent Events | โ Stable | โ |
| HTTP Streams | Streaming HTTP responses | โ Stable | โ |
| TCP | Low-level socket transport (framed JSON) | โ Stable | โ |
| UDP | Low-level datagram transport | โ Stable | โ |
| Text | File-based tool providers (JS/SH/Python/exe) | โ Stable | โ |
use rs_utcp::openapi::OpenApiConverter;
// Automatically convert OpenAPI spec to UTCP tools
let converter = OpenApiConverter::new_from_url(
"https://petstore.swagger.io/v2/swagger.json",
Some("petstore".to_string())
).await?;
let manual = converter.convert();
println!("Discovered {} tools from OpenAPI spec", manual.tools.len());
let config = serde_json::json!({
"manual_call_templates": [{
"call_template_type": "mcp",
"name": "calculator",
"command": "python3",
"args": ["calculator_server.py"],
"env_vars": {
"DEBUG": "1"
}
}]
});
let client = create_client_from_config(config).await?;
let result = client.call_tool("calculator.add",
HashMap::from([
("a".to_string(), json!(5)),
("b".to_string(), json!(3))
])
).await?;
// Call a streaming tool
let mut stream = client.call_tool_stream(
"sse_provider.events",
HashMap::new()
).await?;
// Process stream results
while let Some(item) = stream.next().await {
match item {
Ok(value) => println!("Received: {}", value),
Err(e) => eprintln!("Error: {}", e),
}
}
stream.close().await?;
WebRTC enables direct peer-to-peer tool calling:
# Terminal 1: Start WebRTC server with signaling
cargo run --example webrtc_server
# Terminal 2: Connect and call tools
cargo run --example webrtc_client
See examples/webrtc_server/ for the complete implementation.
rs-utcp includes a powerful Codemode feature that enables dynamic script execution with full access to registered tools. This is perfect for LLM-driven workflows.
use rs_utcp::plugins::codemode::{CodeModeUtcp, CodeModeArgs};
let codemode = CodeModeUtcp::new(client);
// Execute a Rhai script that calls tools
let script = r#"
let weather = call_tool("weather.get_forecast", #{
"city": "Tokyo"
});
let summary = call_tool("ai.summarize", #{
"text": weather.to_string()
});
summary
"#;
let result = codemode.execute(CodeModeArgs {
code: script.to_string(),
timeout: Some(30_000),
}).await?;
println!("Result: {:?}", result.value);
The CodemodeOrchestrator provides a 4-step AI-driven workflow:
use rs_utcp::plugins::codemode::CodemodeOrchestrator;
let codemode = Arc::new(CodeModeUtcp::new(client));
let llm_model = Arc::new(YourLLMModel::new());
let orchestrator = CodemodeOrchestrator::new(codemode, llm_model);
// Let the LLM figure out how to accomplish the task
let result = orchestrator
.call_prompt("Get the weather in Paris and summarize it")
.await?;
match result {
Some(value) => println!("LLM completed task: {}", value),
None => println!("No tools needed for this request"),
}
See the Gemini example for a complete LLM integration.
Codemode executes scripts in a hardened sandbox with comprehensive security measures:
See SECURITY.md for complete security documentation.
Call tools across HTTP, gRPC, and MCP from a single unified interface.
Provide language models with a consistent way to execute tools regardless of their implementation.
Coordinate calls across heterogeneous services using different protocols.
Build extensible applications where plugins can be added via configuration.
Easily swap implementations (e.g., HTTP โ CLI) for testing without code changes.
Run the comprehensive test suite:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_http_transport
# Run examples
cargo run --example basic_usage
cargo run --example all_providers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ UtcpClient โ
โ (Unified interface for all tool operations) โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโโโ
โ โ
โโโโโโโโผโโโโโโโ โโโโโโโโโโผโโโโโโโโโ
โ Repository โ โ Communication โ
โ โ โ Protocols โ
โ - Tools โ โ - HTTP โ
โ - Search โ โ - MCP โ
โโโโโโโโโโโโโโโ โ - gRPC โ
โ - WebSocket โ
โ - CLI โ
โ - etc. โ
โโโโโโโโโโโโโโโโโโโ
call_template_type to provider buildersRegister new communication protocols and call template handlers before constructing your client:
use std::sync::Arc;
use rs_utcp::call_templates::register_call_template_handler;
use rs_utcp::transports::register_communication_protocol;
fn myproto_template_handler(template: serde_json::Value) -> anyhow::Result<serde_json::Value> {
// normalize/augment the template into a provider config
Ok(template)
}
register_call_template_handler("myproto", myproto_template_handler);
register_communication_protocol("myproto", Arc::new(MyProtocol::new())); // implements CommunicationProtocol
{
"manual_call_templates": [{
"call_template_type": "http",
"name": "secure_api",
"url": "https://api.example.com",
"auth": {
"auth_type": "api_key",
"api_key": "${API_KEY}",
"var_name": "X-API-Key",
"location": "header"
}
}]
}
{
"load_variables_from": [
{
"variable_loader_type": "dotenv",
"env_file_path": ".env"
}
],
"variables": {
"DEFAULT_TIMEOUT": "30000"
}
}
You can restrict which communication protocols are allowed for a manual or provider using the allowed_communication_protocols field. This provides a secure-by-default mechanism where tools can only use their own protocol unless explicitly allowed.
{
"manual_version": "1.0.0",
"info": { "title": "Restricted Manual", "version": "1.0.0" },
"allowed_communication_protocols": ["http", "cli"],
"tools": [
{
"name": "http_tool",
"tool_call_template": {
"call_template_type": "http",
"url": "http://example.com"
}
},
{
"name": "cli_tool",
"tool_call_template": {
"call_template_type": "cli",
"command": "echo"
}
}
]
}
If allowed_communication_protocols is not specified, it defaults to only allowing the tool's own protocol type. Tools attempting to use disallowed protocols will be filtered out during registration, and calls will fail validation.
use rs_utcp::tools::ToolSearchStrategy;
use async_trait::async_trait;
struct MySearchStrategy;
#[async_trait]
impl ToolSearchStrategy for MySearchStrategy {
async fn search_tools(&self, query: &str, limit: usize)
-> anyhow::Result<Vec<Tool>>
{
// Your custom search logic
Ok(vec![])
}
}
Contributions are welcome! Here's how you can help:
# Clone the repository
git clone https://github.com/universal-tool-calling-protocol/rs-utcp.git
cd rs-utcp
# Run tests
cargo test
# Format code
cargo fmt
# Run lints
cargo clippy
# Build all examples
cargo build --examples
Licensed under either of:
at your option.
Made with โค๏ธ by the UTCP community