Plugin Discovery and Loading
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- core/README.md
- plugins/communication_protocols/http/pyproject.toml
- plugins/communication_protocols/websocket/pyproject.toml
- plugins/communication_protocols/text/pyproject.toml
- plugins/communication_protocols/mcp/pyproject.toml
- plugins/tool_search/in_mem_embeddings/tests/test_integration.py
- scripts/extract_required_docs.py
The Universal Tool Calling Protocol (UTCP) core is designed to be lightweight and extensible. Its functionality is expanded through a modular plugin-based architecture. This system allows developers to add new communication protocols, tool search strategies, and other capabilities without modifying the core library.
The plugin system is the cornerstone of UTCP's extensibility and interoperability, enabling it to integrate with a wide variety of services and infrastructures. Discovery and loading are handled automatically at runtime, making it seamless for both developers using the UtcpClient and those creating new plugins.
Sources: README.md:14-21, core/README.md:12-19
Plugin Discovery Mechanism
UTCP leverages Python's standard entry point mechanism, provided by setuptools, to discover available plugins. When a Python package containing a UTCP plugin is installed in the environment, it registers itself under a specific entry point group.
Sources: plugins/communication_protocols/http/pyproject.toml:35-36, plugins/communication_protocols/websocket/pyproject.toml:31-32
Entry Point Registration
Plugins declare their existence by adding an entry to the [project.entry-points."utcp.plugins"] section in their pyproject.toml file. Each entry consists of a unique name for the plugin and a reference to a register function within the plugin's code.
Here is an example from the utcp-http plugin:
[project.entry-points."utcp.plugins"]
http = "utcp_http:register"
Sources: plugins/communication_protocols/http/pyproject.toml:35-36
This line tells the UTCP core that a plugin named http is available and its registration logic can be found in the register function inside the utcp_http package.
The following diagram illustrates how plugins are discovered via entry points.
Plugin Loading and Registration
Once a plugin is discovered, the UTCP core loads its register function and executes it. This function is responsible for integrating the plugin's components into the core system's registries.
The process is demonstrated in integration tests, where a plugin's register() function is called, and the test then verifies that the plugin's components are available through the core system's serializers or registries.
Sources: plugins/tool_search/in_mem_embeddings/tests/test_integration.py:18-21, plugins/tool_search/in_mem_embeddings/tests/test_integration.py:40-43
Registration Flow
The following sequence diagram shows the typical flow from client creation to a plugin's components being ready for use.
Available Plugin Types
UTCP supports different types of plugins, primarily for communication protocols and tool search strategies. This is evident from the repository structure and the different plugin packages available.
Sources: README.md:25-32, core/README.md:12-19
Communication Protocol Plugins
These plugins add support for new communication protocols. Each one registers a handler for a specific call_template_type.
| Plugin Package | call_template_type | Entry Point Name | pyproject.toml |
|---|---|---|---|
utcp-http | http, sse, streamable_http | http | plugins/communication_protocols/http/pyproject.toml |
utcp-websocket | websocket | websocket | plugins/communication_protocols/websocket/pyproject.toml |
utcp-cli | cli | cli | plugins/communication_protocols/cli/README.md |
utcp-mcp | mcp | mcp | plugins/communication_protocols/mcp/pyproject.toml |
utcp-text | text | text | plugins/communication_protocols/text/pyproject.toml |
utcp-gql | gql (in progress) | (not defined) | plugins/communication_protocols/gql/pyproject.toml |
Sources: README.md:62-72, plugins/communication_protocols/http/pyproject.toml:36, plugins/communication_protocols/websocket/pyproject.toml:32, plugins/communication_protocols/mcp/pyproject.toml:29, plugins/communication_protocols/text/pyproject.toml:30
Tool Search Strategy Plugins
These plugins provide alternative algorithms for searching and ranking tools within a ToolRepository. An example is the in_mem_embeddings plugin, which uses sentence transformers for semantic search.
The integration test for this plugin shows it being discovered and used via the ToolSearchStrategyConfigSerializer.
# From plugins/tool_search/in_mem_embeddings/tests/test_integration.py
@pytest.mark.asyncio
async def test_plugin_discovery(register_plugin):
"""Test that the core system can discover the registered plugin."""
from utcp.interfaces.tool_search_strategy import ToolSearchStrategyConfigSerializer
strategies = ToolSearchStrategyConfigSerializer.tool_search_strategy_implementations
assert "in_mem_embeddings" in strategies, "Plugin should be discoverable by core system"
Sources: plugins/tool_search/in_mem_embeddings/tests/test_integration.py:40-46
Summary
The plugin architecture is a fundamental aspect of UTCP, providing its core extensibility. By using standard Python entry points, the system can dynamically discover and integrate new functionalities from separately installed packages. This allows for a clean separation between the core protocol logic and specific implementations for communication, tool search, and more. This modular design ensures that UTCP can easily adapt to new technologies and integrate with a vast ecosystem of existing tools and services.
Sources: README.md:14-21, core/README.md:12-19