Creating Custom Plugins
Relevant source files
The following files were used as context for generating this wiki page:- plugins/communication_protocols/websocket/README.md
- core/README.md
- scripts/extract_required_docs.py
- README.md
- CLAUDE.md
- plugins/communication_protocols/text/README.md
- plugins/communication_protocols/mcp/README.md
- plugins/communication_protocols/cli/README.md
- plugins/communication_protocols/http/README.md
- plugins/communication_protocols/text/pyproject.toml
- plugins/communication_protocols/http/pyproject.toml
- plugins/tool_search/in_mem_embeddings/tests/test_integration.py
- plugins/communication_protocols/mcp/pyproject.toml
- plugins/communication_protocols/websocket/pyproject.toml
- plugins/communication_protocols/cli/pyproject.toml
The Universal Tool Calling Protocol (UTCP) is built on a modular, plugin-based architecture that emphasizes extensibility. This design allows developers to easily add new communication protocols, tool storage mechanisms, and search strategies without modifying the core library. By creating custom plugins, you can integrate UTCP with almost any existing service or infrastructure.
This guide details the process of creating, packaging, and registering custom plugins to extend the functionality of the UTCP client. The core mechanism relies on Python's entry points system, which allows the UTCP core to discover and load plugins from installed packages automatically.
Sources: README.md, core/README.md
Plugin Architecture
UTCP's architecture separates the core client logic from protocol-specific implementations. Plugins are self-contained packages that implement specific interfaces defined by the core system. The UtcpClient discovers these plugins at runtime and uses them to handle different types of call_template_type or to provide different functionalities like tool searching.
Sources: README.md, core/README.md, CLAUDE.md
This diagram illustrates the relationship between the UTCP Core and various plugin types.
Plugin Types
UTCP supports several types of plugins. The most common are Communication Protocols and Tool Search Strategies.
| Plugin Type | Description | Examples |
|---|---|---|
| Communication Protocol | Implements a specific transport protocol for calling tools. Each protocol is identified by a unique call_template_type. | http, cli, websocket, mcp, text, sse |
| Tool Search Strategy | Implements an algorithm for searching and ranking tools within a ToolRepository. | tag_and_description_word_match, in_mem_embeddings |
Sources: README.md, core/README.md, plugins/tool_search/in_mem_embeddings/tests/test_integration.py
Creating a Plugin
Creating a custom plugin involves packaging your implementation and making it discoverable through a Python entry point.
1. Package Structure
A plugin should be a standard, installable Python package. It typically contains a pyproject.toml file for build and dependency management, and a source directory for the implementation.
my-utcp-plugin/
├── pyproject.toml
├── README.md
└── src/
└── my_utcp_plugin/
├── __init__.py
└── implementation.py
2. The Entry Point
The key to making a plugin discoverable is the [project.entry-points."utcp.plugins"] section in the pyproject.toml file. The UTCP core scans for installed packages with this entry point to find and load plugins.
The entry point defines a name for your plugin and points to a register function within your package.
[project.entry-points."utcp.plugins"]
my_plugin_name = "my_utcp_plugin:register"
Here are examples from existing UTCP plugins:
HTTP Plugin:
# plugins/communication_protocols/http/pyproject.toml
[project.entry-points."utcp.plugins"]
http = "utcp_http:register"
Sources: plugins/communication_protocols/http/pyproject.toml:37-38
CLI Plugin:
# plugins/communication_protocols/cli/pyproject.toml
[project.entry-points."utcp.plugins"]
cli = "utcp_cli:register"
Sources: plugins/communication_protocols/cli/pyproject.toml:29-30
WebSocket Plugin:
# plugins/communication_protocols/websocket/pyproject.toml
[project.entry-points."utcp.plugins"]
websocket = "utcp_websocket:register"
Sources: plugins/communication_protocols/websocket/pyproject.toml:29-30
3. The register Function and Discovery
The register function is the bridge between your plugin and the UTCP core. When the UTCP client initializes, it finds all entry points and calls their respective register functions. This function is responsible for registering the plugin's implementation with the appropriate core system (e.g., a serializer or a factory).
The following sequence diagram shows the plugin discovery and registration process.
An integration test for the in_mem_embeddings plugin demonstrates this process. The test first calls register() and then verifies that the core system can discover and create an instance of the plugin's strategy via the ToolSearchStrategyConfigSerializer.
Sources: plugins/tool_search/in_mem_embeddings/tests/test_integration.py:18-21, 49-51
4. Implementing the Plugin Interface
Your plugin must implement a specific interface defined by the UTCP core.
Communication Protocol Plugin
A communication protocol plugin must implement the ClientTransportInterface. This interface is responsible for two main actions:
- Discovering tools: Reading a
UtcpManualfrom a source (like a URL or file). - Calling tools: Executing a tool call over the specific protocol.
The methods to implement can be inferred from the functionality of existing plugins like HTTP, CLI, and WebSocket, which all support call_tool and some support call_tool_streaming.
Sources: CLAUDE.md, plugins/communication_protocols/http/README.md, plugins/communication_protocols/websocket/README.md
Tool Search Strategy Plugin
A tool search strategy plugin implements the ToolSearchStrategy interface. The primary responsibility is to search for tools based on a query string.
The in_mem_embeddings integration test shows that this interface must have a search_tools method.
# From plugins/tool_search/in_mem_embeddings/tests/test_integration.py
results = await strategy.search_tools(tool_repository, "cooking", limit=1)
This method takes a tool repository, a search query, and a limit as arguments and returns a list of matching Tool objects.
Sources: CLAUDE.md, plugins/tool_search/in_mem_embeddings/tests/test_integration.py:84-85
Summary
Creating a custom UTCP plugin allows for powerful extensions to the core framework. The process is standardized around Python's packaging and entry point system, ensuring that new functionalities can be seamlessly integrated.
The key steps are:
- Structure your code as an installable Python package.
- Define an entry point in your
pyproject.tomlunder[project.entry-points."utcp.plugins"]that points to aregisterfunction. - Implement the
registerfunction to make your plugin's classes known to the UTCP core serializers or factories. - Implement the required interface for your plugin type, such as
ClientTransportInterfacefor communication protocols orToolSearchStrategyfor search algorithms.
By following this pattern, your plugin will be automatically discovered and utilized by the UtcpClient, making the rich features of UTCP available to any protocol or system you wish to integrate.
Sources: README.md, core/README.md, plugins/communication_protocols/http/pyproject.toml