mcp-use 1.0.1__tar.gz → 1.0.3__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.
Potentially problematic release.
This version of mcp-use might be problematic. Click here for more details.
- {mcp_use-1.0.1 → mcp_use-1.0.3}/PKG-INFO +40 -7
- {mcp_use-1.0.1 → mcp_use-1.0.3}/README.md +39 -6
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/api-reference/introduction.mdx +86 -15
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/essentials/configuration.mdx +47 -20
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/quickstart.mdx +39 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/agents/langchain_agent.py +13 -11
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/agents/mcpagent.py +35 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/connectors/http.py +1 -1
- {mcp_use-1.0.1 → mcp_use-1.0.3}/pyproject.toml +1 -1
- mcp_use-1.0.3/static/image.jpg +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_http_connector.py +1 -1
- mcp_use-1.0.1/static/image.jpg +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/.github/workflows/publish.yml +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/.github/workflows/tests.yml +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/.gitignore +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/.pre-commit-config.yaml +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/LICENSE +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/README.md +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/development.mdx +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/docs.json +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/essentials/connection-types.mdx +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/essentials/llm-integration.mdx +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/favicon.svg +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/images/hero-dark.png +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/images/hero-light.png +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/introduction.mdx +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/logo/dark.svg +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/logo/light.svg +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/docs/snippets/snippet-intro.mdx +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/airbnb_mcp.json +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/airbnb_use.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/blender_use.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/browser_mcp.json +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/browser_use.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/chat_example.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/filesystem_use.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/examples/multi_server_example.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/__init__.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/agents/__init__.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/agents/base.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/agents/prompts/default.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/client.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/config.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/connectors/__init__.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/connectors/base.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/connectors/stdio.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/connectors/websocket.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/logging.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/session.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/task_managers/__init__.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/task_managers/base.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/task_managers/sse.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/task_managers/stdio.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/mcp_use/task_managers/websocket.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/pytest.ini +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/conftest.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_client.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_config.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_logging.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_session.py +0 -0
- {mcp_use-1.0.1 → mcp_use-1.0.3}/tests/unit/test_stdio_connector.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-use
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: MCP Library for LLMs
|
|
5
5
|
Author-email: Pietro Zullo <pietro.zullo@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -346,25 +346,58 @@ if __name__ == "__main__":
|
|
|
346
346
|
asyncio.run(main())
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
|
|
349
|
+
# Tool Access Control
|
|
350
|
+
|
|
351
|
+
MCP-Use allows you to restrict which tools are available to the agent, providing better security and control over agent capabilities:
|
|
352
|
+
|
|
353
|
+
```python
|
|
354
|
+
import asyncio
|
|
355
|
+
from mcp_use import MCPAgent, MCPClient
|
|
356
|
+
from langchain_openai import ChatOpenAI
|
|
357
|
+
|
|
358
|
+
async def main():
|
|
359
|
+
# Create client
|
|
360
|
+
client = MCPClient.from_config_file("config.json")
|
|
361
|
+
|
|
362
|
+
# Create agent with restricted tools
|
|
363
|
+
agent = MCPAgent(
|
|
364
|
+
llm=ChatOpenAI(model="gpt-4"),
|
|
365
|
+
client=client,
|
|
366
|
+
disallowed_tools=["file_system", "network"] # Restrict potentially dangerous tools
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
# Run a query with restricted tool access
|
|
370
|
+
result = await agent.run(
|
|
371
|
+
"Find the best restaurant in San Francisco"
|
|
372
|
+
)
|
|
373
|
+
print(result)
|
|
374
|
+
|
|
375
|
+
# Clean up
|
|
376
|
+
await client.close_all_sessions()
|
|
377
|
+
|
|
378
|
+
if __name__ == "__main__":
|
|
379
|
+
asyncio.run(main())
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
# Roadmap
|
|
350
383
|
|
|
351
384
|
<ul>
|
|
352
385
|
<li>[x] Multiple Servers at once </li>
|
|
353
|
-
<li>[
|
|
386
|
+
<li>[x] Test remote connectors (http, ws)</li>
|
|
354
387
|
<li>[ ] ... </li>
|
|
355
388
|
</ul>
|
|
356
389
|
|
|
357
|
-
|
|
390
|
+
# Contributing
|
|
358
391
|
|
|
359
392
|
We love contributions! Feel free to open issues for bugs or feature requests.
|
|
360
393
|
|
|
361
|
-
|
|
394
|
+
# Requirements
|
|
362
395
|
|
|
363
396
|
- Python 3.11+
|
|
364
397
|
- MCP implementation (like Playwright MCP)
|
|
365
398
|
- LangChain and appropriate model libraries (OpenAI, Anthropic, etc.)
|
|
366
399
|
|
|
367
|
-
|
|
400
|
+
# Citation
|
|
368
401
|
|
|
369
402
|
If you use MCP-Use in your research or project, please cite:
|
|
370
403
|
|
|
@@ -378,6 +411,6 @@ If you use MCP-Use in your research or project, please cite:
|
|
|
378
411
|
}
|
|
379
412
|
```
|
|
380
413
|
|
|
381
|
-
|
|
414
|
+
# License
|
|
382
415
|
|
|
383
416
|
MIT
|
|
@@ -307,25 +307,58 @@ if __name__ == "__main__":
|
|
|
307
307
|
asyncio.run(main())
|
|
308
308
|
```
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
# Tool Access Control
|
|
311
|
+
|
|
312
|
+
MCP-Use allows you to restrict which tools are available to the agent, providing better security and control over agent capabilities:
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
import asyncio
|
|
316
|
+
from mcp_use import MCPAgent, MCPClient
|
|
317
|
+
from langchain_openai import ChatOpenAI
|
|
318
|
+
|
|
319
|
+
async def main():
|
|
320
|
+
# Create client
|
|
321
|
+
client = MCPClient.from_config_file("config.json")
|
|
322
|
+
|
|
323
|
+
# Create agent with restricted tools
|
|
324
|
+
agent = MCPAgent(
|
|
325
|
+
llm=ChatOpenAI(model="gpt-4"),
|
|
326
|
+
client=client,
|
|
327
|
+
disallowed_tools=["file_system", "network"] # Restrict potentially dangerous tools
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
# Run a query with restricted tool access
|
|
331
|
+
result = await agent.run(
|
|
332
|
+
"Find the best restaurant in San Francisco"
|
|
333
|
+
)
|
|
334
|
+
print(result)
|
|
335
|
+
|
|
336
|
+
# Clean up
|
|
337
|
+
await client.close_all_sessions()
|
|
338
|
+
|
|
339
|
+
if __name__ == "__main__":
|
|
340
|
+
asyncio.run(main())
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
# Roadmap
|
|
311
344
|
|
|
312
345
|
<ul>
|
|
313
346
|
<li>[x] Multiple Servers at once </li>
|
|
314
|
-
<li>[
|
|
347
|
+
<li>[x] Test remote connectors (http, ws)</li>
|
|
315
348
|
<li>[ ] ... </li>
|
|
316
349
|
</ul>
|
|
317
350
|
|
|
318
|
-
|
|
351
|
+
# Contributing
|
|
319
352
|
|
|
320
353
|
We love contributions! Feel free to open issues for bugs or feature requests.
|
|
321
354
|
|
|
322
|
-
|
|
355
|
+
# Requirements
|
|
323
356
|
|
|
324
357
|
- Python 3.11+
|
|
325
358
|
- MCP implementation (like Playwright MCP)
|
|
326
359
|
- LangChain and appropriate model libraries (OpenAI, Anthropic, etc.)
|
|
327
360
|
|
|
328
|
-
|
|
361
|
+
# Citation
|
|
329
362
|
|
|
330
363
|
If you use MCP-Use in your research or project, please cite:
|
|
331
364
|
|
|
@@ -339,6 +372,6 @@ If you use MCP-Use in your research or project, please cite:
|
|
|
339
372
|
}
|
|
340
373
|
```
|
|
341
374
|
|
|
342
|
-
|
|
375
|
+
# License
|
|
343
376
|
|
|
344
377
|
MIT
|
|
@@ -127,24 +127,26 @@ agent = MCPAgent(
|
|
|
127
127
|
memory_enabled=True,
|
|
128
128
|
system_prompt=None,
|
|
129
129
|
system_prompt_template=None,
|
|
130
|
-
additional_instructions=None
|
|
130
|
+
additional_instructions=None,
|
|
131
|
+
disallowed_tools=None
|
|
131
132
|
)
|
|
132
133
|
```
|
|
133
134
|
|
|
134
|
-
| Parameter | Type | Required | Default | Description
|
|
135
|
-
| ------------------------- | ------------------- | -------- | ------- |
|
|
136
|
-
| `llm` | BaseLanguageModel | Yes | - | Any LangChain-compatible language model
|
|
137
|
-
| `client` | MCPClient | No | None | The MCPClient instance
|
|
138
|
-
| `connectors` | list[BaseConnector] | No | None | List of connectors if not using client
|
|
139
|
-
| `server_name` | str | No | None | Name of the server to use
|
|
140
|
-
| `max_steps` | int | No | 5 | Maximum number of steps the agent can take
|
|
141
|
-
| `auto_initialize` | bool | No | False | Whether to initialize automatically
|
|
142
|
-
| `memory_enabled` | bool | No | True | Whether to enable memory
|
|
143
|
-
| `system_prompt` | str | No | None | Custom system prompt
|
|
144
|
-
| `system_prompt_template` | str | No | None | Custom system prompt template
|
|
145
|
-
| `additional_instructions` | str | No | None | Additional instructions for the agent
|
|
146
|
-
| `session_options` | dict | No | {} | Additional options for session creation
|
|
147
|
-
| `output_parser` | OutputParser | No | None | Custom output parser for LLM responses
|
|
135
|
+
| Parameter | Type | Required | Default | Description |
|
|
136
|
+
| ------------------------- | ------------------- | -------- | ------- | ------------------------------------------------------------ |
|
|
137
|
+
| `llm` | BaseLanguageModel | Yes | - | Any LangChain-compatible language model |
|
|
138
|
+
| `client` | MCPClient | No | None | The MCPClient instance |
|
|
139
|
+
| `connectors` | list[BaseConnector] | No | None | List of connectors if not using client |
|
|
140
|
+
| `server_name` | str | No | None | Name of the server to use |
|
|
141
|
+
| `max_steps` | int | No | 5 | Maximum number of steps the agent can take |
|
|
142
|
+
| `auto_initialize` | bool | No | False | Whether to initialize automatically |
|
|
143
|
+
| `memory_enabled` | bool | No | True | Whether to enable memory |
|
|
144
|
+
| `system_prompt` | str | No | None | Custom system prompt |
|
|
145
|
+
| `system_prompt_template` | str | No | None | Custom system prompt template |
|
|
146
|
+
| `additional_instructions` | str | No | None | Additional instructions for the agent |
|
|
147
|
+
| `session_options` | dict | No | {} | Additional options for session creation |
|
|
148
|
+
| `output_parser` | OutputParser | No | None | Custom output parser for LLM responses |
|
|
149
|
+
| `disallowed_tools` | list[str] | No | None | List of tool names that should not be available to the agent |
|
|
148
150
|
|
|
149
151
|
**When to use different parameters**:
|
|
150
152
|
|
|
@@ -176,6 +178,11 @@ agent = MCPAgent(
|
|
|
176
178
|
- **session_options**:
|
|
177
179
|
- Customize timeout for long-running server operations
|
|
178
180
|
- Set retry parameters for unstable connections
|
|
181
|
+
- **disallowed_tools**:
|
|
182
|
+
- Use to restrict which tools the agent can access
|
|
183
|
+
- Helpful for security or to limit agent capabilities
|
|
184
|
+
- Useful when certain tools might be dangerous or unnecessary for a specific task
|
|
185
|
+
- Can be updated after initialization using `set_disallowed_tools()`
|
|
179
186
|
|
|
180
187
|
### Core Methods
|
|
181
188
|
|
|
@@ -234,6 +241,39 @@ history = agent.get_history()
|
|
|
234
241
|
- When implementing custom logging
|
|
235
242
|
- To provide context for follow-up queries
|
|
236
243
|
|
|
244
|
+
#### set_disallowed_tools
|
|
245
|
+
|
|
246
|
+
Sets the list of tools that should not be available to the agent.
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
agent.set_disallowed_tools(["tool1", "tool2"])
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
| Parameter | Type | Required | Description |
|
|
253
|
+
| ------------------ | --------- | -------- | ----------------------------------------------- |
|
|
254
|
+
| `disallowed_tools` | list[str] | Yes | List of tool names that should not be available |
|
|
255
|
+
|
|
256
|
+
**When to use**:
|
|
257
|
+
|
|
258
|
+
- To restrict access to specific tools for security reasons
|
|
259
|
+
- To limit agent capabilities for specific tasks
|
|
260
|
+
- To prevent the agent from using potentially dangerous tools
|
|
261
|
+
- Note: Changes take effect on next initialization
|
|
262
|
+
|
|
263
|
+
#### get_disallowed_tools
|
|
264
|
+
|
|
265
|
+
Gets the list of tools that are not available to the agent.
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
disallowed = agent.get_disallowed_tools()
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**When to use**:
|
|
272
|
+
|
|
273
|
+
- To check which tools are currently restricted
|
|
274
|
+
- For debugging or auditing purposes
|
|
275
|
+
- To verify tool restrictions before running the agent
|
|
276
|
+
|
|
237
277
|
## Configuration Details
|
|
238
278
|
|
|
239
279
|
### MCP Server Configuration Schema
|
|
@@ -383,3 +423,34 @@ This approach is useful when:
|
|
|
383
423
|
- The MCP server returns structured data that needs special handling
|
|
384
424
|
- You need to extract specific information from responses
|
|
385
425
|
- You're integrating with custom or specialized MCP servers
|
|
426
|
+
|
|
427
|
+
### Restricting Tool Access
|
|
428
|
+
|
|
429
|
+
Control which tools are available to the agent:
|
|
430
|
+
|
|
431
|
+
```python
|
|
432
|
+
from mcp_use import MCPAgent, MCPClient
|
|
433
|
+
from langchain_openai import ChatOpenAI
|
|
434
|
+
|
|
435
|
+
# Create agent with restricted tools
|
|
436
|
+
agent = MCPAgent(
|
|
437
|
+
llm=ChatOpenAI(model="gpt-4o"),
|
|
438
|
+
client=client,
|
|
439
|
+
disallowed_tools=["file_system", "network", "shell"] # Restrict potentially dangerous tools
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# Update restrictions after initialization
|
|
443
|
+
agent.set_disallowed_tools(["file_system", "network", "shell", "database"])
|
|
444
|
+
await agent.initialize() # Reinitialize to apply changes
|
|
445
|
+
|
|
446
|
+
# Check current restrictions
|
|
447
|
+
restricted_tools = agent.get_disallowed_tools()
|
|
448
|
+
print(f"Restricted tools: {restricted_tools}")
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
This approach is useful when:
|
|
452
|
+
|
|
453
|
+
- You need to restrict access to sensitive operations
|
|
454
|
+
- You want to limit the agent's capabilities for specific tasks
|
|
455
|
+
- You're concerned about security implications of certain tools
|
|
456
|
+
- You want to focus the agent on specific functionality
|
|
@@ -96,28 +96,25 @@ Here's a basic example of how to configure an MCP server:
|
|
|
96
96
|
### Multiple Server Configuration
|
|
97
97
|
|
|
98
98
|
You can configure multiple MCP servers in a single configuration file, allowing you to use different servers for different tasks or combine their capabilities (e.g.):
|
|
99
|
+
|
|
99
100
|
```json
|
|
100
101
|
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"-y",
|
|
115
|
-
"@modelcontextprotocol/server-filesystem",
|
|
116
|
-
"/home/pietro/projects/mcp-use/",
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
}
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"airbnb": {
|
|
104
|
+
"command": "npx",
|
|
105
|
+
"args": ["-y", "@openbnb/mcp-server-airbnb", "--ignore-robots-txt"]
|
|
106
|
+
},
|
|
107
|
+
"playwright": {
|
|
108
|
+
"command": "npx",
|
|
109
|
+
"args": ["@playwright/mcp@latest"],
|
|
110
|
+
"env": { "DISPLAY": ":1" }
|
|
111
|
+
},
|
|
112
|
+
"filesystem": {
|
|
113
|
+
"command": "npx",
|
|
114
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/pietro/projects/mcp-use/"]
|
|
120
115
|
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
121
118
|
```
|
|
122
119
|
|
|
123
120
|
For a complete example of using multiple servers, see the [multi-server example](https://github.com/pietrozullo/mcp-use/blob/main/examples/multi_server_example.py) in our repository.
|
|
@@ -146,7 +143,8 @@ agent = MCPAgent(
|
|
|
146
143
|
auto_initialize=True,
|
|
147
144
|
memory_enabled=True,
|
|
148
145
|
system_prompt="Custom instructions for the agent",
|
|
149
|
-
additional_instructions="Additional guidelines for specific tasks"
|
|
146
|
+
additional_instructions="Additional guidelines for specific tasks",
|
|
147
|
+
disallowed_tools=["file_system", "network", "shell"] # Restrict potentially dangerous tools
|
|
150
148
|
)
|
|
151
149
|
```
|
|
152
150
|
|
|
@@ -162,6 +160,35 @@ agent = MCPAgent(
|
|
|
162
160
|
- `system_prompt`: Custom system prompt (optional)
|
|
163
161
|
- `system_prompt_template`: Custom system prompt template (optional)
|
|
164
162
|
- `additional_instructions`: Additional instructions for the agent (optional)
|
|
163
|
+
- `disallowed_tools`: List of tool names that should not be available to the agent (optional)
|
|
164
|
+
|
|
165
|
+
### Tool Access Control
|
|
166
|
+
|
|
167
|
+
You can restrict which tools are available to the agent for security or to limit its capabilities:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
# Create agent with restricted tools
|
|
171
|
+
agent = MCPAgent(
|
|
172
|
+
llm=ChatOpenAI(model="gpt-4o"),
|
|
173
|
+
client=client,
|
|
174
|
+
disallowed_tools=["file_system", "network", "shell"] # Restrict potentially dangerous tools
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# Update restrictions after initialization
|
|
178
|
+
agent.set_disallowed_tools(["file_system", "network", "shell", "database"])
|
|
179
|
+
await agent.initialize() # Reinitialize to apply changes
|
|
180
|
+
|
|
181
|
+
# Check current restrictions
|
|
182
|
+
restricted_tools = agent.get_disallowed_tools()
|
|
183
|
+
print(f"Restricted tools: {restricted_tools}")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
This feature is useful for:
|
|
187
|
+
|
|
188
|
+
- Restricting access to sensitive operations
|
|
189
|
+
- Limiting agent capabilities for specific tasks
|
|
190
|
+
- Preventing the agent from using potentially dangerous tools
|
|
191
|
+
- Focusing the agent on specific functionality
|
|
165
192
|
|
|
166
193
|
## Error Handling
|
|
167
194
|
|
|
@@ -82,6 +82,45 @@ if __name__ == "__main__":
|
|
|
82
82
|
asyncio.run(main())
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## Restricting Tool Access
|
|
86
|
+
|
|
87
|
+
You can control which tools are available to the agent:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import asyncio
|
|
91
|
+
import os
|
|
92
|
+
from dotenv import load_dotenv
|
|
93
|
+
from langchain_openai import ChatOpenAI
|
|
94
|
+
from mcp_use import MCPAgent, MCPClient
|
|
95
|
+
|
|
96
|
+
async def main():
|
|
97
|
+
# Load environment variables
|
|
98
|
+
load_dotenv()
|
|
99
|
+
|
|
100
|
+
# Create MCPClient from config file
|
|
101
|
+
client = MCPClient.from_config_file("browser_mcp.json")
|
|
102
|
+
|
|
103
|
+
# Create LLM
|
|
104
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
105
|
+
|
|
106
|
+
# Create agent with restricted tools
|
|
107
|
+
agent = MCPAgent(
|
|
108
|
+
llm=llm,
|
|
109
|
+
client=client,
|
|
110
|
+
max_steps=30,
|
|
111
|
+
disallowed_tools=["file_system", "network"] # Restrict potentially dangerous tools
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Run the query
|
|
115
|
+
result = await agent.run(
|
|
116
|
+
"Find the best restaurant in San Francisco USING GOOGLE SEARCH",
|
|
117
|
+
)
|
|
118
|
+
print(f"\nResult: {result}")
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__":
|
|
121
|
+
asyncio.run(main())
|
|
122
|
+
```
|
|
123
|
+
|
|
85
124
|
## Available MCP Servers
|
|
86
125
|
|
|
87
126
|
mcp_use supports various MCP servers:
|
|
@@ -82,6 +82,7 @@ class LangChainAgent:
|
|
|
82
82
|
llm: BaseLanguageModel,
|
|
83
83
|
max_steps: int = 5,
|
|
84
84
|
system_message: str | None = None,
|
|
85
|
+
disallowed_tools: list[str] | None = None,
|
|
85
86
|
) -> None:
|
|
86
87
|
"""Initialize a new LangChain agent.
|
|
87
88
|
|
|
@@ -90,11 +91,13 @@ class LangChainAgent:
|
|
|
90
91
|
llm: The LangChain LLM to use.
|
|
91
92
|
max_steps: The maximum number of steps to take.
|
|
92
93
|
system_message: Optional custom system message to use.
|
|
94
|
+
disallowed_tools: List of tool names that should not be available to the agent.
|
|
93
95
|
"""
|
|
94
96
|
self.connectors = connectors
|
|
95
97
|
self.llm = llm
|
|
96
98
|
self.max_steps = max_steps
|
|
97
99
|
self.system_message = system_message or self.DEFAULT_SYSTEM_MESSAGE
|
|
100
|
+
self.disallowed_tools = disallowed_tools or []
|
|
98
101
|
self.tools: list[BaseTool] = []
|
|
99
102
|
self.agent: AgentExecutor | None = None
|
|
100
103
|
|
|
@@ -137,17 +140,16 @@ class LangChainAgent:
|
|
|
137
140
|
"""Create LangChain tools from MCP tools.
|
|
138
141
|
|
|
139
142
|
Returns:
|
|
140
|
-
A list of LangChain tools
|
|
143
|
+
A list of LangChain tools that wrap MCP tools.
|
|
141
144
|
"""
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
tools = []
|
|
144
146
|
for connector in self.connectors:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
local_connector = connector # Capture for closure
|
|
148
|
+
for tool in connector.tools:
|
|
149
|
+
# Skip disallowed tools
|
|
150
|
+
if tool.name in self.disallowed_tools:
|
|
151
|
+
continue
|
|
147
152
|
|
|
148
|
-
# Wrap MCP tools into LangChain tools
|
|
149
|
-
for tool in tools:
|
|
150
|
-
# Define adapter class to convert MCP tool to LangChain format
|
|
151
153
|
class McpToLangChainAdapter(BaseTool):
|
|
152
154
|
name: str = tool.name or "NO NAME"
|
|
153
155
|
description: str = tool.description or ""
|
|
@@ -202,11 +204,11 @@ class LangChainAgent:
|
|
|
202
204
|
return f"Error executing MCP tool: {str(e)}"
|
|
203
205
|
raise
|
|
204
206
|
|
|
205
|
-
|
|
207
|
+
tools.append(McpToLangChainAdapter())
|
|
206
208
|
|
|
207
209
|
# Log available tools for debugging
|
|
208
|
-
logger.info(f"Available tools: {[tool.name for tool in
|
|
209
|
-
return
|
|
210
|
+
logger.info(f"Available tools: {[tool.name for tool in tools]}")
|
|
211
|
+
return tools
|
|
210
212
|
|
|
211
213
|
def _create_agent(self) -> AgentExecutor:
|
|
212
214
|
"""Create the LangChain agent with the configured system message.
|
|
@@ -39,6 +39,7 @@ class MCPAgent:
|
|
|
39
39
|
system_prompt: str | None = None,
|
|
40
40
|
system_prompt_template: str | None = None,
|
|
41
41
|
additional_instructions: str | None = None,
|
|
42
|
+
disallowed_tools: list[str] | None = None,
|
|
42
43
|
):
|
|
43
44
|
"""Initialize a new MCPAgent instance.
|
|
44
45
|
|
|
@@ -53,6 +54,7 @@ class MCPAgent:
|
|
|
53
54
|
system_prompt: Complete system prompt to use (overrides template if provided).
|
|
54
55
|
system_prompt_template: Template for system prompt with {tool_descriptions} placeholder.
|
|
55
56
|
additional_instructions: Extra instructions to append to the system prompt.
|
|
57
|
+
disallowed_tools: List of tool names that should not be available to the agent.
|
|
56
58
|
"""
|
|
57
59
|
self.llm = llm
|
|
58
60
|
self.client = client
|
|
@@ -63,6 +65,7 @@ class MCPAgent:
|
|
|
63
65
|
self.memory_enabled = memory_enabled
|
|
64
66
|
self._initialized = False
|
|
65
67
|
self._conversation_history: list[BaseMessage] = []
|
|
68
|
+
self.disallowed_tools = disallowed_tools or []
|
|
66
69
|
|
|
67
70
|
# System prompt configuration
|
|
68
71
|
self.system_prompt = system_prompt
|
|
@@ -102,6 +105,7 @@ class MCPAgent:
|
|
|
102
105
|
llm=self.llm,
|
|
103
106
|
max_steps=self.max_steps,
|
|
104
107
|
system_message=(self._system_message.content if self._system_message else None),
|
|
108
|
+
disallowed_tools=self.disallowed_tools,
|
|
105
109
|
)
|
|
106
110
|
|
|
107
111
|
# Initialize the agent
|
|
@@ -125,6 +129,10 @@ class MCPAgent:
|
|
|
125
129
|
tools = connector.tools
|
|
126
130
|
# Generate tool descriptions
|
|
127
131
|
for tool in tools:
|
|
132
|
+
# Skip disallowed tools
|
|
133
|
+
if tool.name in self.disallowed_tools:
|
|
134
|
+
continue
|
|
135
|
+
|
|
128
136
|
# Escape curly braces in the description by doubling them
|
|
129
137
|
# (sometimes e.g. blender mcp they are used in the description)
|
|
130
138
|
description = (
|
|
@@ -188,6 +196,33 @@ class MCPAgent:
|
|
|
188
196
|
if self._agent:
|
|
189
197
|
self._agent.set_system_message(message)
|
|
190
198
|
|
|
199
|
+
def set_disallowed_tools(self, disallowed_tools: list[str]) -> None:
|
|
200
|
+
"""Set the list of tools that should not be available to the agent.
|
|
201
|
+
|
|
202
|
+
This will take effect the next time the agent is initialized.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
disallowed_tools: List of tool names that should not be available.
|
|
206
|
+
"""
|
|
207
|
+
self.disallowed_tools = disallowed_tools
|
|
208
|
+
|
|
209
|
+
# If the agent is already initialized, we need to reinitialize it
|
|
210
|
+
# to apply the changes to the available tools
|
|
211
|
+
if self._initialized:
|
|
212
|
+
logger.info(
|
|
213
|
+
"Agent already initialized. Changes will take effect on next initialization."
|
|
214
|
+
)
|
|
215
|
+
# We don't automatically reinitialize here as it could be disruptive
|
|
216
|
+
# to ongoing operations. The user can call initialize() explicitly if needed.
|
|
217
|
+
|
|
218
|
+
def get_disallowed_tools(self) -> list[str]:
|
|
219
|
+
"""Get the list of tools that are not available to the agent.
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
List of tool names that are not available.
|
|
223
|
+
"""
|
|
224
|
+
return self.disallowed_tools
|
|
225
|
+
|
|
191
226
|
async def run(
|
|
192
227
|
self,
|
|
193
228
|
query: str,
|
|
@@ -54,7 +54,7 @@ class HttpConnector(BaseConnector):
|
|
|
54
54
|
logger.info(f"Connecting to MCP implementation via HTTP/SSE: {self.base_url}")
|
|
55
55
|
try:
|
|
56
56
|
# Create the SSE connection URL
|
|
57
|
-
sse_url = f"{self.base_url}
|
|
57
|
+
sse_url = f"{self.base_url}"
|
|
58
58
|
|
|
59
59
|
# Create and start the connection manager
|
|
60
60
|
self._connection_manager = SseConnectionManager(
|
|
Binary file
|
|
@@ -111,7 +111,7 @@ class TestHttpConnectorConnection(IsolatedAsyncioTestCase):
|
|
|
111
111
|
await self.connector.connect()
|
|
112
112
|
|
|
113
113
|
# Verify connection manager was created and started
|
|
114
|
-
mock_cm_class.assert_called_once_with("http://localhost:8000
|
|
114
|
+
mock_cm_class.assert_called_once_with("http://localhost:8000", {}, 5, 300)
|
|
115
115
|
mock_cm_instance.start.assert_called_once()
|
|
116
116
|
|
|
117
117
|
# Verify client session was created
|
mcp_use-1.0.1/static/image.jpg
DELETED
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|