mcp-use 1.0.2__py3-none-any.whl → 1.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 mcp-use might be problematic. Click here for more details.
- mcp_use/agents/langchain_agent.py +13 -11
- mcp_use/agents/mcpagent.py +35 -0
- {mcp_use-1.0.2.dist-info → mcp_use-1.1.4.dist-info}/METADATA +152 -18
- {mcp_use-1.0.2.dist-info → mcp_use-1.1.4.dist-info}/RECORD +6 -6
- {mcp_use-1.0.2.dist-info → mcp_use-1.1.4.dist-info}/WHEEL +0 -0
- {mcp_use-1.0.2.dist-info → mcp_use-1.1.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -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.
|
mcp_use/agents/mcpagent.py
CHANGED
|
@@ -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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcp-use
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: MCP Library for LLMs
|
|
5
5
|
Author-email: Pietro Zullo <pietro.zullo@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -56,6 +56,19 @@ Description-Content-Type: text/markdown
|
|
|
56
56
|
|
|
57
57
|
💡 Let developers easily connect any LLM to tools like web browsing, file operations, and more.
|
|
58
58
|
|
|
59
|
+
# Features
|
|
60
|
+
|
|
61
|
+
## ✨ Key Features
|
|
62
|
+
|
|
63
|
+
| Feature | Description |
|
|
64
|
+
|---------|-------------|
|
|
65
|
+
| 🔄 **Ease of use** | Create your first MCP capable agent you need only 6 lines of code |
|
|
66
|
+
| 🤖 **LLM Flexibility** | Works with any langchain supported LLM that supports tool calling (OpenAI, Anthropic, Groq, LLama etc.) |
|
|
67
|
+
| 🌐 **HTTP Support** | Direct connection to MCP servers running on specific HTTP ports |
|
|
68
|
+
| 🧩 **Multi-Server Support** | Use multiple MCP servers simultaneously in a single agent |
|
|
69
|
+
| 🛡️ **Tool Restrictions** | Restrict potentially dangerous tools like file system or network access |
|
|
70
|
+
|
|
71
|
+
|
|
59
72
|
# Quick start
|
|
60
73
|
|
|
61
74
|
With pip:
|
|
@@ -72,7 +85,30 @@ cd mcp-use
|
|
|
72
85
|
pip install -e .
|
|
73
86
|
```
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
### Installing LangChain Providers
|
|
89
|
+
|
|
90
|
+
mcp_use works with various LLM providers through LangChain. You'll need to install the appropriate LangChain provider package for your chosen LLM. For example:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# For OpenAI
|
|
94
|
+
pip install langchain-openai
|
|
95
|
+
|
|
96
|
+
# For Anthropic
|
|
97
|
+
pip install langchain-anthropic
|
|
98
|
+
|
|
99
|
+
# For other providers, check the [LangChain chat models documentation](https://python.langchain.com/docs/integrations/chat/)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
and add your API keys for the provider you want to use to your `.env` file.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
OPENAI_API_KEY=
|
|
106
|
+
ANTHROPIC_API_KEY=
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> **Important**: Only models with tool calling capabilities can be used with mcp_use. Make sure your chosen model supports function calling or tool use.
|
|
110
|
+
|
|
111
|
+
### Spin up your agent:
|
|
76
112
|
|
|
77
113
|
```python
|
|
78
114
|
import asyncio
|
|
@@ -85,8 +121,21 @@ async def main():
|
|
|
85
121
|
# Load environment variables
|
|
86
122
|
load_dotenv()
|
|
87
123
|
|
|
88
|
-
# Create
|
|
89
|
-
|
|
124
|
+
# Create configuration dictionary
|
|
125
|
+
config = {
|
|
126
|
+
"mcpServers": {
|
|
127
|
+
"playwright": {
|
|
128
|
+
"command": "npx",
|
|
129
|
+
"args": ["@playwright/mcp@latest"],
|
|
130
|
+
"env": {
|
|
131
|
+
"DISPLAY": ":1"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# Create MCPClient from configuration dictionary
|
|
138
|
+
client = MCPClient.from_dict(config)
|
|
90
139
|
|
|
91
140
|
# Create LLM
|
|
92
141
|
llm = ChatOpenAI(model="gpt-4o")
|
|
@@ -96,7 +145,7 @@ async def main():
|
|
|
96
145
|
|
|
97
146
|
# Run the query
|
|
98
147
|
result = await agent.run(
|
|
99
|
-
"Find the best restaurant in San Francisco
|
|
148
|
+
"Find the best restaurant in San Francisco",
|
|
100
149
|
)
|
|
101
150
|
print(f"\nResult: {result}")
|
|
102
151
|
|
|
@@ -104,6 +153,14 @@ if __name__ == "__main__":
|
|
|
104
153
|
asyncio.run(main())
|
|
105
154
|
```
|
|
106
155
|
|
|
156
|
+
You can also add the servers configuration from a config file like this:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
client = MCPClient.from_config_file(
|
|
160
|
+
os.path.join("browser_mcp.json")
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
107
164
|
Example configuration file (`browser_mcp.json`):
|
|
108
165
|
|
|
109
166
|
```json
|
|
@@ -120,15 +177,10 @@ Example configuration file (`browser_mcp.json`):
|
|
|
120
177
|
}
|
|
121
178
|
```
|
|
122
179
|
|
|
123
|
-
Add your API keys for the provider you want to use to your `.env` file.
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
OPENAI_API_KEY=
|
|
127
|
-
ANTHROPIC_API_KEY=
|
|
128
|
-
```
|
|
129
|
-
|
|
130
180
|
For other settings, models, and more, check out the documentation.
|
|
131
181
|
|
|
182
|
+
# Features
|
|
183
|
+
|
|
132
184
|
# Example Use Cases
|
|
133
185
|
|
|
134
186
|
## Web Browsing with Playwright
|
|
@@ -286,6 +338,55 @@ if __name__ == "__main__":
|
|
|
286
338
|
asyncio.run(main())
|
|
287
339
|
```
|
|
288
340
|
|
|
341
|
+
## HTTP Connection Example
|
|
342
|
+
|
|
343
|
+
MCP-Use now supports HTTP connections, allowing you to connect to MCP servers running on specific HTTP ports. This feature is particularly useful for integrating with web-based MCP servers.
|
|
344
|
+
|
|
345
|
+
Here's an example of how to use the HTTP connection feature:
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
import asyncio
|
|
349
|
+
import os
|
|
350
|
+
from dotenv import load_dotenv
|
|
351
|
+
from langchain_openai import ChatOpenAI
|
|
352
|
+
from mcp_use import MCPAgent, MCPClient
|
|
353
|
+
|
|
354
|
+
async def main():
|
|
355
|
+
"""Run the example using a configuration file."""
|
|
356
|
+
# Load environment variables
|
|
357
|
+
load_dotenv()
|
|
358
|
+
|
|
359
|
+
config = {
|
|
360
|
+
"mcpServers": {
|
|
361
|
+
"http": {
|
|
362
|
+
"url": "http://localhost:8931/sse"
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
# Create MCPClient from config file
|
|
368
|
+
client = MCPClient.from_dict(config)
|
|
369
|
+
|
|
370
|
+
# Create LLM
|
|
371
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
372
|
+
|
|
373
|
+
# Create agent with the client
|
|
374
|
+
agent = MCPAgent(llm=llm, client=client, max_steps=30)
|
|
375
|
+
|
|
376
|
+
# Run the query
|
|
377
|
+
result = await agent.run(
|
|
378
|
+
"Find the best restaurant in San Francisco USING GOOGLE SEARCH",
|
|
379
|
+
max_steps=30,
|
|
380
|
+
)
|
|
381
|
+
print(f"\nResult: {result}")
|
|
382
|
+
|
|
383
|
+
if __name__ == "__main__":
|
|
384
|
+
# Run the appropriate example
|
|
385
|
+
asyncio.run(main())
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
This example demonstrates how to connect to an MCP server running on a specific HTTP port. Make sure to start your MCP server before running this example.
|
|
389
|
+
|
|
289
390
|
# Multi-Server Support
|
|
290
391
|
|
|
291
392
|
MCP-Use supports working with multiple MCP servers simultaneously, allowing you to combine tools from different servers in a single agent. This is useful for complex tasks that require multiple capabilities, such as web browsing combined with file operations or 3D modeling.
|
|
@@ -346,25 +447,58 @@ if __name__ == "__main__":
|
|
|
346
447
|
asyncio.run(main())
|
|
347
448
|
```
|
|
348
449
|
|
|
349
|
-
|
|
450
|
+
# Tool Access Control
|
|
451
|
+
|
|
452
|
+
MCP-Use allows you to restrict which tools are available to the agent, providing better security and control over agent capabilities:
|
|
453
|
+
|
|
454
|
+
```python
|
|
455
|
+
import asyncio
|
|
456
|
+
from mcp_use import MCPAgent, MCPClient
|
|
457
|
+
from langchain_openai import ChatOpenAI
|
|
458
|
+
|
|
459
|
+
async def main():
|
|
460
|
+
# Create client
|
|
461
|
+
client = MCPClient.from_config_file("config.json")
|
|
462
|
+
|
|
463
|
+
# Create agent with restricted tools
|
|
464
|
+
agent = MCPAgent(
|
|
465
|
+
llm=ChatOpenAI(model="gpt-4"),
|
|
466
|
+
client=client,
|
|
467
|
+
disallowed_tools=["file_system", "network"] # Restrict potentially dangerous tools
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
# Run a query with restricted tool access
|
|
471
|
+
result = await agent.run(
|
|
472
|
+
"Find the best restaurant in San Francisco"
|
|
473
|
+
)
|
|
474
|
+
print(result)
|
|
475
|
+
|
|
476
|
+
# Clean up
|
|
477
|
+
await client.close_all_sessions()
|
|
478
|
+
|
|
479
|
+
if __name__ == "__main__":
|
|
480
|
+
asyncio.run(main())
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
# Roadmap
|
|
350
484
|
|
|
351
485
|
<ul>
|
|
352
486
|
<li>[x] Multiple Servers at once </li>
|
|
353
|
-
<li>[
|
|
487
|
+
<li>[x] Test remote connectors (http, ws)</li>
|
|
354
488
|
<li>[ ] ... </li>
|
|
355
489
|
</ul>
|
|
356
490
|
|
|
357
|
-
|
|
491
|
+
# Contributing
|
|
358
492
|
|
|
359
493
|
We love contributions! Feel free to open issues for bugs or feature requests.
|
|
360
494
|
|
|
361
|
-
|
|
495
|
+
# Requirements
|
|
362
496
|
|
|
363
497
|
- Python 3.11+
|
|
364
498
|
- MCP implementation (like Playwright MCP)
|
|
365
499
|
- LangChain and appropriate model libraries (OpenAI, Anthropic, etc.)
|
|
366
500
|
|
|
367
|
-
|
|
501
|
+
# Citation
|
|
368
502
|
|
|
369
503
|
If you use MCP-Use in your research or project, please cite:
|
|
370
504
|
|
|
@@ -378,6 +512,6 @@ If you use MCP-Use in your research or project, please cite:
|
|
|
378
512
|
}
|
|
379
513
|
```
|
|
380
514
|
|
|
381
|
-
|
|
515
|
+
# License
|
|
382
516
|
|
|
383
517
|
MIT
|
|
@@ -5,8 +5,8 @@ mcp_use/logging.py,sha256=2-hSB7ZWcHEx_OFHNg8GIbSGCZx3MW4mZGGWxi2Ew3E,2690
|
|
|
5
5
|
mcp_use/session.py,sha256=Z4EZTUnQUX0QyGMzkJIrMRTX4SDk6qQUoBld408LIJE,3449
|
|
6
6
|
mcp_use/agents/__init__.py,sha256=ukchMTqCOID6ikvLmJ-6sldWTVFIzztGQo4BX6QeQr8,312
|
|
7
7
|
mcp_use/agents/base.py,sha256=bfuldi_89AbSbNc8KeTiCArRT9V62CNxHOWYkLHWjyA,1605
|
|
8
|
-
mcp_use/agents/langchain_agent.py,sha256=
|
|
9
|
-
mcp_use/agents/mcpagent.py,sha256=
|
|
8
|
+
mcp_use/agents/langchain_agent.py,sha256=5fml081T3meLkZxA8o29eLuMmITyr5EfkKMPGy9UgHA,10165
|
|
9
|
+
mcp_use/agents/mcpagent.py,sha256=YF-ApIGM2lM8mOdeopr-hPlMRuNRNMQpJpg4gm9u6Ns,14183
|
|
10
10
|
mcp_use/agents/prompts/default.py,sha256=tnwt9vOiVBhdpu-lIHhwEJo3rvE6EobPfUgS9JURBzg,941
|
|
11
11
|
mcp_use/connectors/__init__.py,sha256=jnd-7pPPJMb0UNJ6aD9lInj5Tlamc8lA_mFyG8RWJpo,385
|
|
12
12
|
mcp_use/connectors/base.py,sha256=TCLVNJdt6qrflmphgXOZhD6xPKQQegbGqe5REmcLYg0,4813
|
|
@@ -18,7 +18,7 @@ mcp_use/task_managers/base.py,sha256=ksNdxTwq8N-zqymxVoKGnWXq9iqkLYC61uB91o6Mh-4
|
|
|
18
18
|
mcp_use/task_managers/sse.py,sha256=WysmjwqRI3meXMZY_F4y9tSBMvSiUZfTJQfitM5l6jQ,2529
|
|
19
19
|
mcp_use/task_managers/stdio.py,sha256=DEISpXv4mo3d5a-WT8lkWbrXJwUh7QW0nMT_IM3fHGg,2269
|
|
20
20
|
mcp_use/task_managers/websocket.py,sha256=ZbCqdGgzCRtsXzRGFws-f2OzH8cPAkN4sJNDwEpRmCc,1915
|
|
21
|
-
mcp_use-1.
|
|
22
|
-
mcp_use-1.
|
|
23
|
-
mcp_use-1.
|
|
24
|
-
mcp_use-1.
|
|
21
|
+
mcp_use-1.1.4.dist-info/METADATA,sha256=vE5PNvtxt7MIOI5EL1DRA73xzNoGjEe2Xa7WfBdV9rU,14015
|
|
22
|
+
mcp_use-1.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
mcp_use-1.1.4.dist-info/licenses/LICENSE,sha256=7Pw7dbwJSBw8zH-WE03JnR5uXvitRtaGTP9QWPcexcs,1068
|
|
24
|
+
mcp_use-1.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|