Text (File-based) Protocol Plugin
Relevant source files
The following files were used as context for generating this wiki page:The Text Protocol Plugin is a simple, file-based communication protocol for UTCP. It enables the definition and use of tools that read content directly from local files. This plugin is ideal for returning mock data, static configurations, or text templates without requiring a live server or network connection. It operates by discovering tools from local UTCP manual files (JSON/YAML) or by converting local OpenAPI specifications into UTCP tools.
The plugin's functionality is divided into two primary operations: discovering tools by reading a manual file, and executing a tool by returning the content of a different, specified file.
Sources: plugins/communication_protocols/text/README.md, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py
Architecture and Core Components
The plugin consists of two main components: the TextCallTemplate for configuration and the TextCommunicationProtocol for implementation logic. It leverages the utcp-http plugin's OpenApiConverter for handling OpenAPI specifications.
Sources: plugins/communication_protocols/text/pyproject.toml, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:15-16
This diagram illustrates the class structure and dependencies of the text plugin.
Key Features
| Feature | Description |
|---|---|
| Local File Content | Defines tools that read and return the content of local files. |
| UTCP Manual Discovery | Loads tool definitions from local UTCP manual files in JSON or YAML format. |
| OpenAPI Support | Automatically converts local OpenAPI specification files to UTCP tools. |
| Static & Simple | Ideal for returning mock data, configuration, or any static text content. |
| Tool Authentication | Supports authentication for tools generated from OpenAPI specs via the auth_tools field. |
Sources: plugins/communication_protocols/text/README.md
Configuration
The plugin is configured using a TextCallTemplate. This template is used both for discovering a manual of tools and for defining the behavior of an individual tool.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | A unique name for the manual call template. |
call_template_type | string | Yes | Must be "text". |
file_path | string | Yes | The path to the local file. This can be a UTCP Manual, an OpenAPI spec, or a content file for a tool. |
auth_tools | object | No | Authentication configuration for tools generated from an OpenAPI spec. |
Sources: README.md, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:42,70
Example manual_call_templates Configuration
This JSON snippet shows how to configure the UtcpClient to use the text plugin to load a manual.
{
"manual_call_templates": [{
"name": "local_file_tools",
"call_template_type": "text",
"file_path": "./manuals/local_tools.json"
}]
}
Sources: plugins/communication_protocols/text/README.md
Operational Flow
The plugin has two distinct operational flows: registering a manual to discover tools and calling a discovered tool.
1. Tool Discovery (register_manual)
This process is initiated when the UtcpClient is created with a TextCallTemplate. The plugin reads the specified file_path, parses it, and registers the defined tools.
The following diagram shows the workflow for the register_manual method.
The implementation intelligently detects if the file is a standard UTCP Manual (in JSON or YAML) or an OpenAPI specification. If it's an OpenAPI spec, it uses the OpenApiConverter to transform it into a UtcpManual before registration.
Sources: plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:64-72
2. Tool Execution (call_tool)
When a tool associated with the text plugin is called, the call_tool method is executed. This operation is straightforward: it reads and returns the entire content of the file_path defined in the tool's own tool_call_template.
Important: Any arguments passed to call_tool are ignored. The function's sole purpose is to return the file's content.
Sources: plugins/communication_protocols/text/README.md, plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:111-120
This sequence diagram shows the tool execution flow.
The streaming variant, call_tool_streaming, behaves similarly but yields the entire file content as a single chunk in an async generator.
Sources: plugins/communication_protocols/text/src/utcp_text/text_communication_protocol.py:122-124
Installation and Integration
The plugin is a separate package that must be installed alongside the core utcp library.
pip install utcp-text
Sources: plugins/communication_protocols/text/README.md, README.md
The plugin integrates automatically with the UtcpClient through Python's entry points mechanism. The pyproject.toml file declares the plugin, allowing the UtcpClient to find and use TextCommunicationProtocol whenever it encounters a call_template_type of "text".
# plugins/communication_protocols/text/pyproject.toml
[project.entry-points."utcp.plugins"]
text = "utcp_text:register"
Sources: plugins/communication_protocols/text/pyproject.toml
Summary
The Text (File-based) Protocol Plugin provides a foundational capability for the UTCP ecosystem by bridging the gap between the protocol and the local filesystem. It offers a zero-dependency (besides file access) way to load tool definitions, mock API responses, and serve static data, making it an essential tool for development, testing, and simple data retrieval scenarios. Its ability to ingest both standard UTCP manuals and OpenAPI specifications further enhances its utility as a versatile data source for the UtcpClient.
Sources: plugins/communication_protocols/text/README.md, core/README.md