Universal Tool Calling Protocol Client for Rust
A powerful, async-first Rust implementation of the Universal Tool Calling Protocol (UTCP)
- π 12 Communication Protocols (formerly transports) - HTTP, MCP, WebSocket, gRPC, CLI, GraphQL, TCP, UDP, SSE, WebRTC, HTTP Streams, and Text-based
- π Async/Await Native - Built with Tokio for high-performance concurrent operations
- π¦ Config-Driven - Load tool providers from JSON with automatic discovery and registration
- π Smart Tool Discovery - Tag-based semantic search across all registered tools
- π€ LLM Integration - Built-in Codemode orchestrator for AI-driven workflows
- π Auto-Migration - Seamless compatibility with UTCP v0.1 and v1.0 formats
- π OpenAPI Support - Automatic tool generation from OpenAPI 3.0 specifications
- π Multi-Auth - Support for API keys, Basic Auth, OAuth2, and custom authentication
- πΎ Streaming - First-class support for streaming responses across compatible communication protocols
- π§ͺ Well-Tested - 90+ tests ensuring reliability and correctness
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 fulluse 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(())
}{
"manual_version": "1.0.0",
"utcp_version": "0.3.0",
"allowed_communication_protocols": ["http", "mcp"],
"info": {
"title": "Example UTCP Manual",
"version": "1.0.0",
"description": "Manual v1.0 with tools"
},
"tools": [
{
"name": "get_forecast",
"description": "Get current weather for a city",
"inputs": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name" },
"units": { "type": "string", "enum": ["metric", "imperial"] }
},
"required": ["city"]
},
"outputs": { "type": "object" },
"tool_call_template": {
"call_template_type": "http",
"name": "weather_api",
"url": "https://api.weather.example.com/tools",
"http_method": "GET",
"headers": { "Accept": "application/json" }
},
"tags": ["weather", "demo"]
},
{
"name": "read_file",
"description": "Read a text file via MCP stdio",
"inputs": {
"type": "object",
"properties": {
"path": { "type": "string", "description": "File path" }
},
"required": ["path"]
},
"outputs": { "type": "object" },
"tool_call_template": {
"call_template_type": "mcp",
"name": "file_tools",
"command": "python3",
"args": ["mcp_server.py"]
},
"tags": ["mcp", "filesystem"]
}
],
"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_clientSee 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:
- Decide - LLM determines if tools are needed
- Select - LLM chooses relevant tools
- Generate - LLM writes a Rhai script
- Execute - Script runs in sandboxed environment
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:
- β Code Validation - Pre-execution checks for dangerous patterns and size limits
- β Timeout Enforcement - Strict timeouts (5s default, 30s max) prevent runaway scripts
- β Resource Limits - Memory, CPU, and output size constraints
- β Sandboxed Execution - Rhai scripts run isolated from the file system and OS
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.
- API Documentation - Complete API reference
- UTCP Specification - Protocol specification
- Examples - Working examples for all transports
- SECURITY - Security features and best practices
- CHANGELOG - Version history and 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. β
βββββββββββββββββββ
- UtcpClient - Main entry point for all operations
- CommunicationProtocolRegistry (was TransportRegistry) - Manages all communication protocol implementations
- Call template handlers - Registry that maps
call_template_typeto provider builders - ToolRepository - Stores and indexes discovered tools
- SearchStrategy - Semantic search across tools
- Codemode - Script execution environment
- Loader - Configuration and provider loading
Register 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:
- Found a bug? Open an issue
- Have a feature idea? Start a discussion
- Want to contribute code? Submit a PR
# 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 --examplesLicensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
- Inspired by go-utcp
- Built on the UTCP specification
- Powered by the amazing Rust async ecosystem
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- UTCP Community: utcp.io
Made with β€οΈ by the UTCP community
