The UTCP Client
Relevant source files
The following files were used as context for generating this wiki page:- core/src/utcp/utcp_client.py
- core/src/utcp/implementations/utcp_client_implementation.py
- core/src/utcp/data/utcp_client_config.py
- README.md
- core/README.md
- CLAUDE.md
- plugins/communication_protocols/http/README.md
- plugins/communication_protocols/cli/README.md
- plugins/communication_protocols/websocket/README.md
- plugins/communication_protocols/mcp/README.md
- plugins/communication_protocols/text/README.md
The UtcpClient is the main entry point for interacting with the Universal Tool Calling Protocol (UTCP) ecosystem. It provides a unified interface for discovering, searching, and executing tools across a wide variety of communication protocols. Designed for scalability and extensibility, the client uses a modular, plugin-based architecture that allows developers to easily integrate with new and existing services.
The client's core responsibilities include managing tool definitions, handling different communication protocols through plugins, and providing a simple API for tool invocation. It is configured via a flexible configuration object that defines tool sources, variable loaders, and other operational parameters.
Sources: README.md:10-17, CLAUDE.md:25-26
Architecture Overview
The UtcpClient is built on a modular architecture that separates core logic from protocol-specific implementations. This design promotes extensibility and interoperability.
The following diagram illustrates the key components of the UTCP Client architecture.
Sources: CLAUDE.md:30-47, core/README.md:26-32
Key Components
| Component | Description | Source File |
|---|---|---|
UtcpClient | The main public interface for the UTCP client. It orchestrates tool discovery, search, and execution. | core/src/utcp/utcp_client.py |
UtcpClientConfig | A Pydantic model that holds the entire configuration for the client, including tool sources (manual_call_templates), variable loaders, and custom component implementations. | core/src/utcp/data/utcp_client_config.py |
ToolRepository | An interface for storing and retrieving tool definitions. The default is an InMemToolRepository. | CLAUDE.md:34 |
ToolSearchStrategy | An interface for tool search algorithms. The default strategy is TagAndDescriptionWordMatchStrategy. | CLAUDE.md:35 |
| Protocol Plugins | Separate, installable packages that implement specific communication protocols (e.g., utcp-http, utcp-cli). They handle the actual execution of tool calls. | README.md:58-67 |
Initialization and Configuration
The UtcpClient is instantiated asynchronously using the UtcpClient.create() class method. This method accepts a configuration which can be provided in one of three ways:
- A path to a JSON configuration file.
- A Python dictionary.
- An instance of the
UtcpClientConfigPydantic model.
Sources: README.md:106-110, core/src/utcp/utcp_client.py
Initialization Flow
The diagram below shows the sequence of operations during the client's initialization.
Configuration (UtcpClientConfig)
The client's behavior is defined by the UtcpClientConfig object. Below are its primary fields.
| Field | Type | Description |
|---|---|---|
manual_call_templates | List[CallTemplate] | A list of templates that tell the client where and how to discover tools. This is the primary mechanism for tool discovery. |
variables | Dict[str, Any] | A dictionary of static variables that can be substituted into call_templates. |
load_variables_from | List[VariableLoader] | A list of configurations for dynamically loading variables, e.g., from .env files. |
tool_repository | ToolRepositoryConfig | Configuration for the tool storage mechanism. Defaults to in-memory storage. |
tool_search_strategy | ToolSearchStrategyConfig | Configuration for the tool search algorithm. |
post_processing | List[ToolPostProcessor] | A list of processors to modify tool outputs after a call. |
Sources: core/src/utcp/data/utcp_client_config.py, README.md:90-104
Example: Dictionary-based Configuration
# From README.md
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "my_api",
"call_template_type": "http",
"url": "https://api.example.com/utcp"
}]
})
Sources: README.md:51-57
Tool Interaction
Once initialized, the client provides methods to list, search for, and execute tools.
Core Methods
| Method | Description |
|---|---|
list_tools() | Returns a list of all registered Tool objects. |
search_tools(query: str) | Searches for tools based on the configured search strategy and returns a ranked list. |
call_tool(tool_name: str, tool_args: dict) | Executes a specific tool with the given arguments and returns the result. |
call_tool_streaming(tool_name: str, tool_args: dict) | Executes a streaming-capable tool and returns an async generator for the response chunks. |
Sources: core/src/utcp/utcp_client.py, plugins/communication_protocols/websocket/README.md:213-214
Tool Naming and Namespacing
Tools are identified by a namespaced name in the format manual_name.tool_name. The manual_name corresponds to the name field of the manual_call_template from which the tool was discovered. This prevents naming conflicts between different tool providers.
Sources: README.md:83-84, core/README.md:154-155
Tool Call Sequence
This diagram shows the high-level sequence for a call_tool invocation.
Protocol Plugins
The power of the UtcpClient comes from its plugin-based architecture. Protocol-specific logic is handled by installable plugins, which the client discovers and utilizes based on the call_template_type in the configuration.
| 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 interface tools. | ✅ Stable |
utcp-websocket | websocket | Real-time bidirectional WebSocket communication. | ✅ Stable |
utcp-mcp | mcp | Interoperability with Model Context Protocol. | ✅ Stable |
utcp-text | text | Local file-based tool definitions. | ✅ Stable |
utcp-socket | socket | TCP/UDP protocols. | 🚧 In Progress |
utcp-gql | gql | GraphQL APIs. | 🚧 In Progress |
Sources: README.md:58-67, core/README.md:40-49
Example: Multi-Protocol Configuration
A single client can be configured to interact with tools from various protocols simultaneously.
{
"manual_call_templates": [
{
"name": "my_rest_api",
"call_template_type": "http",
"url": "https://api.example.com/users/{user_id}"
},
{
"name": "local_scripts",
"call_template_type": "cli",
"commands": [{ "command": "python my_script.py UTCP_ARG_input_UTCP_END" }]
},
{
"name": "realtime_feed",
"call_template_type": "websocket",
"url": "wss://api.example.com/ws"
}
]
}
Sources: plugins/communication_protocols/http/README.md:27-32, plugins/communication_protocols/cli/README.md:30-41, plugins/communication_protocols/websocket/README.md:43-49
Summary
The UtcpClient is the central component for any application using the Universal Tool Calling Protocol. Its design prioritizes flexibility and extensibility, allowing it to serve as a single point of interaction for a diverse and growing set of tools. By leveraging a declarative configuration and a powerful plugin system, the client simplifies the process of integrating AI agents and other systems with external services, regardless of the underlying communication protocol.
Sources: README.md:10-17, core/README.md:12-21