
Show HN: ToolRegistry – A Python Library for Structured Tool Integration by Oaklight
A Python library for managing and executing tools in a structured way.
- Tool registration and management
- JSON Schema generation for tool parameters
- Tool execution and result handling
- Support for both synchronous and asynchronous tools
- Support multiple MCP transport methods: stdio, streamable HTTP, SSE, WebSocket
- Support OpenAPI tools
Full documentation is available at https://toolregistry.lab.oaklight.cn
Previously, the method ToolRegistry.register_static_tools
was used for registering static methods from classes. This has now been replaced by ToolRegistry.register_from_class
. Similarly, ToolRegistry.register_mcp_tools
has been replaced by ToolRegistry.register_from_mcp
, and ToolRegistry.register_openapi_tools
by ToolRegistry.register_from_openapi
. All old methods are planned to be deprecated soon, so please migrate to the new interfaces as soon as possible. For backward compatibility, the old names remain as aliases to the new ones.
Install the core package (requires Python >= 3.8):
Extra modules can be installed by specifying extras in brackets. For example, to install specific extra supports:
pip install toolregistry[mcp,openapi]
Below is a table summarizing available extra modules:
Extra Module | Python Requirement | Example Command |
---|---|---|
mcp | Python >= 3.10 | pip install toolregistry[mcp] |
openapi | Python >= 3.8 | pip install toolregistry[openapi] |
The openai_tool_usage_example.py shows how to integrate ToolRegistry with OpenAI’s API.
The cicada_tool_usage_example.py demonstrates how to use ToolRegistry with the Cicada MultiModalModel.
This section demonstrates how to invoke a basic tool. Example:
return a + b
available_tools = registry.get_available_tools()
print(available_tools) # ['add']
add_func = registry.get_callable('add')
print(type(add_func)) #
add_result = add_func(1, 2)
print(add_result) # 3
add_func = registry['add']
print(type(add_func)) #
add_result = add_func(4, 5)
print(add_result) # 9
For more usage examples, please refer to Documentation – Usage
The ToolRegistry provides first-class support for MCP (Model Context Protocol) tools with multiple transport options:
# transport can be a URL string, script path, transport instance, or MCP instance. transport = "https://mcphub.url/mcp" # Streamable HTTP MCP transport = "http://localhost:8000/sse/test_group" # Legacy HTTP+SSE transport = "examples/mcp_related/mcp_servers/math_server.py" # Local path transport = { "mcpServers": { "make_mcp": { "command": f"{Path.home()}/mambaforge/envs/toolregistry_dev/bin/python", "args": [ f"{Path.home()}/projects/toolregistry/examples/mcp_related/mcp_servers/math_server.py" ], "env": {}, } } } # MCP configuration dictionary example transport = FastMCP(name="MyFastMCP") # FastMCP instance transport = StreamableHttpTransport(url="https://mcphub.example.com/mcp", headers={"Authorization": "Bearer token"}) # Transport instance with custom headers registry.register_from_mcp(transport) # Get all tools' JSON, including MCP tools tools_json = registry.get_tools_json()
ToolRegistry supports integration with OpenAPI for interacting with tools using a standardized API interface:
registry.register_from_openapi("http://localhost:8000/") # Providing base URL registry.register_from_openapi("./openapi_spec.json", "http://localhost/") # Providing local OpenAPI specification file and base URL # Get all tools' JSON, including OpenAPI tools tools_json = registry.get_tools_json()
When only providing a base URL, ToolRegistry will attempt a “best effort” auto-discovery to find the OpenAPI specification file (e.g., via http://
or http://
). If discovery fails, ensure the prov
1 Comment
Oaklight
Author here!
I’ve been working on ToolRegistry, a Python library for registering, managing, and invoking tools—from local functions to MCP/OpenAPI endpoints—in a structured, composable way.
With ToolRegistry, you can:
* Register Python functions, classes, or external tools.
* Auto-generate JSON Schemas for parameters.
* Run tools synchronously or asynchronously in parallel.
* Integrate tools over STDIO, HTTP, WebSocket, or SSE via Model Context Protocol (MCP).
* Experimental support for OpenAPI services
* Compose tools dynamically and reconstruct tool output messages.
The goal is to make it easier to build apps, agents, or systems that coordinate multiple tools flexibly—without getting bogged down in glue code.
GitHub: [https://github.com/Oaklight/ToolRegistry](https://github.com/Oaklight/ToolRegistry)
PyPI: [https://pypi.org/project/toolregistry/](https://pypi.org/project/toolregistry/)
Docs: [https://toolregistry.lab.oaklight.cn](https://toolregistry.lab.oaklight.cn)
Would love feedback—ideas, issues, or use cases welcome!
Thanks for checking it out.