Skip to content

Commit 600dbf4

Browse files
committed
📝 docs(README): update transport methods and tool registry
- clarify support for multiple MCP transport methods in both README_en.md and README_zh.md - add examples for MCP transport configuration including StreamableHttpTransport and FastMCP - enhance OpenAPI integration section with auto-discovery explanation and better examples - refine descriptions of hub tools with expanded functionality details - introduce community contribution section in both README files
1 parent 7e49aca commit 600dbf4

File tree

2 files changed

+80
-43
lines changed

2 files changed

+80
-43
lines changed

README_en.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ToolRegistry
22

3-
[中文版](README_zh.md)
3+
[English Version](README_en.md) | [中文版](README_zh.md)
44

55
A Python library for managing and executing tools in a structured way.
66

@@ -10,7 +10,8 @@ A Python library for managing and executing tools in a structured way.
1010
- JSON Schema generation for tool parameters
1111
- Tool execution and result handling
1212
- Support for both synchronous and asynchronous tools
13-
- Support [MCP sse](https://toolregistry.lab.oaklight.cn/mcp.html), [OpenAPI](https://toolregistry.lab.oaklight.cn/openapi.html) tools
13+
- Support multiple MCP transport methods: stdio, streamable HTTP, SSE, WebSocket
14+
- Support [OpenAPI](https://toolregistry.lab.oaklight.cn/openapi.html) tools
1415

1516
## Full Documentation
1617

@@ -91,38 +92,53 @@ For more usage examples, please refer to [Documentation - Usage](https://toolreg
9192
The ToolRegistry provides first-class support for MCP (Model Context Protocol) tools with multiple transport options:
9293

9394
```python
94-
# Can be URL string, path to script, or transport instance
95-
transport = "http://localhost:8000/sse"
96-
transport = "examples/mcp_related/mcp_servers/math_server.py"
95+
# transport can be a URL string, script path, transport instance, or MCP instance.
96+
transport = "https://mcphub.url/mcp" # Streamable HTTP MCP
97+
transport = "http://localhost:8000/sse/test_group" # Legacy HTTP+SSE
98+
transport = "examples/mcp_related/mcp_servers/math_server.py" # Local path
99+
transport = {
100+
"mcpServers": {
101+
"make_mcp": {
102+
"command": f"{Path.home()}/mambaforge/envs/toolregistry_dev/bin/python",
103+
"args": [
104+
f"{Path.home()}/projects/toolregistry/examples/mcp_related/mcp_servers/math_server.py"
105+
],
106+
"env": {},
107+
}
108+
}
109+
} # MCP configuration dictionary example
110+
transport = FastMCP(name="MyFastMCP") # FastMCP instance
111+
transport = StreamableHttpTransport(url="https://mcphub.example.com/mcp", headers={"Authorization": "Bearer token"}) # Transport instance with custom headers
97112

98113
registry.register_from_mcp(transport)
99114

100-
# Get all tools JSON including MCP tools
115+
# Get all tools' JSON, including MCP tools
101116
tools_json = registry.get_tools_json()
102117
```
103118

104-
Supported transport types:
105-
106-
- URL string (http://, https://, ws://, wss://)
107-
- Path to script file (.py, .js)
108-
- Existing ClientTransport instance
109-
- FastMCP instance
110-
111119
## OpenAPI Integration
112120

113121
ToolRegistry supports integration with OpenAPI for interacting with tools using a standardized API interface:
114122

115123
```python
116-
registry.register_from_openapi("http://localhost:8000/") # by providing baseurl
117-
registry.register_from_openapi("./openapi_spec.json", "http://localhost/") # by providing local OpenAPI spec file and base url
124+
registry.register_from_openapi("http://localhost:8000/") # Providing base URL
125+
registry.register_from_openapi("./openapi_spec.json", "http://localhost/") # Providing local OpenAPI specification file and base URL
118126

119-
# Get all tools JSON including OpenAPI tools
127+
# Get all tools' JSON, including OpenAPI tools
120128
tools_json = registry.get_tools_json()
121129
```
122130

123-
## Registering Hub Tools
131+
### Note
132+
133+
When only providing a base URL, ToolRegistry will attempt a "best effort" auto-discovery to find the OpenAPI specification file (e.g., via `http://<base_url>/openapi.json` or `http://<base_url>/swagger.json`). If discovery fails, ensure the provided URL is correct or download the OpenAPI specification file yourself and register using the file + base URL method:
134+
135+
```python
136+
registry.register_from_openapi("./openapi_spec.json", "http://localhost/")
137+
```
138+
139+
## Registering Class Tools
124140

125-
Hub tools are registered to ToolRegistry using the `register_from_class` method. This allows developers to extend the functionality of ToolRegistry by creating custom tool classes with reusable methods.
141+
Class tools are registered to ToolRegistry using the `register_from_class` method. This allows developers to extend the functionality of ToolRegistry by creating custom tool classes with reusable methods.
126142

127143
Example:
128144

@@ -154,17 +170,15 @@ print(registry["instance_example.greet"]("Alice")) # Hello, Alice! I'm Bob.
154170

155171
### Hub Tools
156172

157-
[Latest Available Tools](src/toolregistry/hub/)
158-
159-
Hub tools encapsulate commonly used functionalities as methods in classes. These tools are grouped for better organization and reusability.
173+
[Available Tools](src/toolregistry/hub/)
160174

161-
Examples of available hub tools include:
175+
Hub tools encapsulate commonly used functionalities as methods in classes. Examples of available hub tools include:
162176

163177
- **Calculator**: Basic arithmetic, scientific operations, statistical functions, financial calculations, and more.
164-
- **FileOps**: File manipulation operations like diff generation, patching, and verification.
165-
- **Filesystem**: Comprehensive file system operations such as directory listing, file reading/writing, and path manipulation.
166-
- **UnitConverter**: Extensive unit conversion tools for temperature, length, weight, and more.
167-
- **WebSearch**: Web search functionality supporting multiple search engines including SearxNG and Google.
178+
- **FileOps**: File manipulation like diff generation, patching, verification, merging, and splitting.
179+
- **Filesystem**: Comprehensive file system operations such as directory listing, file read/write, path normalization, and querying file attributes.
180+
- **UnitConverter**: Extensive unit conversions such as temperature, length, weight, volume, etc.
181+
- **WebSearch**: Web search functionality supporting multiple engines like SearxNG and Google.
168182

169183
To register hub tools:
170184

@@ -180,6 +194,10 @@ print(registry.get_available_tools())
180194
# Output: ['Calculator.add', 'Calculator.subtract', ..., 'Calculator.multiply', ...]
181195
```
182196

197+
### Community Contribution
198+
199+
We welcome community contributions of new tool classes to ToolRegistry! If you have designs or implementations for other commonly used tools, feel free to submit them through a Pull Request on the [GitHub Repository](https://github.com/yourrepository/toolregistry). Your contributions will help expand the diversity and usability of the tools.
200+
183201
## License
184202

185203
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

README_zh.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ToolRegistry
22

3-
[English Version](README_en.md)
3+
[English Version](README_en.md) | [中文版](README_zh.md)
44

55
一个用于以结构化方式管理和执行工具的 Python 库。
66

@@ -10,7 +10,8 @@
1010
- 工具参数的 JSON Schema 生成
1111
- 工具执行与结果处理
1212
- 支持同步和异步工具
13-
- 支持 [MCP sse](https://toolregistry.lab.oaklight.cn/mcp.html)[OpenAPI](https://toolregistry.lab.oaklight.cn/openapi.html) 工具
13+
- 支持多种 MCP 传输方式: stdio, streamable http, sse, websocket
14+
- 支持 [OpenAPI](https://toolregistry.lab.oaklight.cn/openapi.html) 工具
1415

1516
## 完整文档
1617

@@ -91,38 +92,52 @@ print(add_result) # 9
9192
ToolRegistry 提供对 MCP(模型上下文协议)工具的一流支持:
9293

9394
```python
94-
# 可以是URL字符串、脚本路径或transport实例
95-
transport = "http://localhost:8000/sse"
96-
transport = "examples/mcp_related/mcp_servers/math_server.py"
95+
# transport 可以是 URL 字符串、脚本路径、transport 实例或 MCP 实例。
96+
transport = "https://mcphub.url/mcp" # 使用 HTTP Streamable MCP
97+
transport = "http://localhost:8000/sse/test_group" # 使用 legacy HTTP+sse
98+
transport = "examples/mcp_related/mcp_servers/math_server.py" # 本地路径
99+
transport = {
100+
"mcpServers": {
101+
"make_mcp": {
102+
"command": f"{Path.home()}/mambaforge/envs/toolregistry_dev/bin/python",
103+
"args": [
104+
f"{Path.home()}/projects/toolregistry/examples/mcp_related/mcp_servers/math_server.py"
105+
],
106+
"env": {},
107+
}
108+
}
109+
} # 示例 MCP 配置字典
110+
transport = FastMCP(name="MyFastMCP") # 使用 FastMCP 实例
111+
transport = StreamableHttpTransport(url="https://mcphub.example.com/mcp", headers={"Authorization": "Bearer token"}) # 使用自定义头的 transport 实例
97112

98113
registry.register_from_mcp(transport)
99114

100115
# 获取所有工具的 JSON,包括 MCP 工具
101116
tools_json = registry.get_tools_json()
102-
```
103-
104-
支持的transport类型:
105-
106-
- URL字符串 (http://, https://, ws://, wss://)
107-
- 脚本文件路径 (.py, .js)
108-
- 现有的ClientTransport实例
109-
- FastMCP实例
110117

111118
## OpenAPI 集成
112119

113120
ToolRegistry 支持与 OpenAPI 集成,以使用标准化 API 接口与工具交互:
114121

115122
```python
116-
registry.register_from_openapi("http://localhost:8000/") # 提供基础 URL
117-
registry.register_from_openapi("./openapi_spec.json", "http://localhost/") # 提供本地 OpenAPI 规范文件和基础 URL
123+
registry.register_from_openapi("http://localhost:8000/") # 提供基础 URL
124+
registry.register_from_openapi("./openapi_spec.json", "http://localhost/") # 提供本地 OpenAPI 规范文件和基础 URL
118125

119126
# 获取所有工具的 JSON,包括 OpenAPI 工具
120127
tools_json = registry.get_tools_json()
121128
```
122129

123-
## 注册 Hub 工具
130+
### 注意事项
131+
132+
在仅提供基础 URL 的情况下,ToolRegistry 会尝试 "best effort" 自动发现 OpenAPI 规范文件(例如通过 `http://<base_url>/openapi.json``http://<base_url>/swagger.json`)。如果发现失败,请检查所提供的 URL 是否正确,或者自行下载 OpenAPI 规范文件并使用文件 + 基础 URL 的方式注册工具。例如:
133+
134+
```python
135+
registry.register_from_openapi("./openapi_spec.json", "http://localhost/")
136+
```
137+
138+
## 注册 Class 工具
124139

125-
Hub 工具通过 `register_from_class` 方法注册到 ToolRegistry。这允许开发人员通过创建具有可重用方法的自定义工具类来扩展 ToolRegistry 的功能。
140+
Class 工具通过 `register_from_class` 方法注册到 ToolRegistry。这允许开发人员通过创建具有可重用方法的自定义工具类来扩展 ToolRegistry 的功能。
126141

127142
示例:
128143

@@ -204,6 +219,10 @@ print(registry.get_available_tools())
204219
# 输出:['Calculator.add', 'Calculator.subtract', ..., 'Calculator.multiply', ...]
205220
```
206221

222+
### 社区贡献
223+
224+
我们欢迎社区贡献新的工具类到 ToolRegistry!如果您有其他常用工具类的设计或实现,欢迎通过 Pull Request 提交到 [GitHub 仓库](https://github.com/yourrepository/toolregistry)。您的贡献将帮助拓展工具的多样性和适用性。
225+
207226
## 许可证
208227

209228
此项目根据 MIT 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。

0 commit comments

Comments
 (0)