turbomcp 0.2.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.
- turbomcp-0.2.0/LICENSE +21 -0
- turbomcp-0.2.0/PKG-INFO +227 -0
- turbomcp-0.2.0/README.md +194 -0
- turbomcp-0.2.0/pyproject.toml +43 -0
- turbomcp-0.2.0/setup.cfg +4 -0
- turbomcp-0.2.0/tests/test_core.py +145 -0
- turbomcp-0.2.0/tests/test_mcp_stdio.py +121 -0
- turbomcp-0.2.0/turbomcp/__init__.py +7 -0
- turbomcp-0.2.0/turbomcp/__main__.py +173 -0
- turbomcp-0.2.0/turbomcp/core.py +561 -0
- turbomcp-0.2.0/turbomcp/default_tools.py +259 -0
- turbomcp-0.2.0/turbomcp/http_api.py +94 -0
- turbomcp-0.2.0/turbomcp/mcp_stdio.py +196 -0
- turbomcp-0.2.0/turbomcp.egg-info/PKG-INFO +227 -0
- turbomcp-0.2.0/turbomcp.egg-info/SOURCES.txt +17 -0
- turbomcp-0.2.0/turbomcp.egg-info/dependency_links.txt +1 -0
- turbomcp-0.2.0/turbomcp.egg-info/entry_points.txt +2 -0
- turbomcp-0.2.0/turbomcp.egg-info/requires.txt +22 -0
- turbomcp-0.2.0/turbomcp.egg-info/top_level.txt +1 -0
turbomcp-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 walker-null-byte
|
|
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.
|
turbomcp-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: turbomcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Zero-dependency tool registry and MCP server for LLM agents, with built-in tool search.
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: mcp,llm,agents,tools,tool-calling,model-context-protocol
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Provides-Extra: http
|
|
15
|
+
Requires-Dist: flask; extra == "http"
|
|
16
|
+
Provides-Extra: web
|
|
17
|
+
Requires-Dist: requests; extra == "web"
|
|
18
|
+
Requires-Dist: beautifulsoup4; extra == "web"
|
|
19
|
+
Requires-Dist: ddgs; extra == "web"
|
|
20
|
+
Requires-Dist: googlesearch-python; extra == "web"
|
|
21
|
+
Provides-Extra: semantic
|
|
22
|
+
Requires-Dist: model2vec; extra == "semantic"
|
|
23
|
+
Requires-Dist: numpy; extra == "semantic"
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: flask; extra == "all"
|
|
26
|
+
Requires-Dist: requests; extra == "all"
|
|
27
|
+
Requires-Dist: beautifulsoup4; extra == "all"
|
|
28
|
+
Requires-Dist: ddgs; extra == "all"
|
|
29
|
+
Requires-Dist: googlesearch-python; extra == "all"
|
|
30
|
+
Requires-Dist: model2vec; extra == "all"
|
|
31
|
+
Requires-Dist: numpy; extra == "all"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# turbomcp
|
|
35
|
+
|
|
36
|
+
**A zero-dependency tool registry and MCP server for LLM agents — with built-in tool search so agents don't drown in schemas.**
|
|
37
|
+
|
|
38
|
+
Write plain Python functions. Get JSON Schema, OpenAI function-calling definitions, a real [MCP](https://modelcontextprotocol.io) server, and ranked tool search — without installing anything else.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from turbomcp import ContextAware
|
|
42
|
+
|
|
43
|
+
mcp = ContextAware()
|
|
44
|
+
|
|
45
|
+
@mcp.tool()
|
|
46
|
+
def greet(name: str = "World"):
|
|
47
|
+
"""Greet a user by name.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
name (str): Who to greet
|
|
51
|
+
"""
|
|
52
|
+
return f"Hello, {name}!"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
That's a working tool. Schemas are generated from the signature and docstring — types from annotations, descriptions from the `Args:` section, required/optional from defaults.
|
|
56
|
+
|
|
57
|
+
## Why turbomcp?
|
|
58
|
+
|
|
59
|
+
Most tool servers dump every tool schema into the model's context on every request. That's fine for 5 tools and a disaster for 50. turbomcp is built around **progressive disclosure** — an agent can work its way down this ladder and only pay for what it needs:
|
|
60
|
+
|
|
61
|
+
| Call | Returns | Context cost |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `mcp.list_tools()` | just the names | tiny |
|
|
64
|
+
| `mcp.list_tools(with_summary=True)` | names + one-liners | small |
|
|
65
|
+
| `mcp.search_tools("fetch a webpage")` | ranked matches, full schemas | only what's relevant |
|
|
66
|
+
| `mcp.get_capabilities(name="read_file")` | one full schema on demand | one tool |
|
|
67
|
+
|
|
68
|
+
Search is keyword-based out of the box (name/description/parameter matching with field weighting), and optionally **semantic** via static embeddings — no GPU, ~1s startup, instant queries.
|
|
69
|
+
|
|
70
|
+
## Install
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install turbomcp # core: registry + MCP server, zero dependencies
|
|
74
|
+
pip install turbomcp[web] # + built-in web tools (search, scrape)
|
|
75
|
+
pip install turbomcp[semantic] # + semantic tool search (model2vec)
|
|
76
|
+
pip install turbomcp[http] # + Flask REST API for debugging
|
|
77
|
+
pip install turbomcp[all] # everything
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Use it as an MCP server
|
|
81
|
+
|
|
82
|
+
Any MCP client (Claude Code, Claude Desktop, ...) can launch your registry directly:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
turbomcp serve my_tools.py # finds the ContextAware instance in the file
|
|
86
|
+
turbomcp serve my_tools.py:mcp # or name the variable explicitly
|
|
87
|
+
turbomcp demo # try it with the built-in default tools
|
|
88
|
+
turbomcp init [my_tools.py] # create a starter template
|
|
89
|
+
turbomcp init my_tools.py --with-web --with-semantic # include optional features
|
|
90
|
+
turbomcp help # show all commands
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Claude Code:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
claude mcp add my-tools -- turbomcp serve /path/to/my_tools.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Claude Desktop (`claude_desktop_config.json`):
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"mcpServers": {
|
|
104
|
+
"my-tools": {
|
|
105
|
+
"command": "turbomcp",
|
|
106
|
+
"args": ["serve", "/path/to/my_tools.py"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The server implements MCP over stdio natively (JSON-RPC 2.0): `initialize`, `ping`, `tools/list`, `tools/call`, and it emits `notifications/tools/list_changed` when tools are registered or removed **at runtime** — register a new tool while the server is live and connected clients find out immediately.
|
|
113
|
+
|
|
114
|
+
> One rule when serving stdio: don't `print()` to stdout in your tool file — it corrupts the protocol stream. Use `sys.stderr`.
|
|
115
|
+
|
|
116
|
+
### Lazy mode: tool search over MCP
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
turbomcp serve my_tools.py --lazy
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
In lazy mode the client doesn't see your catalog at all. It sees three meta-tools — `search_tools`, `get_tool`, `call_tool` — and discovers what it needs by searching. A 100-tool registry costs the model three schemas instead of a hundred.
|
|
123
|
+
|
|
124
|
+
## Use it with OpenAI-compatible APIs
|
|
125
|
+
|
|
126
|
+
The same registry plugs straight into any chat-completions API (OpenAI, Gemini's OpenAI endpoint, Ollama, llama.cpp, vLLM, ...):
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from openai import OpenAI
|
|
130
|
+
|
|
131
|
+
client = OpenAI(base_url="http://localhost:11434/v1", api_key="unused")
|
|
132
|
+
|
|
133
|
+
response = client.chat.completions.create(
|
|
134
|
+
model="your-model",
|
|
135
|
+
messages=[{"role": "user", "content": "Greet Ada"}],
|
|
136
|
+
tools=mcp.to_openai_tools(), # <- emitted in OpenAI format
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
for call in response.choices[0].message.tool_calls or []:
|
|
140
|
+
import json
|
|
141
|
+
result = mcp.call(call.function.name, json.loads(call.function.arguments))
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Also available: `mcp.to_mcp_tools()` (MCP format) and `mcp.get_tools_prompt()` (plain text for models without native tool calling).
|
|
145
|
+
|
|
146
|
+
## Tool search
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
mcp.search_tools("fetch a webpage", top_n=3)
|
|
150
|
+
# {"query": ..., "semantic": False, "tools": [{"name": "webpage_scrape", "score": ..., ...}]}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Enable semantic search to close the synonym gap ("say hello" → `greet`):
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
mcp.enable_semantic_search() # pip install turbomcp[semantic]
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Keyword and semantic scores are blended (tunable `alpha`); without the extra installed, search falls back to pure keyword scoring automatically.
|
|
160
|
+
|
|
161
|
+
## Built-in default tools
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
mcp.register_default(all=True) # everything
|
|
165
|
+
mcp.register_default(names=["calculate", "read_file"]) # or pick
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Tool | Needs `[web]` extra |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `internet_search` — DuckDuckGo (default) or Google, text or images | yes |
|
|
171
|
+
| `webpage_scrape` — fetch a page, strip boilerplate, return text | yes |
|
|
172
|
+
| `get_current_time` — local/IANA-timezone/UTC time | no |
|
|
173
|
+
| `read_file` — read a local text file | no |
|
|
174
|
+
| `calculate` — math expressions via a safe AST evaluator (no `eval`) | no |
|
|
175
|
+
| `get_system_info` — OS, arch, hostname, Python version | no |
|
|
176
|
+
|
|
177
|
+
## Writing good tools
|
|
178
|
+
|
|
179
|
+
Schemas are only as good as your signatures and docstrings:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from typing import Literal, Optional
|
|
183
|
+
|
|
184
|
+
@mcp.tool()
|
|
185
|
+
def convert(path: str, format: Literal["mp4", "webm", "gif"], quality: Optional[int] = None):
|
|
186
|
+
"""Convert a video file to another format.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
path (str): Path to the input file
|
|
190
|
+
format (str): Output format
|
|
191
|
+
quality (int): Output quality 1-100, default keeps source quality
|
|
192
|
+
"""
|
|
193
|
+
...
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- **Annotations → types**: `str`, `int`, `float`, `bool`, `list[str]`, `dict`, `Optional[X]`, `Literal[...]` (becomes an `enum`) all map to proper JSON Schema.
|
|
197
|
+
- **Defaults → optional**: parameters without defaults are `required`.
|
|
198
|
+
- **`Args:` section → descriptions**: Google-style docstrings, one line per parameter.
|
|
199
|
+
- The first docstring paragraph becomes the tool description — make it say *when* to use the tool, not just what it does.
|
|
200
|
+
|
|
201
|
+
## Optional HTTP API
|
|
202
|
+
|
|
203
|
+
For curl-debugging or non-MCP clients (`pip install turbomcp[http]`):
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
mcp.start_server(port=5000) # generates an API token, printed to stderr
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| Endpoint | Description |
|
|
210
|
+
|---|---|
|
|
211
|
+
| `GET /tools?summary=true` | names (+ summaries) |
|
|
212
|
+
| `GET /capabilities` | full catalog |
|
|
213
|
+
| `GET /tool/<name>` | one tool's schema |
|
|
214
|
+
| `GET /search?q=...` | ranked search |
|
|
215
|
+
| `POST /call_tool` | execute — `{"name": ..., "params": {...}}`, token via `X-API-Key` header or `api_key` field |
|
|
216
|
+
|
|
217
|
+
The server binds `127.0.0.1` and only `/call_tool` requires the token. It's a Flask dev server: fine on localhost, not meant for the open internet.
|
|
218
|
+
|
|
219
|
+
## Security notes
|
|
220
|
+
|
|
221
|
+
- Tools run with your user's permissions. A tool like "run shell command" gives the model exactly that power — register it knowingly.
|
|
222
|
+
- `calculate` uses an AST walker, not `eval` — sandbox-escape expressions like `(1).__class__...` are rejected.
|
|
223
|
+
- The HTTP token is generated per-process and printed to stderr; MCP stdio needs no token because the client launches the process itself.
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT
|
turbomcp-0.2.0/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# turbomcp
|
|
2
|
+
|
|
3
|
+
**A zero-dependency tool registry and MCP server for LLM agents — with built-in tool search so agents don't drown in schemas.**
|
|
4
|
+
|
|
5
|
+
Write plain Python functions. Get JSON Schema, OpenAI function-calling definitions, a real [MCP](https://modelcontextprotocol.io) server, and ranked tool search — without installing anything else.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from turbomcp import ContextAware
|
|
9
|
+
|
|
10
|
+
mcp = ContextAware()
|
|
11
|
+
|
|
12
|
+
@mcp.tool()
|
|
13
|
+
def greet(name: str = "World"):
|
|
14
|
+
"""Greet a user by name.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
name (str): Who to greet
|
|
18
|
+
"""
|
|
19
|
+
return f"Hello, {name}!"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
That's a working tool. Schemas are generated from the signature and docstring — types from annotations, descriptions from the `Args:` section, required/optional from defaults.
|
|
23
|
+
|
|
24
|
+
## Why turbomcp?
|
|
25
|
+
|
|
26
|
+
Most tool servers dump every tool schema into the model's context on every request. That's fine for 5 tools and a disaster for 50. turbomcp is built around **progressive disclosure** — an agent can work its way down this ladder and only pay for what it needs:
|
|
27
|
+
|
|
28
|
+
| Call | Returns | Context cost |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `mcp.list_tools()` | just the names | tiny |
|
|
31
|
+
| `mcp.list_tools(with_summary=True)` | names + one-liners | small |
|
|
32
|
+
| `mcp.search_tools("fetch a webpage")` | ranked matches, full schemas | only what's relevant |
|
|
33
|
+
| `mcp.get_capabilities(name="read_file")` | one full schema on demand | one tool |
|
|
34
|
+
|
|
35
|
+
Search is keyword-based out of the box (name/description/parameter matching with field weighting), and optionally **semantic** via static embeddings — no GPU, ~1s startup, instant queries.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install turbomcp # core: registry + MCP server, zero dependencies
|
|
41
|
+
pip install turbomcp[web] # + built-in web tools (search, scrape)
|
|
42
|
+
pip install turbomcp[semantic] # + semantic tool search (model2vec)
|
|
43
|
+
pip install turbomcp[http] # + Flask REST API for debugging
|
|
44
|
+
pip install turbomcp[all] # everything
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Use it as an MCP server
|
|
48
|
+
|
|
49
|
+
Any MCP client (Claude Code, Claude Desktop, ...) can launch your registry directly:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
turbomcp serve my_tools.py # finds the ContextAware instance in the file
|
|
53
|
+
turbomcp serve my_tools.py:mcp # or name the variable explicitly
|
|
54
|
+
turbomcp demo # try it with the built-in default tools
|
|
55
|
+
turbomcp init [my_tools.py] # create a starter template
|
|
56
|
+
turbomcp init my_tools.py --with-web --with-semantic # include optional features
|
|
57
|
+
turbomcp help # show all commands
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Claude Code:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
claude mcp add my-tools -- turbomcp serve /path/to/my_tools.py
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Claude Desktop (`claude_desktop_config.json`):
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"my-tools": {
|
|
72
|
+
"command": "turbomcp",
|
|
73
|
+
"args": ["serve", "/path/to/my_tools.py"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The server implements MCP over stdio natively (JSON-RPC 2.0): `initialize`, `ping`, `tools/list`, `tools/call`, and it emits `notifications/tools/list_changed` when tools are registered or removed **at runtime** — register a new tool while the server is live and connected clients find out immediately.
|
|
80
|
+
|
|
81
|
+
> One rule when serving stdio: don't `print()` to stdout in your tool file — it corrupts the protocol stream. Use `sys.stderr`.
|
|
82
|
+
|
|
83
|
+
### Lazy mode: tool search over MCP
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
turbomcp serve my_tools.py --lazy
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
In lazy mode the client doesn't see your catalog at all. It sees three meta-tools — `search_tools`, `get_tool`, `call_tool` — and discovers what it needs by searching. A 100-tool registry costs the model three schemas instead of a hundred.
|
|
90
|
+
|
|
91
|
+
## Use it with OpenAI-compatible APIs
|
|
92
|
+
|
|
93
|
+
The same registry plugs straight into any chat-completions API (OpenAI, Gemini's OpenAI endpoint, Ollama, llama.cpp, vLLM, ...):
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from openai import OpenAI
|
|
97
|
+
|
|
98
|
+
client = OpenAI(base_url="http://localhost:11434/v1", api_key="unused")
|
|
99
|
+
|
|
100
|
+
response = client.chat.completions.create(
|
|
101
|
+
model="your-model",
|
|
102
|
+
messages=[{"role": "user", "content": "Greet Ada"}],
|
|
103
|
+
tools=mcp.to_openai_tools(), # <- emitted in OpenAI format
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
for call in response.choices[0].message.tool_calls or []:
|
|
107
|
+
import json
|
|
108
|
+
result = mcp.call(call.function.name, json.loads(call.function.arguments))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Also available: `mcp.to_mcp_tools()` (MCP format) and `mcp.get_tools_prompt()` (plain text for models without native tool calling).
|
|
112
|
+
|
|
113
|
+
## Tool search
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
mcp.search_tools("fetch a webpage", top_n=3)
|
|
117
|
+
# {"query": ..., "semantic": False, "tools": [{"name": "webpage_scrape", "score": ..., ...}]}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Enable semantic search to close the synonym gap ("say hello" → `greet`):
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
mcp.enable_semantic_search() # pip install turbomcp[semantic]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Keyword and semantic scores are blended (tunable `alpha`); without the extra installed, search falls back to pure keyword scoring automatically.
|
|
127
|
+
|
|
128
|
+
## Built-in default tools
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
mcp.register_default(all=True) # everything
|
|
132
|
+
mcp.register_default(names=["calculate", "read_file"]) # or pick
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
| Tool | Needs `[web]` extra |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `internet_search` — DuckDuckGo (default) or Google, text or images | yes |
|
|
138
|
+
| `webpage_scrape` — fetch a page, strip boilerplate, return text | yes |
|
|
139
|
+
| `get_current_time` — local/IANA-timezone/UTC time | no |
|
|
140
|
+
| `read_file` — read a local text file | no |
|
|
141
|
+
| `calculate` — math expressions via a safe AST evaluator (no `eval`) | no |
|
|
142
|
+
| `get_system_info` — OS, arch, hostname, Python version | no |
|
|
143
|
+
|
|
144
|
+
## Writing good tools
|
|
145
|
+
|
|
146
|
+
Schemas are only as good as your signatures and docstrings:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from typing import Literal, Optional
|
|
150
|
+
|
|
151
|
+
@mcp.tool()
|
|
152
|
+
def convert(path: str, format: Literal["mp4", "webm", "gif"], quality: Optional[int] = None):
|
|
153
|
+
"""Convert a video file to another format.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
path (str): Path to the input file
|
|
157
|
+
format (str): Output format
|
|
158
|
+
quality (int): Output quality 1-100, default keeps source quality
|
|
159
|
+
"""
|
|
160
|
+
...
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
- **Annotations → types**: `str`, `int`, `float`, `bool`, `list[str]`, `dict`, `Optional[X]`, `Literal[...]` (becomes an `enum`) all map to proper JSON Schema.
|
|
164
|
+
- **Defaults → optional**: parameters without defaults are `required`.
|
|
165
|
+
- **`Args:` section → descriptions**: Google-style docstrings, one line per parameter.
|
|
166
|
+
- The first docstring paragraph becomes the tool description — make it say *when* to use the tool, not just what it does.
|
|
167
|
+
|
|
168
|
+
## Optional HTTP API
|
|
169
|
+
|
|
170
|
+
For curl-debugging or non-MCP clients (`pip install turbomcp[http]`):
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
mcp.start_server(port=5000) # generates an API token, printed to stderr
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
| Endpoint | Description |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `GET /tools?summary=true` | names (+ summaries) |
|
|
179
|
+
| `GET /capabilities` | full catalog |
|
|
180
|
+
| `GET /tool/<name>` | one tool's schema |
|
|
181
|
+
| `GET /search?q=...` | ranked search |
|
|
182
|
+
| `POST /call_tool` | execute — `{"name": ..., "params": {...}}`, token via `X-API-Key` header or `api_key` field |
|
|
183
|
+
|
|
184
|
+
The server binds `127.0.0.1` and only `/call_tool` requires the token. It's a Flask dev server: fine on localhost, not meant for the open internet.
|
|
185
|
+
|
|
186
|
+
## Security notes
|
|
187
|
+
|
|
188
|
+
- Tools run with your user's permissions. A tool like "run shell command" gives the model exactly that power — register it knowingly.
|
|
189
|
+
- `calculate` uses an AST walker, not `eval` — sandbox-escape expressions like `(1).__class__...` are rejected.
|
|
190
|
+
- The HTTP token is generated per-process and printed to stderr; MCP stdio needs no token because the client launches the process itself.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "turbomcp"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Zero-dependency tool registry and MCP server for LLM agents, with built-in tool search."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = ["mcp", "llm", "agents", "tools", "tool-calling", "model-context-protocol"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Topic :: Software Development :: Libraries",
|
|
18
|
+
]
|
|
19
|
+
# The core (registry + MCP stdio server) is stdlib-only on purpose.
|
|
20
|
+
dependencies = []
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
# Flask REST API (debugging / non-MCP clients)
|
|
24
|
+
http = ["flask"]
|
|
25
|
+
# Built-in web tools: internet_search, webpage_scrape
|
|
26
|
+
web = ["requests", "beautifulsoup4", "ddgs", "googlesearch-python"]
|
|
27
|
+
# Semantic tool search (static embeddings, no GPU)
|
|
28
|
+
semantic = ["model2vec", "numpy"]
|
|
29
|
+
all = [
|
|
30
|
+
"flask",
|
|
31
|
+
"requests",
|
|
32
|
+
"beautifulsoup4",
|
|
33
|
+
"ddgs",
|
|
34
|
+
"googlesearch-python",
|
|
35
|
+
"model2vec",
|
|
36
|
+
"numpy",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
turbomcp = "turbomcp.__main__:main"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
include = ["turbomcp*"]
|
turbomcp-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Core registry tests. Run directly: python tests/test_core.py"""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from typing import List, Optional
|
|
6
|
+
|
|
7
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
8
|
+
|
|
9
|
+
from turbomcp import ContextAware
|
|
10
|
+
from turbomcp.default_tools import calculate
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def make_registry():
|
|
14
|
+
reg = ContextAware(name="test")
|
|
15
|
+
|
|
16
|
+
@reg.tool()
|
|
17
|
+
def greet(name: str = "World"):
|
|
18
|
+
"""Greet a user by name.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
name (str): Who to greet
|
|
22
|
+
"""
|
|
23
|
+
return f"Hello, {name}!"
|
|
24
|
+
|
|
25
|
+
@reg.tool(description="Add two numbers together")
|
|
26
|
+
def add(a: int, b: int):
|
|
27
|
+
return a + b
|
|
28
|
+
|
|
29
|
+
@reg.tool()
|
|
30
|
+
def tag_items(items: List[str], label: Optional[str] = None, limit: int = 10):
|
|
31
|
+
"""Tag a list of items with a label.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
items (list): The items to tag
|
|
35
|
+
label (str): Optional label to apply
|
|
36
|
+
limit (int): Max items to process
|
|
37
|
+
"""
|
|
38
|
+
return [f"{label or 'tag'}:{i}" for i in items[:limit]]
|
|
39
|
+
|
|
40
|
+
return reg
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_schema_generation():
|
|
44
|
+
reg = make_registry()
|
|
45
|
+
schema = reg.tools["tag_items"]["input_schema"]
|
|
46
|
+
|
|
47
|
+
assert schema["type"] == "object"
|
|
48
|
+
assert schema["required"] == ["items"], schema
|
|
49
|
+
assert schema["properties"]["items"] == {
|
|
50
|
+
"type": "array", "items": {"type": "string"}, "description": "The items to tag",
|
|
51
|
+
}, schema["properties"]["items"]
|
|
52
|
+
# Optional[str] -> plain string type, not required, default captured
|
|
53
|
+
assert schema["properties"]["label"]["type"] == "string"
|
|
54
|
+
assert schema["properties"]["label"]["default"] is None
|
|
55
|
+
assert schema["properties"]["limit"] == {
|
|
56
|
+
"type": "integer", "default": 10, "description": "Max items to process",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
greet_schema = reg.tools["greet"]["input_schema"]
|
|
60
|
+
assert "required" not in greet_schema # all params have defaults
|
|
61
|
+
assert greet_schema["properties"]["name"]["description"] == "Who to greet"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_descriptions():
|
|
65
|
+
reg = make_registry()
|
|
66
|
+
assert reg.tools["greet"]["description"] == "Greet a user by name."
|
|
67
|
+
assert reg.tools["add"]["description"] == "Add two numbers together"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_emitters():
|
|
71
|
+
reg = make_registry()
|
|
72
|
+
|
|
73
|
+
openai_tools = reg.to_openai_tools()
|
|
74
|
+
assert all(t["type"] == "function" for t in openai_tools)
|
|
75
|
+
fn = next(t["function"] for t in openai_tools if t["function"]["name"] == "add")
|
|
76
|
+
assert fn["parameters"]["required"] == ["a", "b"]
|
|
77
|
+
assert fn["parameters"]["properties"]["a"] == {"type": "integer"}
|
|
78
|
+
|
|
79
|
+
mcp_tools = reg.to_mcp_tools()
|
|
80
|
+
entry = next(t for t in mcp_tools if t["name"] == "greet")
|
|
81
|
+
assert set(entry.keys()) == {"name", "description", "inputSchema"}
|
|
82
|
+
assert entry["inputSchema"]["type"] == "object"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_call_and_errors():
|
|
86
|
+
reg = make_registry()
|
|
87
|
+
assert reg.call("add", {"a": 2, "b": 3}) == 5
|
|
88
|
+
assert reg.call("greet") == "Hello, World!"
|
|
89
|
+
try:
|
|
90
|
+
reg.call("nope")
|
|
91
|
+
assert False, "expected ValueError"
|
|
92
|
+
except ValueError:
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_search():
|
|
97
|
+
reg = make_registry()
|
|
98
|
+
result = reg.search_tools("greet someone")
|
|
99
|
+
assert result["semantic"] is False
|
|
100
|
+
assert result["tools"][0]["name"] == "greet"
|
|
101
|
+
assert reg.search_tools("")["tools"] == []
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_change_notifications():
|
|
105
|
+
reg = make_registry()
|
|
106
|
+
events = []
|
|
107
|
+
reg.subscribe(lambda: events.append(1))
|
|
108
|
+
|
|
109
|
+
@reg.tool()
|
|
110
|
+
def extra():
|
|
111
|
+
"""Do nothing."""
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
reg.unregister("extra")
|
|
115
|
+
assert len(events) == 2
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_calculator_safe():
|
|
119
|
+
assert calculate("2 + 2 * 3")["result"] == 8
|
|
120
|
+
assert calculate("sqrt(16)")["result"] == 4.0
|
|
121
|
+
assert calculate("sum([1, 2, 3])")["result"] == 6
|
|
122
|
+
# The classic sandbox escapes must be rejected, not evaluated.
|
|
123
|
+
assert "error" in calculate("(1).__class__.__bases__[0].__subclasses__()")
|
|
124
|
+
assert "error" in calculate("__import__('os').system('id')")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_tools_prompt():
|
|
128
|
+
reg = make_registry()
|
|
129
|
+
prompt = reg.get_tools_prompt()
|
|
130
|
+
assert "## greet" in prompt
|
|
131
|
+
assert "[required]" in prompt
|
|
132
|
+
assert "optional" in prompt
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
if __name__ == "__main__":
|
|
136
|
+
failures = 0
|
|
137
|
+
for fn_name, fn in sorted(globals().items()):
|
|
138
|
+
if fn_name.startswith("test_") and callable(fn):
|
|
139
|
+
try:
|
|
140
|
+
fn()
|
|
141
|
+
print(f"PASS {fn_name}")
|
|
142
|
+
except AssertionError as e:
|
|
143
|
+
failures += 1
|
|
144
|
+
print(f"FAIL {fn_name}: {e}")
|
|
145
|
+
sys.exit(1 if failures else 0)
|