Getting Started
Relevant source files
The following files were used as context for generating this wiki page: - [README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/README.md) - [core/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/core/README.md) - [plugins/communication_protocols/http/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/plugins/communication_protocols/http/README.md) - [plugins/communication_protocols/cli/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/plugins/communication_protocols/cli/README.md) - [plugins/communication_protocols/websocket/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/plugins/communication_protocols/websocket/README.md) - [plugins/communication_protocols/text/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/plugins/communication_protocols/text/README.md) - [plugins/communication_protocols/mcp/README.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/plugins/communication_protocols/mcp/README.md) - [CLAUDE.md](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/CLAUDE.md) - [scripts/extract_required_docs.py](https://github.com/universal-tool-calling-protocol/python-utcp/blob/HEAD/scripts/extract_required_docs.py)The Universal Tool Calling Protocol (UTCP) is a secure and scalable standard for defining and interacting with tools across various communication protocols. It is designed with a focus on extensibility through a plugin-based architecture, interoperability with existing services, and ease of use for developers. This guide provides the essential information to install, configure, and start using the python-utcp library.
UTCP's modular design separates the core logic from protocol-specific implementations. This allows developers to integrate with a wide range of services, from modern REST APIs to command-line tools, using a unified client interface.
Sources: README.md:8-17, core/README.md:8-18
Architecture Overview
The UTCP architecture consists of a central core package and multiple protocol plugins.
- Core Package (
utcp): Provides the foundational components, including the mainUtcpClient, data models (Tool,CallTemplate,UtcpManual), and interfaces for the plugin system. - Protocol Plugins: Independent, installable packages that implement specific communication protocols (e.g.,
utcp-http,utcp-cli,utcp-websocket). These plugins register themselves with the core client, extending its capabilities.
Sources: README.md:26-34, core/README.md:29-35
This diagram illustrates the modular architecture of UTCP.
Sources: README.md:26-34, core/README.md:29-35
Installation
To get started, install the core library and the specific protocol plugins you need. The most common combination is utcp and utcp-http.
# Install core + HTTP plugin (most common)
pip install utcp utcp-http
# Install additional plugins as needed
pip install utcp-cli utcp-websocket utcp-text utcp-mcp
For development, you can install packages in editable mode from a cloned repository.
# Clone the repository
git clone https://github.com/universal-tool-calling-protocol/python-utcp.git
cd python-utcp
# Install the core package in editable mode
pip install -e "core[dev]"
# Install a specific protocol plugin in editable mode
pip install -e plugins/communication_protocols/http
Sources: README.md:41-45, 62-69, plugins/communication_protocols/http/README.md:15-17, plugins/communication_protocols/cli/README.md:15-17, plugins/communication_protocols/websocket/README.md:27-29
Client Initialization and Usage
The primary entry point for interacting with tools is the UtcpClient. It is initialized asynchronously using the create class method, which takes a configuration object.
Client Configuration
The client can be configured in three ways:
- A path to a JSON configuration file.
- A Python dictionary.
- A
UtcpClientConfigPydantic object.
The configuration defines manual_call_templates, which are instructions for how the client should discover tools. The term call_template replaces the older term provider.
Sources: README.md:77-82, 114-117, core/README.md:104-107, 113-114
This sequence diagram shows the client initialization process.
Sources: README.md:114-117, core/README.md:104-107
Basic Usage Example
The following example demonstrates how to create a client and call a tool. Tool names are namespaced as manual_name.tool_name.
import asyncio
from utcp.utcp_client import UtcpClient
async def main():
# Initialize client from a dictionary
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "my_api",
"call_template_type": "http",
"url": "https://api.example.com/utcp"
}]
})
# Call a tool using its namespaced name: `manual_name.tool_name`
result = await client.call_tool("my_api.get_data", {"id": "123"})
print(result)
if __name__ == "__main__":
asyncio.run(main())
Sources: README.md:50-60, 85, core/README.md:200-207
Tool Call Flow
This diagram illustrates the sequence of events when call_tool is invoked.
Sources: README.md:58-60, core/README.md:200-207
Protocol Plugins
UTCP's power comes from its protocol plugins. Each plugin handles a different call_template_type.
| Plugin | call_template_type | Description | Status |
|---|---|---|---|
utcp-http | http, sse, streamable_http | HTTP/REST APIs, Server-Sent Events, and streaming. | ✅ Stable |
utcp-cli | cli | Command-line tools and multi-step scripts. | ✅ Stable |
utcp-websocket | websocket | Real-time bidirectional communication. | ✅ Stable |
utcp-text | text | Local file-based tools. | ✅ Stable |
utcp-mcp | mcp | Interoperability with Model Context Protocol. | ✅ Stable |
utcp-socket | socket | TCP/UDP protocols. | 🚧 In Progress |
utcp-gql | gql | GraphQL APIs. | 🚧 In Progress |
Sources: README.md:47-48, core/README.md:42-51
Configuration Examples
Below are minimal configuration examples for common plugins.
HTTP Plugin
For interacting with REST APIs.
{
"name": "my_rest_api",
"call_template_type": "http",
"url": "https://api.example.com/users/{user_id}",
"http_method": "POST"
}
Sources: README.md:195-200, plugins/communication_protocols/http/README.md:28-33
CLI Plugin
For executing local shell commands.
{
"name": "multi_step_cli_tool",
"call_template_type": "cli",
"commands": [
{
"command": "git clone UTCP_ARG_repo_url_UTCP_END temp_repo"
},
{
"command": "cd temp_repo && find . -name '*.py' | wc -l"
}
]
}
Sources: README.md:240-251, plugins/communication_protocols/cli/README.md:39-47
WebSocket Plugin
For real-time, flexible WebSocket communication. If no message template is provided, arguments are sent as a JSON object.
{
"name": "my_websocket",
"call_template_type": "websocket",
"url": "wss://api.example.com/ws"
}
Sources: plugins/communication_protocols/websocket/README.md:36-41, 74-82
Text Plugin
For loading tools or content from local files.
{
"name": "my_text_manual",
"call_template_type": "text",
"file_path": "./manuals/my_manual.json"
}
Sources: README.md:264-269, plugins/communication_protocols/text/README.md:58-62
OpenAPI Ingestion: Zero Infrastructure Integration
A key feature of UTCP is its ability to automatically convert an OpenAPI 2.0/3.0 specification into a set of callable UTCP tools without requiring any server-side modifications or additional infrastructure. This allows AI agents to interact directly with existing REST APIs.
To use this feature, simply create an http call template pointing to the URL of an OpenAPI specification file.
# Client configuration for automatic OpenAPI detection
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "github",
"call_template_type": "http",
"url": "https://api.github.com/openapi.json",
"auth_tools": { # Authentication for generated tools requiring auth
"auth_type": "api_key",
"api_key": "Bearer ${GITHUB_TOKEN}",
"var_name": "Authorization",
"location": "header"
}
}]
})
Sources: README.md:278-306, plugins/communication_protocols/text/README.md:11-14
Providing a UTCP Manual (Server-Side)
To expose your own tools, you can create a UTCPManual. This is typically a JSON object served from a discovery endpoint (e.g., /utcp) that describes the available tools. The manual includes the tool_call_template which tells the client how to execute each tool.
The example below shows a FastAPI server exposing a get_weather tool.
from fastapi import FastAPI
app = FastAPI()
# The discovery endpoint returns the tool manual
@app.get("/utcp")
def utcp_discovery():
return {
"manual_version": "1.0.0",
"utcp_version": "1.0.2",
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a location",
"inputs": {
"type": "object",
"properties": {"location": {"type": "string"}}
},
"tool_call_template": {
"call_template_type": "http",
"url": "https://example.com/api/weather",
"http_method": "GET"
}
}
]
}
# The actual tool endpoint
@app.get("/api/weather")
def get_weather(location: str):
return {"temperature": 22.5, "conditions": "Sunny"}
Sources: README.md:163-192, core/README.md:248-283