chuk-tool-processor 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
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.
Potentially problematic release.
This version of chuk-tool-processor might be problematic. Click here for more details.
- chuk_tool_processor/__init__.py +0 -1
- chuk_tool_processor/mcp/__init__.py +21 -0
- chuk_tool_processor/mcp/mcp_tool.py +53 -0
- chuk_tool_processor/mcp/register_mcp_tools.py +82 -0
- chuk_tool_processor/mcp/setup_mcp_sse.py +74 -0
- chuk_tool_processor/mcp/setup_mcp_stdio.py +78 -0
- chuk_tool_processor/mcp/stream_manager.py +293 -0
- chuk_tool_processor/mcp/transport/__init__.py +14 -0
- chuk_tool_processor/mcp/transport/base_transport.py +103 -0
- chuk_tool_processor/mcp/transport/sse_transport.py +189 -0
- chuk_tool_processor/mcp/transport/stdio_transport.py +197 -0
- {chuk_tool_processor-0.1.2.dist-info → chuk_tool_processor-0.1.4.dist-info}/METADATA +169 -3
- {chuk_tool_processor-0.1.2.dist-info → chuk_tool_processor-0.1.4.dist-info}/RECORD +15 -5
- {chuk_tool_processor-0.1.2.dist-info → chuk_tool_processor-0.1.4.dist-info}/WHEEL +1 -1
- {chuk_tool_processor-0.1.2.dist-info → chuk_tool_processor-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chuk-tool-processor
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: chuk-mcp>=0.1.12
|
|
7
8
|
Requires-Dist: dotenv>=0.9.9
|
|
8
9
|
Requires-Dist: openai>=1.76.0
|
|
9
10
|
Requires-Dist: pydantic>=2.11.3
|
|
@@ -21,6 +22,7 @@ The CHUK Tool Processor is a Python library designed to handle the execution of
|
|
|
21
22
|
2. **Executing tools** with proper isolation and error handling
|
|
22
23
|
3. **Managing tool executions** with retry logic, caching, and rate limiting
|
|
23
24
|
4. **Monitoring tool usage** with comprehensive logging
|
|
25
|
+
5. **MCP (Model Context Protocol) Integration** for remote tool execution
|
|
24
26
|
|
|
25
27
|
## Features
|
|
26
28
|
|
|
@@ -34,6 +36,7 @@ The CHUK Tool Processor is a Python library designed to handle the execution of
|
|
|
34
36
|
- **Retry Logic**: Automatically retry transient failures with exponential backoff
|
|
35
37
|
- **Structured Logging**: Comprehensive logging system for debugging and monitoring
|
|
36
38
|
- **Plugin Discovery**: Dynamically discover and load plugins from packages
|
|
39
|
+
- **MCP Integration**: Connect to and execute remote tools via Model Context Protocol
|
|
37
40
|
|
|
38
41
|
## Installation
|
|
39
42
|
|
|
@@ -101,6 +104,159 @@ if __name__ == "__main__":
|
|
|
101
104
|
asyncio.run(main())
|
|
102
105
|
```
|
|
103
106
|
|
|
107
|
+
## MCP Integration
|
|
108
|
+
|
|
109
|
+
The CHUK Tool Processor supports Model Context Protocol (MCP) for connecting to remote tool servers. This enables distributed tool execution and integration with third-party services.
|
|
110
|
+
|
|
111
|
+
### MCP with Stdio Transport
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
from chuk_tool_processor.mcp import setup_mcp_stdio
|
|
116
|
+
|
|
117
|
+
async def main():
|
|
118
|
+
# Configure MCP server
|
|
119
|
+
config_file = "server_config.json"
|
|
120
|
+
servers = ["echo", "calculator", "search"]
|
|
121
|
+
server_names = {0: "echo", 1: "calculator", 2: "search"}
|
|
122
|
+
|
|
123
|
+
# Setup MCP with stdio transport
|
|
124
|
+
processor, stream_manager = await setup_mcp_stdio(
|
|
125
|
+
config_file=config_file,
|
|
126
|
+
servers=servers,
|
|
127
|
+
server_names=server_names,
|
|
128
|
+
namespace="mcp", # All tools will be registered under this namespace
|
|
129
|
+
enable_caching=True,
|
|
130
|
+
enable_retries=True
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Process text with MCP tool calls
|
|
134
|
+
llm_text = """
|
|
135
|
+
Let me echo your message using the MCP server.
|
|
136
|
+
|
|
137
|
+
<tool name="mcp.echo" args='{"message": "Hello from MCP!"}'/>
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
results = await processor.process_text(llm_text)
|
|
141
|
+
|
|
142
|
+
for result in results:
|
|
143
|
+
print(f"Tool: {result.tool}")
|
|
144
|
+
print(f"Result: {result.result}")
|
|
145
|
+
|
|
146
|
+
# Clean up
|
|
147
|
+
await stream_manager.close()
|
|
148
|
+
|
|
149
|
+
if __name__ == "__main__":
|
|
150
|
+
asyncio.run(main())
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### MCP Server Configuration
|
|
154
|
+
|
|
155
|
+
Create a server configuration file (`server_config.json`):
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"mcpServers": {
|
|
160
|
+
"echo": {
|
|
161
|
+
"command": "uv",
|
|
162
|
+
"args": ["--directory", "/path/to/echo-server", "run", "src/echo_server/main.py"]
|
|
163
|
+
},
|
|
164
|
+
"calculator": {
|
|
165
|
+
"command": "node",
|
|
166
|
+
"args": ["/path/to/calculator-server/index.js"]
|
|
167
|
+
},
|
|
168
|
+
"search": {
|
|
169
|
+
"command": "python",
|
|
170
|
+
"args": ["/path/to/search-server/main.py"]
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Namespaced Tool Access
|
|
177
|
+
|
|
178
|
+
MCP tools are automatically registered in both their namespace and the default namespace:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
# These are equivalent:
|
|
182
|
+
<tool name="echo" args='{"message": "Hello"}'/>
|
|
183
|
+
<tool name="mcp.echo" args='{"message": "Hello"}'/>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### MCP with SSE Transport
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import asyncio
|
|
190
|
+
from chuk_tool_processor.mcp import setup_mcp_sse
|
|
191
|
+
|
|
192
|
+
async def main():
|
|
193
|
+
# Configure SSE servers
|
|
194
|
+
sse_servers = [
|
|
195
|
+
{
|
|
196
|
+
"name": "weather",
|
|
197
|
+
"url": "https://api.example.com/sse/weather",
|
|
198
|
+
"api_key": "your_api_key"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "geocoding",
|
|
202
|
+
"url": "https://api.example.com/sse/geocoding"
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
# Setup MCP with SSE transport
|
|
207
|
+
processor, stream_manager = await setup_mcp_sse(
|
|
208
|
+
servers=sse_servers,
|
|
209
|
+
server_names={0: "weather", 1: "geocoding"},
|
|
210
|
+
namespace="remote",
|
|
211
|
+
enable_caching=True
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Process tool calls
|
|
215
|
+
llm_text = """
|
|
216
|
+
Get the weather for New York.
|
|
217
|
+
|
|
218
|
+
<tool name="remote.weather" args='{"location": "New York", "units": "imperial"}'/>
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
results = await processor.process_text(llm_text)
|
|
222
|
+
|
|
223
|
+
await stream_manager.close()
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### MCP Stream Manager
|
|
227
|
+
|
|
228
|
+
The `StreamManager` class handles all MCP communication:
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from chuk_tool_processor.mcp.stream_manager import StreamManager
|
|
232
|
+
|
|
233
|
+
# Create and initialize
|
|
234
|
+
stream_manager = await StreamManager.create(
|
|
235
|
+
config_file="config.json",
|
|
236
|
+
servers=["echo", "search"],
|
|
237
|
+
transport_type="stdio"
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# Get available tools
|
|
241
|
+
tools = stream_manager.get_all_tools()
|
|
242
|
+
for tool in tools:
|
|
243
|
+
print(f"Tool: {tool['name']}")
|
|
244
|
+
|
|
245
|
+
# Get server information
|
|
246
|
+
server_info = stream_manager.get_server_info()
|
|
247
|
+
for server in server_info:
|
|
248
|
+
print(f"Server: {server['name']}, Status: {server['status']}")
|
|
249
|
+
|
|
250
|
+
# Call a tool directly
|
|
251
|
+
result = await stream_manager.call_tool(
|
|
252
|
+
tool_name="echo",
|
|
253
|
+
arguments={"message": "Hello"}
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Clean up
|
|
257
|
+
await stream_manager.close()
|
|
258
|
+
```
|
|
259
|
+
|
|
104
260
|
## Advanced Usage
|
|
105
261
|
|
|
106
262
|
### Using Decorators for Tool Configuration
|
|
@@ -259,11 +415,16 @@ The tool processor has several key components organized into a modular structure
|
|
|
259
415
|
- `plugins/discovery.py`: Plugin discovery mechanism
|
|
260
416
|
- `plugins/parsers/`: Parser plugins for different formats
|
|
261
417
|
|
|
262
|
-
5. **
|
|
418
|
+
5. **MCP Integration**: Model Context Protocol support
|
|
419
|
+
- `mcp/stream_manager.py`: Manages MCP server connections
|
|
420
|
+
- `mcp/transport/`: Transport implementations (stdio, SSE)
|
|
421
|
+
- `mcp/setup_mcp_*.py`: Easy setup functions for MCP integration
|
|
422
|
+
|
|
423
|
+
6. **Utils**: Shared utilities
|
|
263
424
|
- `utils/logging.py`: Structured logging system
|
|
264
425
|
- `utils/validation.py`: Argument and result validation
|
|
265
426
|
|
|
266
|
-
|
|
427
|
+
7. **Core**: Central components
|
|
267
428
|
- `core/processor.py`: Main processor for handling tool calls
|
|
268
429
|
- `core/exceptions.py`: Exception hierarchy
|
|
269
430
|
|
|
@@ -274,6 +435,8 @@ The repository includes several example scripts:
|
|
|
274
435
|
- `examples/tool_registry_example.py`: Demonstrates tool registration and usage
|
|
275
436
|
- `examples/plugin_example.py`: Shows how to create and use custom plugins
|
|
276
437
|
- `examples/tool_calling_example_usage.py`: Basic example demonstrating tool execution
|
|
438
|
+
- `examples/mcp_stdio_example.py`: MCP stdio transport demonstration
|
|
439
|
+
- `examples/mcp_stdio_example_calling_usage.py`: Complete MCP integration example
|
|
277
440
|
|
|
278
441
|
Run examples with:
|
|
279
442
|
|
|
@@ -287,6 +450,9 @@ uv run examples/plugin_example.py
|
|
|
287
450
|
# Tool execution example
|
|
288
451
|
uv run examples/tool_calling_example_usage.py
|
|
289
452
|
|
|
453
|
+
# MCP example
|
|
454
|
+
uv run examples/mcp_stdio_example.py
|
|
455
|
+
|
|
290
456
|
# Enable debug logging
|
|
291
457
|
LOGLEVEL=DEBUG uv run examples/tool_calling_example_usage.py
|
|
292
458
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
chuk_tool_processor/__init__.py,sha256=
|
|
1
|
+
chuk_tool_processor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
chuk_tool_processor/core/__init__.py,sha256=slM7pZna88tyZrF3KtN22ApYyCqGNt5Yscv-knsLOOA,38
|
|
3
3
|
chuk_tool_processor/core/exceptions.py,sha256=h4zL1jpCY1Ud1wT8xDeMxZ8GR8ttmkObcv36peUHJEA,1571
|
|
4
4
|
chuk_tool_processor/core/processor.py,sha256=ud7ezONnUFh_aDSapiBGNx-LtZfhAFpYjFuw2m_tFXk,10165
|
|
@@ -16,6 +16,16 @@ chuk_tool_processor/logging/context.py,sha256=hQFWGeraHX3DM28JDSiIuhQqep6TBfo1ua
|
|
|
16
16
|
chuk_tool_processor/logging/formatter.py,sha256=4pO-fLULkD3JPLjZOSiOZPGsjV3c4Ztr5ySda1RAvi4,1754
|
|
17
17
|
chuk_tool_processor/logging/helpers.py,sha256=Fk32BuecWZdyrmv8U0lh4W0AdNx4-gKcCaWBdId_rlI,3569
|
|
18
18
|
chuk_tool_processor/logging/metrics.py,sha256=ti_owuslT-x9cjcbP-_j7jivrlyY-Vb41mVhU-6W-2M,1537
|
|
19
|
+
chuk_tool_processor/mcp/__init__.py,sha256=vR9HHxLpXlKTIIwJJRr3QTmZegcdedR1YKyb46j6FIM,689
|
|
20
|
+
chuk_tool_processor/mcp/mcp_tool.py,sha256=TvZEudgQvaev2jaPw6OGsqAR5GNu6_cPaUCgqiT5ogU,1504
|
|
21
|
+
chuk_tool_processor/mcp/register_mcp_tools.py,sha256=ofE7pEn6sKDH8HWvNamVOaXsitLOaG48M5GhcpqCBbs,2801
|
|
22
|
+
chuk_tool_processor/mcp/setup_mcp_sse.py,sha256=Ep2IKRdH1Y299bCxt9G0NtwnsvguYP6mpraZyUJ8OKU,2643
|
|
23
|
+
chuk_tool_processor/mcp/setup_mcp_stdio.py,sha256=NjTvAFqQHxxN3XubsTgYY3lTrvPVWlnwCzkzbz7WE_M,2747
|
|
24
|
+
chuk_tool_processor/mcp/stream_manager.py,sha256=qIWzsQCTlu1SQQBExAdvBHGB3T5isQDyMhj29WkfbKQ,11779
|
|
25
|
+
chuk_tool_processor/mcp/transport/__init__.py,sha256=7QQqeSKVKv0N9GcyJuYF0R4FDZeooii5RjggvFFg5GY,296
|
|
26
|
+
chuk_tool_processor/mcp/transport/base_transport.py,sha256=1E29LjWw5vLQrPUDF_9TJt63P5dxAAN7n6E_KiZbGUY,3427
|
|
27
|
+
chuk_tool_processor/mcp/transport/sse_transport.py,sha256=bryH9DOWOn5qr6LsimTriukDC4ix2kuRq6bUv9qOV20,7645
|
|
28
|
+
chuk_tool_processor/mcp/transport/stdio_transport.py,sha256=lFXL7p8ca4z_J0RBL8UCHrQ1UH7C2-LbC0tZhpya4V4,7763
|
|
19
29
|
chuk_tool_processor/models/__init__.py,sha256=TC__rdVa0lQsmJHM_hbLDPRgToa_pQT_UxRcPZk6iVw,40
|
|
20
30
|
chuk_tool_processor/models/execution_strategy.py,sha256=ZPHysmKNHqJmahTtUXAbt1ke09vxy7EhZcsrwTdla8o,508
|
|
21
31
|
chuk_tool_processor/models/tool_call.py,sha256=RZOnx2YczkJN6ym2PLiI4CRzP2qU_5hpMtHxMcFOxY4,298
|
|
@@ -41,7 +51,7 @@ chuk_tool_processor/registry/providers/__init__.py,sha256=_0dg4YhyfAV0TXuR_i4ewX
|
|
|
41
51
|
chuk_tool_processor/registry/providers/memory.py,sha256=29aI5uvykjDmn9ymIukEdUtmTC9SXOAsDu9hw36XF44,4474
|
|
42
52
|
chuk_tool_processor/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
53
|
chuk_tool_processor/utils/validation.py,sha256=7ezn_o-3IHDrzOD3j6ttsAn2s3zS-jIjeBTuqicrs6A,3775
|
|
44
|
-
chuk_tool_processor-0.1.
|
|
45
|
-
chuk_tool_processor-0.1.
|
|
46
|
-
chuk_tool_processor-0.1.
|
|
47
|
-
chuk_tool_processor-0.1.
|
|
54
|
+
chuk_tool_processor-0.1.4.dist-info/METADATA,sha256=ekQNpVXyJrLw9kaLnhHW4iI1Q5do07T6Ol2QfeRsQn0,13703
|
|
55
|
+
chuk_tool_processor-0.1.4.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
|
56
|
+
chuk_tool_processor-0.1.4.dist-info/top_level.txt,sha256=7lTsnuRx4cOW4U2sNJWNxl4ZTt_J1ndkjTbj3pHPY5M,20
|
|
57
|
+
chuk_tool_processor-0.1.4.dist-info/RECORD,,
|
|
File without changes
|