mcp-use 1.0.2__py3-none-any.whl → 1.0.3__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.0.3.dist-info}/METADATA +40 -7
- {mcp_use-1.0.2.dist-info → mcp_use-1.0.3.dist-info}/RECORD +6 -6
- {mcp_use-1.0.2.dist-info → mcp_use-1.0.3.dist-info}/WHEEL +0 -0
- {mcp_use-1.0.2.dist-info → mcp_use-1.0.3.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.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
|
|
@@ -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.0.
|
|
22
|
-
mcp_use-1.0.
|
|
23
|
-
mcp_use-1.0.
|
|
24
|
-
mcp_use-1.0.
|
|
21
|
+
mcp_use-1.0.3.dist-info/METADATA,sha256=3HbO5h9azPZyPz6HmK0rWZEB7pdxh4U3jCSEQKtGdtc,11043
|
|
22
|
+
mcp_use-1.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
mcp_use-1.0.3.dist-info/licenses/LICENSE,sha256=7Pw7dbwJSBw8zH-WE03JnR5uXvitRtaGTP9QWPcexcs,1068
|
|
24
|
+
mcp_use-1.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|