toolanything 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. toolanything-0.1.0/LICENSE +21 -0
  2. toolanything-0.1.0/PKG-INFO +355 -0
  3. toolanything-0.1.0/README.md +324 -0
  4. toolanything-0.1.0/pyproject.toml +56 -0
  5. toolanything-0.1.0/setup.cfg +4 -0
  6. toolanything-0.1.0/setup.py +4 -0
  7. toolanything-0.1.0/src/toolanything/__init__.py +250 -0
  8. toolanything-0.1.0/src/toolanything/__main__.py +4 -0
  9. toolanything-0.1.0/src/toolanything/adapters/__init__.py +11 -0
  10. toolanything-0.1.0/src/toolanything/adapters/base_adapter.py +41 -0
  11. toolanything-0.1.0/src/toolanything/adapters/mcp_adapter.py +144 -0
  12. toolanything-0.1.0/src/toolanything/adapters/openai_adapter.py +156 -0
  13. toolanything-0.1.0/src/toolanything/cli.py +606 -0
  14. toolanything-0.1.0/src/toolanything/core/__init__.py +93 -0
  15. toolanything-0.1.0/src/toolanything/core/builtin_tools.py +29 -0
  16. toolanything-0.1.0/src/toolanything/core/connection_tester.py +766 -0
  17. toolanything-0.1.0/src/toolanything/core/credentials.py +35 -0
  18. toolanything-0.1.0/src/toolanything/core/doctor_server.py +41 -0
  19. toolanything-0.1.0/src/toolanything/core/failure_log.py +66 -0
  20. toolanything-0.1.0/src/toolanything/core/http_tools.py +86 -0
  21. toolanything-0.1.0/src/toolanything/core/invokers/__init__.py +9 -0
  22. toolanything-0.1.0/src/toolanything/core/invokers/base.py +25 -0
  23. toolanything-0.1.0/src/toolanything/core/invokers/callable_invoker.py +58 -0
  24. toolanything-0.1.0/src/toolanything/core/invokers/http_invoker.py +188 -0
  25. toolanything-0.1.0/src/toolanything/core/invokers/model_invoker.py +229 -0
  26. toolanything-0.1.0/src/toolanything/core/invokers/sql_invoker.py +146 -0
  27. toolanything-0.1.0/src/toolanything/core/metadata.py +68 -0
  28. toolanything-0.1.0/src/toolanything/core/model_runtime.py +34 -0
  29. toolanything-0.1.0/src/toolanything/core/model_tools.py +91 -0
  30. toolanything-0.1.0/src/toolanything/core/models.py +181 -0
  31. toolanything-0.1.0/src/toolanything/core/registry.py +352 -0
  32. toolanything-0.1.0/src/toolanything/core/result_serializer.py +19 -0
  33. toolanything-0.1.0/src/toolanything/core/runtime_types.py +42 -0
  34. toolanything-0.1.0/src/toolanything/core/schema.py +141 -0
  35. toolanything-0.1.0/src/toolanything/core/security_manager.py +77 -0
  36. toolanything-0.1.0/src/toolanything/core/selection_strategies.py +193 -0
  37. toolanything-0.1.0/src/toolanything/core/semantic_search.py +510 -0
  38. toolanything-0.1.0/src/toolanything/core/source_specs.py +97 -0
  39. toolanything-0.1.0/src/toolanything/core/sql_connections.py +111 -0
  40. toolanything-0.1.0/src/toolanything/core/sql_tools.py +62 -0
  41. toolanything-0.1.0/src/toolanything/core/tool_manager.py +163 -0
  42. toolanything-0.1.0/src/toolanything/core/tool_search.py +115 -0
  43. toolanything-0.1.0/src/toolanything/decorators/__init__.py +4 -0
  44. toolanything-0.1.0/src/toolanything/decorators/pipeline.py +55 -0
  45. toolanything-0.1.0/src/toolanything/decorators/tool.py +64 -0
  46. toolanything-0.1.0/src/toolanything/exceptions.py +46 -0
  47. toolanything-0.1.0/src/toolanything/host_adapters/__init__.py +8 -0
  48. toolanything-0.1.0/src/toolanything/host_adapters/base.py +90 -0
  49. toolanything-0.1.0/src/toolanything/inspector/__init__.py +6 -0
  50. toolanything-0.1.0/src/toolanything/inspector/app.py +159 -0
  51. toolanything-0.1.0/src/toolanything/inspector/service.py +1018 -0
  52. toolanything-0.1.0/src/toolanything/inspector/static/app.js +1131 -0
  53. toolanything-0.1.0/src/toolanything/inspector/static/index.html +263 -0
  54. toolanything-0.1.0/src/toolanything/inspector/static/styles.css +1174 -0
  55. toolanything-0.1.0/src/toolanything/openai_runtime.py +332 -0
  56. toolanything-0.1.0/src/toolanything/pipeline/__init__.py +21 -0
  57. toolanything-0.1.0/src/toolanything/pipeline/context.py +84 -0
  58. toolanything-0.1.0/src/toolanything/pipeline/steps.py +50 -0
  59. toolanything-0.1.0/src/toolanything/protocol/__init__.py +1 -0
  60. toolanything-0.1.0/src/toolanything/protocol/mcp_jsonrpc.py +372 -0
  61. toolanything-0.1.0/src/toolanything/runtime/__init__.py +24 -0
  62. toolanything-0.1.0/src/toolanything/runtime/concurrency.py +149 -0
  63. toolanything-0.1.0/src/toolanything/runtime/serve.py +115 -0
  64. toolanything-0.1.0/src/toolanything/server/__init__.py +3 -0
  65. toolanything-0.1.0/src/toolanything/server/mcp_auth.py +14 -0
  66. toolanything-0.1.0/src/toolanything/server/mcp_runtime.py +110 -0
  67. toolanything-0.1.0/src/toolanything/server/mcp_sse_asgi.py +234 -0
  68. toolanything-0.1.0/src/toolanything/server/mcp_stdio_server.py +68 -0
  69. toolanything-0.1.0/src/toolanything/server/mcp_streamable_http.py +854 -0
  70. toolanything-0.1.0/src/toolanything/server/mcp_tool_server.py +631 -0
  71. toolanything-0.1.0/src/toolanything/state/__init__.py +3 -0
  72. toolanything-0.1.0/src/toolanything/state/context.py +18 -0
  73. toolanything-0.1.0/src/toolanything/state/manager.py +158 -0
  74. toolanything-0.1.0/src/toolanything/utils/__init__.py +1 -0
  75. toolanything-0.1.0/src/toolanything/utils/docstring_parser.py +122 -0
  76. toolanything-0.1.0/src/toolanything/utils/introspection.py +7 -0
  77. toolanything-0.1.0/src/toolanything/utils/json_tools.py +12 -0
  78. toolanything-0.1.0/src/toolanything/utils/logger.py +30 -0
  79. toolanything-0.1.0/src/toolanything/utils/openai_tool_names.py +66 -0
  80. toolanything-0.1.0/src/toolanything.egg-info/PKG-INFO +355 -0
  81. toolanything-0.1.0/src/toolanything.egg-info/SOURCES.txt +125 -0
  82. toolanything-0.1.0/src/toolanything.egg-info/dependency_links.txt +1 -0
  83. toolanything-0.1.0/src/toolanything.egg-info/entry_points.txt +2 -0
  84. toolanything-0.1.0/src/toolanything.egg-info/requires.txt +13 -0
  85. toolanything-0.1.0/src/toolanything.egg-info/top_level.txt +1 -0
  86. toolanything-0.1.0/tests/test_adapter_protocol_mapping.py +54 -0
  87. toolanything-0.1.0/tests/test_async_execution.py +36 -0
  88. toolanything-0.1.0/tests/test_bfcl_converter.py +165 -0
  89. toolanything-0.1.0/tests/test_bfcl_pipeline.py +120 -0
  90. toolanything-0.1.0/tests/test_callable_invoker.py +125 -0
  91. toolanything-0.1.0/tests/test_cli.py +257 -0
  92. toolanything-0.1.0/tests/test_concurrency.py +69 -0
  93. toolanything-0.1.0/tests/test_context_injection.py +36 -0
  94. toolanything-0.1.0/tests/test_decorator.py +47 -0
  95. toolanything-0.1.0/tests/test_docstring_parser.py +32 -0
  96. toolanything-0.1.0/tests/test_doctor_stdio.py +38 -0
  97. toolanything-0.1.0/tests/test_example_opencv_mcp_web.py +210 -0
  98. toolanything-0.1.0/tests/test_hf_dataset_exporter.py +217 -0
  99. toolanything-0.1.0/tests/test_http_tools.py +251 -0
  100. toolanything-0.1.0/tests/test_inspector_service.py +332 -0
  101. toolanything-0.1.0/tests/test_invoker_runtime_path.py +77 -0
  102. toolanything-0.1.0/tests/test_manager_batch.py +37 -0
  103. toolanything-0.1.0/tests/test_mcp_adapter.py +45 -0
  104. toolanything-0.1.0/tests/test_mcp_server_integration.py +286 -0
  105. toolanything-0.1.0/tests/test_mcp_streamable_http.py +653 -0
  106. toolanything-0.1.0/tests/test_model_tools.py +252 -0
  107. toolanything-0.1.0/tests/test_openai_adapter.py +86 -0
  108. toolanything-0.1.0/tests/test_openai_runtime.py +57 -0
  109. toolanything-0.1.0/tests/test_parallel_step.py +28 -0
  110. toolanything-0.1.0/tests/test_persistent_state_manager.py +61 -0
  111. toolanything-0.1.0/tests/test_pipeline.py +25 -0
  112. toolanything-0.1.0/tests/test_pipeline_context.py +29 -0
  113. toolanything-0.1.0/tests/test_refactor_phase0_baseline.py +184 -0
  114. toolanything-0.1.0/tests/test_registry_cache.py +48 -0
  115. toolanything-0.1.0/tests/test_registry_execution_semantics.py +20 -0
  116. toolanything-0.1.0/tests/test_registry_namespacing.py +85 -0
  117. toolanything-0.1.0/tests/test_schema_engine.py +106 -0
  118. toolanything-0.1.0/tests/test_security_and_serializer.py +48 -0
  119. toolanything-0.1.0/tests/test_semantic_benchmark.py +210 -0
  120. toolanything-0.1.0/tests/test_semantic_search.py +353 -0
  121. toolanything-0.1.0/tests/test_sql_tools.py +244 -0
  122. toolanything-0.1.0/tests/test_state_manager.py +16 -0
  123. toolanything-0.1.0/tests/test_streamable_http_and_model_examples.py +108 -0
  124. toolanything-0.1.0/tests/test_tool_manager.py +34 -0
  125. toolanything-0.1.0/tests/test_tool_metadata.py +56 -0
  126. toolanything-0.1.0/tests/test_tool_search_tool.py +158 -0
  127. toolanything-0.1.0/tests/test_tool_selection_examples.py +69 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AllanYiin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,355 @@
1
+ Metadata-Version: 2.4
2
+ Name: toolanything
3
+ Version: 0.1.0
4
+ Summary: One function to MCP and Tool calling
5
+ Author: ToolAnything
6
+ License-Expression: MIT
7
+ Keywords: mcp,tool-calling,openai,fastapi
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: tenacity>=8.2.0
20
+ Requires-Dist: fastapi>=0.110.0
21
+ Requires-Dist: uvicorn>=0.27.0
22
+ Requires-Dist: opencv-python>=4.12.0.88
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
26
+ Provides-Extra: docs
27
+ Requires-Dist: mkdocs>=1.6.0; extra == "docs"
28
+ Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
29
+ Requires-Dist: mkdocstrings[python]>=0.28.0; extra == "docs"
30
+ Dynamic: license-file
31
+
32
+ # ToolAnything
33
+
34
+ > 一次定義工具,同時接上 MCP 與 OpenAI tool calling。
35
+
36
+ ToolAnything 是一個給 LLM 應用開發者的 Python 工具層。它把最容易失控的整合工作收斂成一套:工具定義、schema 生成、名稱映射、執行 runtime、MCP transport,以及本機診斷與驗證流程。
37
+
38
+ 如果你正在做 agent、assistant、copilot 或內部 AI 平台,通常真正拖慢進度的不是模型 API 本身,而是這些重複工作:
39
+
40
+ - 同一個 tool 要維護兩套 schema
41
+ - Python function、HTTP API、SQL、model inference 都要各自包 wrapper
42
+ - tool 可以宣告,但不容易用真實 MCP host 或 OpenAI loop 驗證
43
+ - transport、debug、Claude Desktop 設定與 smoke test 都變成額外成本
44
+
45
+ ToolAnything 的目標不是再做一個全能 agent framework,而是把這一層 integration glue code 拿掉,讓你把心力放回工具契約、產品邏輯與模型行為。
46
+
47
+ ## 為什麼 LLM 開發者會想用它
48
+
49
+ ### 1. 一次定義,同時接 MCP 與 OpenAI
50
+
51
+ 你可以用一份工具定義,同時得到:
52
+
53
+ - MCP tool schema
54
+ - OpenAI tool schema
55
+ - OpenAI-safe tool name mapping
56
+ - 一套共用的工具執行 runtime
57
+
58
+ 這可以直接減少雙協議整合時最常見的 schema drift 問題。
59
+
60
+ ### 2. 不只包 Python function,也能直接包外部來源
61
+
62
+ ToolAnything 不把「tool = Python function」當成唯一前提。除了 `@tool`,也支援把這些來源直接註冊成正式工具:
63
+
64
+ - HTTP API
65
+ - SQL query
66
+ - PyTorch inference
67
+ - ONNX inference
68
+
69
+ 這對已經有既有服務、資料庫查詢或模型資產的團隊特別有價值,因為你不必先手寫一層低價值 wrapper 才能把它接進 LLM toolchain。
70
+
71
+ ### 3. 不只輸出 schema,還能真的跑起來
72
+
73
+ 這個 repo 的定位不是 schema helper。它同時提供:
74
+
75
+ - `toolanything serve`:啟動 MCP server
76
+ - `toolanything doctor`:檢查 initialize、`tools/list`、`tools/call`
77
+ - `toolanything inspect`:用內建 Web inspector 直接測工具與 MCP transcript
78
+ - `OpenAIChatRuntime`:直接跑 OpenAI tool loop
79
+
80
+ 也就是說,你不只可以「宣告工具」,還能用同一套工具做本機驗證、host 整合與 OpenAI roundtrip 測試。
81
+
82
+ ### 4. 有意識地把責任切乾淨
83
+
84
+ ToolAnything 幫你處理的是 integration 與 protocol plumbing,不是替你決定 agent orchestration。
85
+
86
+ 它很適合拿來做:
87
+
88
+ - AI 產品的工具層
89
+ - MCP server
90
+ - 雙協議工具輸出層
91
+ - 可重用的 tool runtime
92
+
93
+ 它不打算直接取代:
94
+
95
+ - workflow / memory / planning framework
96
+ - 完整 agent platform
97
+ - 產品 UI
98
+
99
+ 這個邊界反而是優勢,因為你比較不會被迫接受一整套過重的抽象。
100
+
101
+ ## 你實際省掉的是什麼
102
+
103
+ 沒有 ToolAnything 時,常見流程通常長這樣:
104
+
105
+ 1. 定義 Python function 或外部 API wrapper
106
+ 2. 產生 OpenAI tools schema
107
+ 3. 產生 MCP tools schema
108
+ 4. 處理 tool name mapping 與合法化
109
+ 5. 寫一套 tool execution loop
110
+ 6. 補 `stdio` 或 HTTP transport
111
+ 7. 再補 diagnosis、inspect、Claude Desktop 設定與 smoke test
112
+
113
+ 用 ToolAnything 時,這些工作會被收斂進同一套 API、runtime 與 CLI。
114
+
115
+ ## 這個專案最適合誰
116
+
117
+ 適合:
118
+
119
+ - 想把既有 Python function 快速暴露成 MCP / OpenAI tools 的開發者
120
+ - 需要同時支援 MCP 與 OpenAI tool calling 的產品團隊
121
+ - 想把 REST API、SQL、model inference 轉成正式 tool source 的平台團隊
122
+ - 希望工具層本身就帶有 CLI、diagnostics 與 examples 的開發者
123
+
124
+ 不適合:
125
+
126
+ - 你只需要一次性的 schema 匯出
127
+ - 你要的是完整 agent orchestration / workflow / memory 平台
128
+ - 你不打算碰 Python runtime,只想找純前端或純 SaaS 型方案
129
+
130
+ ## 60 秒看懂核心體驗
131
+
132
+ ### Step 1: 定義一個 tool
133
+
134
+ ```python
135
+ from toolanything import tool
136
+
137
+
138
+ @tool(name="calculator.add", description="加總兩個整數")
139
+ def add(a: int, b: int) -> int:
140
+ return a + b
141
+ ```
142
+
143
+ ### Step 2: 啟動成 MCP server
144
+
145
+ ```bash
146
+ toolanything serve tools.py --stdio
147
+ ```
148
+
149
+ ### Step 3: 驗證它真的可呼叫
150
+
151
+ ```bash
152
+ toolanything doctor --mode stdio --tools tools
153
+ ```
154
+
155
+ 做到這裡時,你已經不是只有一個 Python function,而是一個可以被 MCP host 發現與呼叫的工具服務,包含:
156
+
157
+ - `tools/list`
158
+ - `tools/call`
159
+ - input schema 生成
160
+ - 回傳值序列化
161
+ - stdio transport
162
+
163
+ ## 安裝
164
+
165
+ 目前建議直接從 repo 安裝:
166
+
167
+ ```bash
168
+ git clone <this-repo>
169
+ cd ToolAnything
170
+ pip install -e .
171
+ ```
172
+
173
+ 如果你要跑測試或開發工具:
174
+
175
+ ```bash
176
+ pip install -e .[dev]
177
+ ```
178
+
179
+ 需求:
180
+
181
+ - Python `>=3.10`
182
+
183
+ ## 快速開始
184
+
185
+ ### 1. 用 decorator 定義工具
186
+
187
+ ```python
188
+ from toolanything import tool
189
+
190
+
191
+ @tool(name="weather.query", description="取得城市天氣")
192
+ def get_weather(city: str, unit: str = "c") -> dict:
193
+ return {"city": city, "unit": unit, "temp": 25}
194
+ ```
195
+
196
+ ### 2. 啟動 MCP server
197
+
198
+ ```bash
199
+ toolanything serve examples/quickstart/tools.py --stdio
200
+ ```
201
+
202
+ 如果你要測 HTTP transport:
203
+
204
+ ```bash
205
+ toolanything serve examples/quickstart/tools.py --streamable-http --host 127.0.0.1 --port 9092
206
+ ```
207
+
208
+ ### 3. 檢查 transport 與 tool call
209
+
210
+ ```bash
211
+ toolanything doctor --mode stdio --tools examples.quickstart.tools
212
+ ```
213
+
214
+ 或檢查 HTTP server:
215
+
216
+ ```bash
217
+ toolanything doctor --mode http --url http://127.0.0.1:9092
218
+ ```
219
+
220
+ ### 4. 開 inspector 做互動式驗證
221
+
222
+ ```bash
223
+ toolanything inspect
224
+ ```
225
+
226
+ 它適合拿來:
227
+
228
+ - 看工具 schema
229
+ - 手動送 `tools/call`
230
+ - 檢查 MCP transcript
231
+ - 做 OpenAI tool-calling smoke test
232
+
233
+ ## 直接跑 OpenAI tool loop
234
+
235
+ 如果你不只想匯出 tool schema,也想直接讓模型透過工具回答:
236
+
237
+ ```python
238
+ from toolanything import OpenAIChatRuntime
239
+
240
+ runtime = OpenAIChatRuntime()
241
+ result = runtime.run(
242
+ model="gpt-4.1-mini",
243
+ prompt="請使用 weather.query 回答問題。",
244
+ )
245
+
246
+ print(result["final_text"])
247
+ ```
248
+
249
+ ## 不只 function,也支援 source-based tools
250
+
251
+ 如果你的工具不是 Python function,而是既有服務或資產,可以直接走 source-based API。
252
+
253
+ 支援範圍:
254
+
255
+ - HTTP source
256
+ - SQL source
257
+ - Model source
258
+
259
+ 相關範例:
260
+
261
+ - [examples/non_function_tools/http_tool.py](examples/non_function_tools/http_tool.py)
262
+ - [examples/non_function_tools/sql_tool.py](examples/non_function_tools/sql_tool.py)
263
+ - [examples/non_function_tools/onnx_tool.py](examples/non_function_tools/onnx_tool.py)
264
+ - [examples/non_function_tools/pytorch_tool.py](examples/non_function_tools/pytorch_tool.py)
265
+
266
+ 如果你是從既有 callable-first 寫法遷移過來,舊用法仍可繼續使用;新功能則建議優先採用 source-based API。詳見 [docs/migration-guide.md](docs/migration-guide.md)。
267
+
268
+ ## 核心能力一覽
269
+
270
+ | 能力 | 對開發者的價值 |
271
+ | --- | --- |
272
+ | 一份工具同時支援 MCP 與 OpenAI | 降低雙協議維護成本,避免 schema 漂移 |
273
+ | `@tool` 與 source-based API 並存 | 先用簡單方式上手,再逐步接 HTTP / SQL / model |
274
+ | `OpenAIChatRuntime` | 不只輸出 schema,還能直接跑 tool loop |
275
+ | `stdio`、Streamable HTTP、legacy SSE/HTTP | 可以依 host 與部署情境切換 transport |
276
+ | `doctor`、`inspect`、Claude Desktop integration | 導入與除錯成本更低 |
277
+ | tool metadata 與 search strategy | 工具數量變多後仍可做篩選、排序與策略化選擇 |
278
+
279
+ ## MCP transport 支援
280
+
281
+ | Transport | 典型場景 |
282
+ | --- | --- |
283
+ | `stdio` | Claude Desktop、IDE、本機 agent host |
284
+ | Streamable HTTP | 新版 MCP HTTP 整合,適合服務間連線 |
285
+ | legacy SSE / HTTP | 相容舊 client |
286
+
287
+ 如果你要做新的 MCP 網路整合,建議優先用 Streamable HTTP。
288
+
289
+ ## 專案導覽
290
+
291
+ 如果你第一次進 repo,建議照這個順序閱讀:
292
+
293
+ | 想解決的問題 | 先看哪裡 |
294
+ | --- | --- |
295
+ | 我要先跑通最小可用流程 | [examples/quickstart/README.md](examples/quickstart/README.md) |
296
+ | 我要理解不同 transport 差異 | [examples/mcp_transports/README.md](examples/mcp_transports/README.md) |
297
+ | 我要做新版 MCP HTTP 整合 | [examples/streamable_http/README.md](examples/streamable_http/README.md) |
298
+ | 我要把 HTTP / SQL / model 變成 tool | [examples/non_function_tools/README.md](examples/non_function_tools/README.md) |
299
+ | 我要做工具搜尋與選擇策略 | [examples/tool_selection/README.md](examples/tool_selection/README.md) |
300
+ | 我要理解架構與擴充點 | [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md) |
301
+ | 我要評估遷移成本 | [docs/migration-guide.md](docs/migration-guide.md) |
302
+
303
+ ## Claude Desktop 整合
304
+
305
+ 產生設定片段:
306
+
307
+ ```bash
308
+ toolanything init-claude --module examples/opencv_mcp_web/server.py --port 9090
309
+ ```
310
+
311
+ 直接寫入設定檔:
312
+
313
+ ```bash
314
+ toolanything install-claude --module examples/opencv_mcp_web/server.py --port 9090
315
+ ```
316
+
317
+ ## 架構定位
318
+
319
+ 可以把 ToolAnything 想成四層:
320
+
321
+ 1. Tool definition layer
322
+ 2. Runtime layer
323
+ 3. Transport layer
324
+ 4. Developer tooling layer
325
+
326
+ 這個分層的意義是:你寫的是工具與工具契約,不是一次又一次地重寫 protocol 與 integration plumbing。
327
+
328
+ 如果你在意長期維護與擴充點,請直接看 [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md)。
329
+
330
+ ## 專案狀態
331
+
332
+ - 目前版本:`0.1.0`
333
+ - Python requirement:`>=3.10`
334
+ - 開發狀態:Alpha
335
+
336
+ 目前已具備:
337
+
338
+ - callable-first 與 source-based 兩條工具定義路徑
339
+ - MCP `stdio`、Streamable HTTP、legacy SSE/HTTP
340
+ - OpenAI tool schema adapter 與 tool loop runtime
341
+ - `doctor`、`inspect`、Claude Desktop integration
342
+ - examples、migration 文件與測試
343
+
344
+ 這代表它已經適合拿來做原型、內部平台整合與架構驗證;若你要導入正式產品,建議先從自己的真實工具與 host 組合做一輪 smoke test。
345
+
346
+ ## 文件索引
347
+
348
+ - [docs/docs-map.md](docs/docs-map.md)
349
+ - [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md)
350
+ - [docs/migration-guide.md](docs/migration-guide.md)
351
+ - [docs/mcp-test-client-spec.md](docs/mcp-test-client-spec.md)
352
+
353
+ ## License
354
+
355
+ MIT
@@ -0,0 +1,324 @@
1
+ # ToolAnything
2
+
3
+ > 一次定義工具,同時接上 MCP 與 OpenAI tool calling。
4
+
5
+ ToolAnything 是一個給 LLM 應用開發者的 Python 工具層。它把最容易失控的整合工作收斂成一套:工具定義、schema 生成、名稱映射、執行 runtime、MCP transport,以及本機診斷與驗證流程。
6
+
7
+ 如果你正在做 agent、assistant、copilot 或內部 AI 平台,通常真正拖慢進度的不是模型 API 本身,而是這些重複工作:
8
+
9
+ - 同一個 tool 要維護兩套 schema
10
+ - Python function、HTTP API、SQL、model inference 都要各自包 wrapper
11
+ - tool 可以宣告,但不容易用真實 MCP host 或 OpenAI loop 驗證
12
+ - transport、debug、Claude Desktop 設定與 smoke test 都變成額外成本
13
+
14
+ ToolAnything 的目標不是再做一個全能 agent framework,而是把這一層 integration glue code 拿掉,讓你把心力放回工具契約、產品邏輯與模型行為。
15
+
16
+ ## 為什麼 LLM 開發者會想用它
17
+
18
+ ### 1. 一次定義,同時接 MCP 與 OpenAI
19
+
20
+ 你可以用一份工具定義,同時得到:
21
+
22
+ - MCP tool schema
23
+ - OpenAI tool schema
24
+ - OpenAI-safe tool name mapping
25
+ - 一套共用的工具執行 runtime
26
+
27
+ 這可以直接減少雙協議整合時最常見的 schema drift 問題。
28
+
29
+ ### 2. 不只包 Python function,也能直接包外部來源
30
+
31
+ ToolAnything 不把「tool = Python function」當成唯一前提。除了 `@tool`,也支援把這些來源直接註冊成正式工具:
32
+
33
+ - HTTP API
34
+ - SQL query
35
+ - PyTorch inference
36
+ - ONNX inference
37
+
38
+ 這對已經有既有服務、資料庫查詢或模型資產的團隊特別有價值,因為你不必先手寫一層低價值 wrapper 才能把它接進 LLM toolchain。
39
+
40
+ ### 3. 不只輸出 schema,還能真的跑起來
41
+
42
+ 這個 repo 的定位不是 schema helper。它同時提供:
43
+
44
+ - `toolanything serve`:啟動 MCP server
45
+ - `toolanything doctor`:檢查 initialize、`tools/list`、`tools/call`
46
+ - `toolanything inspect`:用內建 Web inspector 直接測工具與 MCP transcript
47
+ - `OpenAIChatRuntime`:直接跑 OpenAI tool loop
48
+
49
+ 也就是說,你不只可以「宣告工具」,還能用同一套工具做本機驗證、host 整合與 OpenAI roundtrip 測試。
50
+
51
+ ### 4. 有意識地把責任切乾淨
52
+
53
+ ToolAnything 幫你處理的是 integration 與 protocol plumbing,不是替你決定 agent orchestration。
54
+
55
+ 它很適合拿來做:
56
+
57
+ - AI 產品的工具層
58
+ - MCP server
59
+ - 雙協議工具輸出層
60
+ - 可重用的 tool runtime
61
+
62
+ 它不打算直接取代:
63
+
64
+ - workflow / memory / planning framework
65
+ - 完整 agent platform
66
+ - 產品 UI
67
+
68
+ 這個邊界反而是優勢,因為你比較不會被迫接受一整套過重的抽象。
69
+
70
+ ## 你實際省掉的是什麼
71
+
72
+ 沒有 ToolAnything 時,常見流程通常長這樣:
73
+
74
+ 1. 定義 Python function 或外部 API wrapper
75
+ 2. 產生 OpenAI tools schema
76
+ 3. 產生 MCP tools schema
77
+ 4. 處理 tool name mapping 與合法化
78
+ 5. 寫一套 tool execution loop
79
+ 6. 補 `stdio` 或 HTTP transport
80
+ 7. 再補 diagnosis、inspect、Claude Desktop 設定與 smoke test
81
+
82
+ 用 ToolAnything 時,這些工作會被收斂進同一套 API、runtime 與 CLI。
83
+
84
+ ## 這個專案最適合誰
85
+
86
+ 適合:
87
+
88
+ - 想把既有 Python function 快速暴露成 MCP / OpenAI tools 的開發者
89
+ - 需要同時支援 MCP 與 OpenAI tool calling 的產品團隊
90
+ - 想把 REST API、SQL、model inference 轉成正式 tool source 的平台團隊
91
+ - 希望工具層本身就帶有 CLI、diagnostics 與 examples 的開發者
92
+
93
+ 不適合:
94
+
95
+ - 你只需要一次性的 schema 匯出
96
+ - 你要的是完整 agent orchestration / workflow / memory 平台
97
+ - 你不打算碰 Python runtime,只想找純前端或純 SaaS 型方案
98
+
99
+ ## 60 秒看懂核心體驗
100
+
101
+ ### Step 1: 定義一個 tool
102
+
103
+ ```python
104
+ from toolanything import tool
105
+
106
+
107
+ @tool(name="calculator.add", description="加總兩個整數")
108
+ def add(a: int, b: int) -> int:
109
+ return a + b
110
+ ```
111
+
112
+ ### Step 2: 啟動成 MCP server
113
+
114
+ ```bash
115
+ toolanything serve tools.py --stdio
116
+ ```
117
+
118
+ ### Step 3: 驗證它真的可呼叫
119
+
120
+ ```bash
121
+ toolanything doctor --mode stdio --tools tools
122
+ ```
123
+
124
+ 做到這裡時,你已經不是只有一個 Python function,而是一個可以被 MCP host 發現與呼叫的工具服務,包含:
125
+
126
+ - `tools/list`
127
+ - `tools/call`
128
+ - input schema 生成
129
+ - 回傳值序列化
130
+ - stdio transport
131
+
132
+ ## 安裝
133
+
134
+ 目前建議直接從 repo 安裝:
135
+
136
+ ```bash
137
+ git clone <this-repo>
138
+ cd ToolAnything
139
+ pip install -e .
140
+ ```
141
+
142
+ 如果你要跑測試或開發工具:
143
+
144
+ ```bash
145
+ pip install -e .[dev]
146
+ ```
147
+
148
+ 需求:
149
+
150
+ - Python `>=3.10`
151
+
152
+ ## 快速開始
153
+
154
+ ### 1. 用 decorator 定義工具
155
+
156
+ ```python
157
+ from toolanything import tool
158
+
159
+
160
+ @tool(name="weather.query", description="取得城市天氣")
161
+ def get_weather(city: str, unit: str = "c") -> dict:
162
+ return {"city": city, "unit": unit, "temp": 25}
163
+ ```
164
+
165
+ ### 2. 啟動 MCP server
166
+
167
+ ```bash
168
+ toolanything serve examples/quickstart/tools.py --stdio
169
+ ```
170
+
171
+ 如果你要測 HTTP transport:
172
+
173
+ ```bash
174
+ toolanything serve examples/quickstart/tools.py --streamable-http --host 127.0.0.1 --port 9092
175
+ ```
176
+
177
+ ### 3. 檢查 transport 與 tool call
178
+
179
+ ```bash
180
+ toolanything doctor --mode stdio --tools examples.quickstart.tools
181
+ ```
182
+
183
+ 或檢查 HTTP server:
184
+
185
+ ```bash
186
+ toolanything doctor --mode http --url http://127.0.0.1:9092
187
+ ```
188
+
189
+ ### 4. 開 inspector 做互動式驗證
190
+
191
+ ```bash
192
+ toolanything inspect
193
+ ```
194
+
195
+ 它適合拿來:
196
+
197
+ - 看工具 schema
198
+ - 手動送 `tools/call`
199
+ - 檢查 MCP transcript
200
+ - 做 OpenAI tool-calling smoke test
201
+
202
+ ## 直接跑 OpenAI tool loop
203
+
204
+ 如果你不只想匯出 tool schema,也想直接讓模型透過工具回答:
205
+
206
+ ```python
207
+ from toolanything import OpenAIChatRuntime
208
+
209
+ runtime = OpenAIChatRuntime()
210
+ result = runtime.run(
211
+ model="gpt-4.1-mini",
212
+ prompt="請使用 weather.query 回答問題。",
213
+ )
214
+
215
+ print(result["final_text"])
216
+ ```
217
+
218
+ ## 不只 function,也支援 source-based tools
219
+
220
+ 如果你的工具不是 Python function,而是既有服務或資產,可以直接走 source-based API。
221
+
222
+ 支援範圍:
223
+
224
+ - HTTP source
225
+ - SQL source
226
+ - Model source
227
+
228
+ 相關範例:
229
+
230
+ - [examples/non_function_tools/http_tool.py](examples/non_function_tools/http_tool.py)
231
+ - [examples/non_function_tools/sql_tool.py](examples/non_function_tools/sql_tool.py)
232
+ - [examples/non_function_tools/onnx_tool.py](examples/non_function_tools/onnx_tool.py)
233
+ - [examples/non_function_tools/pytorch_tool.py](examples/non_function_tools/pytorch_tool.py)
234
+
235
+ 如果你是從既有 callable-first 寫法遷移過來,舊用法仍可繼續使用;新功能則建議優先採用 source-based API。詳見 [docs/migration-guide.md](docs/migration-guide.md)。
236
+
237
+ ## 核心能力一覽
238
+
239
+ | 能力 | 對開發者的價值 |
240
+ | --- | --- |
241
+ | 一份工具同時支援 MCP 與 OpenAI | 降低雙協議維護成本,避免 schema 漂移 |
242
+ | `@tool` 與 source-based API 並存 | 先用簡單方式上手,再逐步接 HTTP / SQL / model |
243
+ | `OpenAIChatRuntime` | 不只輸出 schema,還能直接跑 tool loop |
244
+ | `stdio`、Streamable HTTP、legacy SSE/HTTP | 可以依 host 與部署情境切換 transport |
245
+ | `doctor`、`inspect`、Claude Desktop integration | 導入與除錯成本更低 |
246
+ | tool metadata 與 search strategy | 工具數量變多後仍可做篩選、排序與策略化選擇 |
247
+
248
+ ## MCP transport 支援
249
+
250
+ | Transport | 典型場景 |
251
+ | --- | --- |
252
+ | `stdio` | Claude Desktop、IDE、本機 agent host |
253
+ | Streamable HTTP | 新版 MCP HTTP 整合,適合服務間連線 |
254
+ | legacy SSE / HTTP | 相容舊 client |
255
+
256
+ 如果你要做新的 MCP 網路整合,建議優先用 Streamable HTTP。
257
+
258
+ ## 專案導覽
259
+
260
+ 如果你第一次進 repo,建議照這個順序閱讀:
261
+
262
+ | 想解決的問題 | 先看哪裡 |
263
+ | --- | --- |
264
+ | 我要先跑通最小可用流程 | [examples/quickstart/README.md](examples/quickstart/README.md) |
265
+ | 我要理解不同 transport 差異 | [examples/mcp_transports/README.md](examples/mcp_transports/README.md) |
266
+ | 我要做新版 MCP HTTP 整合 | [examples/streamable_http/README.md](examples/streamable_http/README.md) |
267
+ | 我要把 HTTP / SQL / model 變成 tool | [examples/non_function_tools/README.md](examples/non_function_tools/README.md) |
268
+ | 我要做工具搜尋與選擇策略 | [examples/tool_selection/README.md](examples/tool_selection/README.md) |
269
+ | 我要理解架構與擴充點 | [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md) |
270
+ | 我要評估遷移成本 | [docs/migration-guide.md](docs/migration-guide.md) |
271
+
272
+ ## Claude Desktop 整合
273
+
274
+ 產生設定片段:
275
+
276
+ ```bash
277
+ toolanything init-claude --module examples/opencv_mcp_web/server.py --port 9090
278
+ ```
279
+
280
+ 直接寫入設定檔:
281
+
282
+ ```bash
283
+ toolanything install-claude --module examples/opencv_mcp_web/server.py --port 9090
284
+ ```
285
+
286
+ ## 架構定位
287
+
288
+ 可以把 ToolAnything 想成四層:
289
+
290
+ 1. Tool definition layer
291
+ 2. Runtime layer
292
+ 3. Transport layer
293
+ 4. Developer tooling layer
294
+
295
+ 這個分層的意義是:你寫的是工具與工具契約,不是一次又一次地重寫 protocol 與 integration plumbing。
296
+
297
+ 如果你在意長期維護與擴充點,請直接看 [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md)。
298
+
299
+ ## 專案狀態
300
+
301
+ - 目前版本:`0.1.0`
302
+ - Python requirement:`>=3.10`
303
+ - 開發狀態:Alpha
304
+
305
+ 目前已具備:
306
+
307
+ - callable-first 與 source-based 兩條工具定義路徑
308
+ - MCP `stdio`、Streamable HTTP、legacy SSE/HTTP
309
+ - OpenAI tool schema adapter 與 tool loop runtime
310
+ - `doctor`、`inspect`、Claude Desktop integration
311
+ - examples、migration 文件與測試
312
+
313
+ 這代表它已經適合拿來做原型、內部平台整合與架構驗證;若你要導入正式產品,建議先從自己的真實工具與 host 組合做一輪 smoke test。
314
+
315
+ ## 文件索引
316
+
317
+ - [docs/docs-map.md](docs/docs-map.md)
318
+ - [docs/architecture-walkthrough.md](docs/architecture-walkthrough.md)
319
+ - [docs/migration-guide.md](docs/migration-guide.md)
320
+ - [docs/mcp-test-client-spec.md](docs/mcp-test-client-spec.md)
321
+
322
+ ## License
323
+
324
+ MIT