UTCP Manuals
Relevant source files
The following files were used as context for generating this wiki page:A UtcpManual is the standardized format for describing a collection of tools within the Universal Tool Calling Protocol (UTCP). It serves as the contract for tool discovery, allowing a UtcpClient to learn about the tools offered by a provider, including their names, descriptions, input/output schemas, and how to invoke them. The manual is the authoritative source of truth for what tools a provider offers and is fundamental to UTCP's principles of interoperability and extensibility.
Manuals are typically exposed via a discovery mechanism, such as a /utcp endpoint on a web server, or loaded from local files. They can be created manually, generated automatically from code using decorators, or converted from existing API specifications like OpenAPI. This flexibility allows UTCP to integrate with a wide range of existing services and infrastructure.
Sources: core/src/utcp/data/utcp_manual.py:6-15, core/README.md:209-212
UtcpManual Data Structure
The UtcpManual is a Pydantic BaseModel that defines the structure for tool discovery responses. It contains versioning information and a list of Tool objects.
Sources: core/src/utcp/data/utcp_manual.py:20-22
Core Components
The diagram below illustrates the relationship between UtcpManual and its primary component, the Tool.
This class diagram shows that a UtcpManual contains a list of Tool objects, each defining a specific capability.
Sources: core/src/utcp/data/utcp_manual.py:20-49, core/src/utcp/data/tool.py
Fields
| Field | Type | Description |
|---|---|---|
utcp_version | str | The UTCP protocol version supported by the provider. Defaults to the current library version. |
manual_version | str | The version of the manual itself, for tracking changes to the tool definitions. Defaults to "1.0.0". |
tools | List[Tool] | A list of available Tool objects, each with its complete configuration, including schemas, description, and tool_call_template. |
Sources: core/src/utcp/data/utcp_manual.py:43-45
JSON Representation
The following is an example of a UtcpManual serialized to JSON. This structure is what a tool provider would return from a discovery endpoint.
{
"manual_version": "1.0.0",
"utcp_version": "1.0.2",
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a location",
"tags": ["weather"],
"inputs": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
},
"outputs": {
"type": "object",
"properties": {
"temperature": {"type": "number"},
"conditions": {"type": "string"}
}
},
"tool_call_template": {
"call_template_type": "http",
"url": "https://example.com/api/weather",
"http_method": "GET"
}
}
]
}
Sources: README.md:237-264
Manual Discovery and Registration
The UtcpClient discovers tools by registering manuals. This process is initiated by a CallTemplate which tells the client how to fetch the manual. The client delegates the registration to the appropriate CommunicationProtocol based on the call_template_type.
The protocol returns a RegisterManualResult object, which contains the fetched UtcpManual, a success flag, and any errors. If successful, the client saves the manual and its tools to the configured ToolRepository.
Sources: core/tests/client/test_utcp_client.py:183-200, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:38-41
Registration Flow
This sequence diagram shows how a UtcpClient registers a manual using a communication protocol.
This diagram illustrates the interaction between the client, a communication protocol, and the tool repository during the manual registration process.
Sources: core/tests/client/test_utcp_client.py:114-121, core/tests/client/test_utcp_client.py:183-200
RegisterManualResult Data Structure
This object encapsulates the result of a manual registration attempt.
| Field | Type | Description |
|---|---|---|
manual_call_template | CallTemplate | The call template used to fetch the manual. |
manual | UtcpManual | The UtcpManual object that was fetched and parsed. |
success | bool | A boolean flag indicating if the registration was successful. |
errors | List[str] | A list of error messages if the registration failed. |
Sources: core/src/utcp/data/register_manual_response.py:11-19
Creating a UtcpManual
UTCP provides several methods for creating a UtcpManual, catering to different use cases from greenfield development to integrating existing systems.
From Decorators
For new Python-based tools, the @utcp_tool decorator can be used to mark functions as tools. The UtcpManual.create_from_decorators() static method collects all decorated tools from the global ToolContext and assembles them into a UtcpManual.
This is the most straightforward way to expose tools from a Python application.
from fastapi import FastAPI
from utcp.data.utcp_manual import UtcpManual
from utcp.python_specific_tooling.tool_decorator import utcp_tool
app = FastAPI()
# The discovery endpoint returns the tool manual
@app.get("/utcp")
def utcp_discovery():
return UtcpManual.create_from_decorators(manual_version="1.0.0")
@utcp_tool(...)
@app.get("/api/weather")
def get_weather(location: str):
# ... tool logic ...
Sources: core/src/utcp/data/utcp_manual.py:72-79, core/README.md:216-229
From OpenAPI Specifications
UTCP can automatically generate a UtcpManual from an OpenAPI v2.0 or v3.0 specification. The OpenApiConverter class handles this conversion, transforming API endpoints into UTCP Tool objects. This is a powerful feature for integrating existing REST APIs into UTCP without any code changes on the server side.
The TextCommunicationProtocol demonstrates this by detecting if a file contains an OpenAPI spec and using the converter automatically.
Sources: README.md:376-380, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:61-69
The following flowchart shows the process of converting an OpenAPI specification into a UTCP Manual.
From Local Files
The utcp-text plugin allows loading a UtcpManual directly from a local JSON or YAML file. The TextCommunicationProtocol reads the file specified in a TextCallTemplate and parses it. This method is ideal for static tool definitions, mock data, or configurations that can be version-controlled alongside the application code.
# Client configuration to load a manual from a local file
client = await UtcpClient.create(config={
"manual_call_templates": [{
"name": "local_file_tools",
"call_template_type": "text",
"file_path": "./manuals/local_tools.json"
}]
})
Sources: plugins/communication_protocols/text/README.md:49-60, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:43-50
Serialization and Validation
The UtcpManualSerializer is responsible for converting UtcpManual objects to and from dictionaries. This is crucial for handling data from discovery endpoints (which is typically JSON) and for validating that the data conforms to the UtcpManual schema.
The serializer uses model_dump() for conversion to a dictionary and model_validate() for creating an object from a dictionary, wrapping any validation errors in a UtcpSerializerValidationError.
Sources: core/src/utcp/data/utcp_manual.py:108-131
UtcpManualSerializer Methods
| Method | Description |
|---|---|
to_dict() | Converts a UtcpManual object into its dictionary representation. |
validate_dict() | Validates a dictionary against the UtcpManual model and converts it into a UtcpManual object. |
Sources: core/src/utcp/data/utcp_manual.py:111-131
Conclusion
The UtcpManual is a cornerstone of the UTCP architecture, providing a standardized and flexible mechanism for tool discovery. By defining a clear contract between tool providers and clients, it enables seamless integration, automated tool generation, and robust versioning. The various methods for creating manuals—from decorators, OpenAPI specs, or local files—make UTCP a highly adaptable protocol for both new and existing systems, reinforcing its goal of being a universal standard for tool interaction.
Sources: core/src/utcp/data/utcp_manual.py:6-15, README.md:12-21