mcp-use 0.1.0__py3-none-any.whl → 1.0.1__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/__init__.py +6 -6
- mcp_use/agents/langchain_agent.py +88 -64
- mcp_use/agents/mcpagent.py +216 -52
- mcp_use/agents/prompts/default.py +22 -0
- mcp_use/client.py +93 -68
- mcp_use/config.py +3 -57
- mcp_use/connectors/base.py +94 -16
- mcp_use/connectors/http.py +51 -95
- mcp_use/connectors/stdio.py +38 -84
- mcp_use/connectors/websocket.py +124 -21
- mcp_use/session.py +0 -55
- mcp_use/task_managers/__init__.py +19 -0
- mcp_use/task_managers/base.py +151 -0
- mcp_use/task_managers/sse.py +82 -0
- mcp_use/task_managers/stdio.py +73 -0
- mcp_use/task_managers/websocket.py +63 -0
- mcp_use-1.0.1.dist-info/METADATA +383 -0
- mcp_use-1.0.1.dist-info/RECORD +24 -0
- {mcp_use-0.1.0.dist-info → mcp_use-1.0.1.dist-info}/WHEEL +1 -2
- mcp_use/tools/__init__.py +0 -11
- mcp_use/tools/converter.py +0 -108
- mcp_use/tools/formats.py +0 -181
- mcp_use/types.py +0 -33
- mcp_use-0.1.0.dist-info/METADATA +0 -287
- mcp_use-0.1.0.dist-info/RECORD +0 -23
- mcp_use-0.1.0.dist-info/top_level.txt +0 -1
- {mcp_use-0.1.0.dist-info → mcp_use-1.0.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SSE connection management for MCP implementations.
|
|
3
|
+
|
|
4
|
+
This module provides a connection manager for SSE-based MCP connections
|
|
5
|
+
that ensures proper task isolation and resource cleanup.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from mcp.client.sse import sse_client
|
|
11
|
+
|
|
12
|
+
from ..logging import logger
|
|
13
|
+
from .base import ConnectionManager
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SseConnectionManager(ConnectionManager[tuple[Any, Any]]):
|
|
17
|
+
"""Connection manager for SSE-based MCP connections.
|
|
18
|
+
|
|
19
|
+
This class handles the proper task isolation for sse_client context managers
|
|
20
|
+
to prevent the "cancel scope in different task" error. It runs the sse_client
|
|
21
|
+
in a dedicated task and manages its lifecycle.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
url: str,
|
|
27
|
+
headers: dict[str, str] | None = None,
|
|
28
|
+
timeout: float = 5,
|
|
29
|
+
sse_read_timeout: float = 60 * 5,
|
|
30
|
+
):
|
|
31
|
+
"""Initialize a new SSE connection manager.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
url: The SSE endpoint URL
|
|
35
|
+
headers: Optional HTTP headers
|
|
36
|
+
timeout: Timeout for HTTP operations in seconds
|
|
37
|
+
sse_read_timeout: Timeout for SSE read operations in seconds
|
|
38
|
+
"""
|
|
39
|
+
super().__init__()
|
|
40
|
+
self.url = url
|
|
41
|
+
self.headers = headers or {}
|
|
42
|
+
self.timeout = timeout
|
|
43
|
+
self.sse_read_timeout = sse_read_timeout
|
|
44
|
+
self._sse_ctx = None
|
|
45
|
+
|
|
46
|
+
async def _establish_connection(self) -> tuple[Any, Any]:
|
|
47
|
+
"""Establish an SSE connection.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
A tuple of (read_stream, write_stream)
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
Exception: If connection cannot be established.
|
|
54
|
+
"""
|
|
55
|
+
# Create the context manager
|
|
56
|
+
self._sse_ctx = sse_client(
|
|
57
|
+
url=self.url,
|
|
58
|
+
headers=self.headers,
|
|
59
|
+
timeout=self.timeout,
|
|
60
|
+
sse_read_timeout=self.sse_read_timeout,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Enter the context manager
|
|
64
|
+
read_stream, write_stream = await self._sse_ctx.__aenter__()
|
|
65
|
+
|
|
66
|
+
# Return the streams
|
|
67
|
+
return (read_stream, write_stream)
|
|
68
|
+
|
|
69
|
+
async def _close_connection(self, connection: tuple[Any, Any]) -> None:
|
|
70
|
+
"""Close the SSE connection.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
connection: The connection to close (ignored, we use the context manager)
|
|
74
|
+
"""
|
|
75
|
+
if self._sse_ctx:
|
|
76
|
+
# Exit the context manager
|
|
77
|
+
try:
|
|
78
|
+
await self._sse_ctx.__aexit__(None, None, None)
|
|
79
|
+
except Exception as e:
|
|
80
|
+
logger.warning(f"Error closing SSE context: {e}")
|
|
81
|
+
finally:
|
|
82
|
+
self._sse_ctx = None
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""
|
|
2
|
+
StdIO connection management for MCP implementations.
|
|
3
|
+
|
|
4
|
+
This module provides a connection manager for stdio-based MCP connections
|
|
5
|
+
that ensures proper task isolation and resource cleanup.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Any, TextIO
|
|
10
|
+
|
|
11
|
+
from mcp import StdioServerParameters
|
|
12
|
+
from mcp.client.stdio import stdio_client
|
|
13
|
+
|
|
14
|
+
from ..logging import logger
|
|
15
|
+
from .base import ConnectionManager
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class StdioConnectionManager(ConnectionManager[tuple[Any, Any]]):
|
|
19
|
+
"""Connection manager for stdio-based MCP connections.
|
|
20
|
+
|
|
21
|
+
This class handles the proper task isolation for stdio_client context managers
|
|
22
|
+
to prevent the "cancel scope in different task" error. It runs the stdio_client
|
|
23
|
+
in a dedicated task and manages its lifecycle.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
server_params: StdioServerParameters,
|
|
29
|
+
errlog: TextIO = sys.stderr,
|
|
30
|
+
):
|
|
31
|
+
"""Initialize a new stdio connection manager.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
server_params: The parameters for the stdio server
|
|
35
|
+
errlog: The error log stream
|
|
36
|
+
"""
|
|
37
|
+
super().__init__()
|
|
38
|
+
self.server_params = server_params
|
|
39
|
+
self.errlog = errlog
|
|
40
|
+
self._stdio_ctx = None
|
|
41
|
+
|
|
42
|
+
async def _establish_connection(self) -> tuple[Any, Any]:
|
|
43
|
+
"""Establish a stdio connection.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
A tuple of (read_stream, write_stream)
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
Exception: If connection cannot be established.
|
|
50
|
+
"""
|
|
51
|
+
# Create the context manager
|
|
52
|
+
self._stdio_ctx = stdio_client(self.server_params, self.errlog)
|
|
53
|
+
|
|
54
|
+
# Enter the context manager
|
|
55
|
+
read_stream, write_stream = await self._stdio_ctx.__aenter__()
|
|
56
|
+
|
|
57
|
+
# Return the streams
|
|
58
|
+
return (read_stream, write_stream)
|
|
59
|
+
|
|
60
|
+
async def _close_connection(self, connection: tuple[Any, Any]) -> None:
|
|
61
|
+
"""Close the stdio connection.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
connection: The connection to close (ignored, we use the context manager)
|
|
65
|
+
"""
|
|
66
|
+
if self._stdio_ctx:
|
|
67
|
+
# Exit the context manager
|
|
68
|
+
try:
|
|
69
|
+
await self._stdio_ctx.__aexit__(None, None, None)
|
|
70
|
+
except Exception as e:
|
|
71
|
+
logger.warning(f"Error closing stdio context: {e}")
|
|
72
|
+
finally:
|
|
73
|
+
self._stdio_ctx = None
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WebSocket connection management for MCP implementations.
|
|
3
|
+
|
|
4
|
+
This module provides a connection manager for WebSocket-based MCP connections.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import websockets
|
|
8
|
+
from websockets.client import ClientConnection
|
|
9
|
+
|
|
10
|
+
from ..logging import logger
|
|
11
|
+
from .base import ConnectionManager
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WebSocketConnectionManager(ConnectionManager[ClientConnection]):
|
|
15
|
+
"""Connection manager for WebSocket-based MCP connections.
|
|
16
|
+
|
|
17
|
+
This class handles the lifecycle of WebSocket connections, ensuring proper
|
|
18
|
+
connection establishment and cleanup.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
url: str,
|
|
24
|
+
headers: dict[str, str] | None = None,
|
|
25
|
+
):
|
|
26
|
+
"""Initialize a new WebSocket connection manager.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
url: The WebSocket URL to connect to
|
|
30
|
+
headers: Optional headers to include in the WebSocket connection
|
|
31
|
+
"""
|
|
32
|
+
super().__init__()
|
|
33
|
+
self.url = url
|
|
34
|
+
self.headers = headers or {}
|
|
35
|
+
|
|
36
|
+
async def _establish_connection(self) -> ClientConnection:
|
|
37
|
+
"""Establish a WebSocket connection.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The established WebSocket connection
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
Exception: If connection cannot be established
|
|
44
|
+
"""
|
|
45
|
+
logger.debug(f"Connecting to WebSocket: {self.url}")
|
|
46
|
+
try:
|
|
47
|
+
ws = await websockets.connect(self.url, extra_headers=self.headers)
|
|
48
|
+
return ws
|
|
49
|
+
except Exception as e:
|
|
50
|
+
logger.error(f"Failed to connect to WebSocket: {e}")
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
async def _close_connection(self, connection: ClientConnection) -> None:
|
|
54
|
+
"""Close the WebSocket connection.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
connection: The WebSocket connection to close
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
logger.debug("Closing WebSocket connection")
|
|
61
|
+
await connection.close()
|
|
62
|
+
except Exception as e:
|
|
63
|
+
logger.warning(f"Error closing WebSocket connection: {e}")
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-use
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: MCP Library for LLMs
|
|
5
|
+
Author-email: Pietro Zullo <pietro.zullo@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
18
|
+
Requires-Dist: jsonschema-pydantic>=0.1.0
|
|
19
|
+
Requires-Dist: langchain-community>=0.0.10
|
|
20
|
+
Requires-Dist: langchain>=0.1.0
|
|
21
|
+
Requires-Dist: mcp
|
|
22
|
+
Requires-Dist: pydantic>=2.0.0
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
24
|
+
Requires-Dist: typing-extensions>=4.8.0
|
|
25
|
+
Requires-Dist: websockets>=12.0
|
|
26
|
+
Provides-Extra: anthropic
|
|
27
|
+
Requires-Dist: anthropic>=0.15.0; extra == 'anthropic'
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: black>=23.9.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.5.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
36
|
+
Provides-Extra: openai
|
|
37
|
+
Requires-Dist: openai>=1.10.0; extra == 'openai'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
<picture>
|
|
41
|
+
<img alt="" src="./static/image.jpg" width="full">
|
|
42
|
+
</picture>
|
|
43
|
+
|
|
44
|
+
<h1 align="center">Open Source MCP CLient Library </h1>
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/mcp_use/)
|
|
47
|
+
[](https://pypi.org/project/mcp_use/)
|
|
48
|
+
[](https://pypi.org/project/mcp_use/)
|
|
49
|
+
[](https://pypi.org/project/mcp_use/)
|
|
50
|
+
[](https://docs.mcp-use.io)
|
|
51
|
+
[](https://github.com/pietrozullo/mcp-use/blob/main/LICENSE)
|
|
52
|
+
[](https://github.com/astral-sh/ruff)
|
|
53
|
+
[](https://github.com/pietrozullo/mcp-use/stargazers)
|
|
54
|
+
|
|
55
|
+
🌐 MCP-Use is the open source way to connect any LLM to MCP tools and build custom agents that have tool access, without using closed source or application clients.
|
|
56
|
+
|
|
57
|
+
💡 Let developers easily connect any LLM to tools like web browsing, file operations, and more.
|
|
58
|
+
|
|
59
|
+
# Quick start
|
|
60
|
+
|
|
61
|
+
With pip:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install mcp-use
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or install from source:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git clone https://github.com/pietrozullo/mcp-use.git
|
|
71
|
+
cd mcp-use
|
|
72
|
+
pip install -e .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Spin up your agent:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
import os
|
|
80
|
+
from dotenv import load_dotenv
|
|
81
|
+
from langchain_openai import ChatOpenAI
|
|
82
|
+
from mcp_use import MCPAgent, MCPClient
|
|
83
|
+
|
|
84
|
+
async def main():
|
|
85
|
+
# Load environment variables
|
|
86
|
+
load_dotenv()
|
|
87
|
+
|
|
88
|
+
# Create MCPClient from config file
|
|
89
|
+
client = MCPClient.from_config_file("browser_mcp.json")
|
|
90
|
+
|
|
91
|
+
# Create LLM
|
|
92
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
93
|
+
|
|
94
|
+
# Create agent with the client
|
|
95
|
+
agent = MCPAgent(llm=llm, client=client, max_steps=30)
|
|
96
|
+
|
|
97
|
+
# Run the query
|
|
98
|
+
result = await agent.run(
|
|
99
|
+
"Find the best restaurant in San Francisco USING GOOGLE SEARCH",
|
|
100
|
+
)
|
|
101
|
+
print(f"\nResult: {result}")
|
|
102
|
+
|
|
103
|
+
if __name__ == "__main__":
|
|
104
|
+
asyncio.run(main())
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Example configuration file (`browser_mcp.json`):
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"mcpServers": {
|
|
112
|
+
"playwright": {
|
|
113
|
+
"command": "npx",
|
|
114
|
+
"args": ["@playwright/mcp@latest"],
|
|
115
|
+
"env": {
|
|
116
|
+
"DISPLAY": ":1"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
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
|
+
For other settings, models, and more, check out the documentation.
|
|
131
|
+
|
|
132
|
+
# Example Use Cases
|
|
133
|
+
|
|
134
|
+
## Web Browsing with Playwright
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import asyncio
|
|
138
|
+
import os
|
|
139
|
+
from dotenv import load_dotenv
|
|
140
|
+
from langchain_openai import ChatOpenAI
|
|
141
|
+
from mcp_use import MCPAgent, MCPClient
|
|
142
|
+
|
|
143
|
+
async def main():
|
|
144
|
+
# Load environment variables
|
|
145
|
+
load_dotenv()
|
|
146
|
+
|
|
147
|
+
# Create MCPClient from config file
|
|
148
|
+
client = MCPClient.from_config_file(
|
|
149
|
+
os.path.join(os.path.dirname(__file__), "browser_mcp.json")
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# Create LLM
|
|
153
|
+
llm = ChatOpenAI(model="gpt-4o")
|
|
154
|
+
# Alternative models:
|
|
155
|
+
# llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")
|
|
156
|
+
# llm = ChatGroq(model="llama3-8b-8192")
|
|
157
|
+
|
|
158
|
+
# Create agent with the client
|
|
159
|
+
agent = MCPAgent(llm=llm, client=client, max_steps=30)
|
|
160
|
+
|
|
161
|
+
# Run the query
|
|
162
|
+
result = await agent.run(
|
|
163
|
+
"Find the best restaurant in San Francisco USING GOOGLE SEARCH",
|
|
164
|
+
max_steps=30,
|
|
165
|
+
)
|
|
166
|
+
print(f"\nResult: {result}")
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
asyncio.run(main())
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Airbnb Search
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
import asyncio
|
|
176
|
+
import os
|
|
177
|
+
from dotenv import load_dotenv
|
|
178
|
+
from langchain_anthropic import ChatAnthropic
|
|
179
|
+
from mcp_use import MCPAgent, MCPClient
|
|
180
|
+
|
|
181
|
+
async def run_airbnb_example():
|
|
182
|
+
# Load environment variables
|
|
183
|
+
load_dotenv()
|
|
184
|
+
|
|
185
|
+
# Create MCPClient with Airbnb configuration
|
|
186
|
+
client = MCPClient.from_config_file(
|
|
187
|
+
os.path.join(os.path.dirname(__file__), "airbnb_mcp.json")
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Create LLM - you can choose between different models
|
|
191
|
+
llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")
|
|
192
|
+
|
|
193
|
+
# Create agent with the client
|
|
194
|
+
agent = MCPAgent(llm=llm, client=client, max_steps=30)
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
# Run a query to search for accommodations
|
|
198
|
+
result = await agent.run(
|
|
199
|
+
"Find me a nice place to stay in Barcelona for 2 adults "
|
|
200
|
+
"for a week in August. I prefer places with a pool and "
|
|
201
|
+
"good reviews. Show me the top 3 options.",
|
|
202
|
+
max_steps=30,
|
|
203
|
+
)
|
|
204
|
+
print(f"\nResult: {result}")
|
|
205
|
+
finally:
|
|
206
|
+
# Ensure we clean up resources properly
|
|
207
|
+
if client.sessions:
|
|
208
|
+
await client.close_all_sessions()
|
|
209
|
+
|
|
210
|
+
if __name__ == "__main__":
|
|
211
|
+
asyncio.run(run_airbnb_example())
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Example configuration file (`airbnb_mcp.json`):
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"mcpServers": {
|
|
219
|
+
"airbnb": {
|
|
220
|
+
"command": "npx",
|
|
221
|
+
"args": ["-y", "@openbnb/mcp-server-airbnb"]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Blender 3D Creation
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
import asyncio
|
|
231
|
+
from dotenv import load_dotenv
|
|
232
|
+
from langchain_anthropic import ChatAnthropic
|
|
233
|
+
from mcp_use import MCPAgent, MCPClient
|
|
234
|
+
|
|
235
|
+
async def run_blender_example():
|
|
236
|
+
# Load environment variables
|
|
237
|
+
load_dotenv()
|
|
238
|
+
|
|
239
|
+
# Create MCPClient with Blender MCP configuration
|
|
240
|
+
config = {"mcpServers": {"blender": {"command": "uvx", "args": ["blender-mcp"]}}}
|
|
241
|
+
client = MCPClient.from_dict(config)
|
|
242
|
+
|
|
243
|
+
# Create LLM
|
|
244
|
+
llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")
|
|
245
|
+
|
|
246
|
+
# Create agent with the client
|
|
247
|
+
agent = MCPAgent(llm=llm, client=client, max_steps=30)
|
|
248
|
+
|
|
249
|
+
try:
|
|
250
|
+
# Run the query
|
|
251
|
+
result = await agent.run(
|
|
252
|
+
"Create an inflatable cube with soft material and a plane as ground.",
|
|
253
|
+
max_steps=30,
|
|
254
|
+
)
|
|
255
|
+
print(f"\nResult: {result}")
|
|
256
|
+
finally:
|
|
257
|
+
# Ensure we clean up resources properly
|
|
258
|
+
if client.sessions:
|
|
259
|
+
await client.close_all_sessions()
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
asyncio.run(run_blender_example())
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
# Configuration File Support
|
|
266
|
+
|
|
267
|
+
MCP-Use supports initialization from configuration files, making it easy to manage and switch between different MCP server setups:
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
import asyncio
|
|
271
|
+
from mcp_use import create_session_from_config
|
|
272
|
+
|
|
273
|
+
async def main():
|
|
274
|
+
# Create an MCP session from a config file
|
|
275
|
+
session = create_session_from_config("mcp-config.json")
|
|
276
|
+
|
|
277
|
+
# Initialize the session
|
|
278
|
+
await session.initialize()
|
|
279
|
+
|
|
280
|
+
# Use the session...
|
|
281
|
+
|
|
282
|
+
# Disconnect when done
|
|
283
|
+
await session.disconnect()
|
|
284
|
+
|
|
285
|
+
if __name__ == "__main__":
|
|
286
|
+
asyncio.run(main())
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
# Multi-Server Support
|
|
290
|
+
|
|
291
|
+
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.
|
|
292
|
+
|
|
293
|
+
## Configuration
|
|
294
|
+
|
|
295
|
+
You can configure multiple servers in your configuration file:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"mcpServers": {
|
|
300
|
+
"airbnb": {
|
|
301
|
+
"command": "npx",
|
|
302
|
+
"args": ["-y", "@openbnb/mcp-server-airbnb", "--ignore-robots-txt"]
|
|
303
|
+
},
|
|
304
|
+
"playwright": {
|
|
305
|
+
"command": "npx",
|
|
306
|
+
"args": ["@playwright/mcp@latest"],
|
|
307
|
+
"env": {
|
|
308
|
+
"DISPLAY": ":1"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Usage
|
|
316
|
+
|
|
317
|
+
The `MCPClient` class provides several methods for managing multiple servers:
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
import asyncio
|
|
321
|
+
from mcp_use import MCPClient, MCPAgent
|
|
322
|
+
from langchain_anthropic import ChatAnthropic
|
|
323
|
+
|
|
324
|
+
async def main():
|
|
325
|
+
# Create client with multiple servers
|
|
326
|
+
client = MCPClient.from_config_file("multi_server_config.json")
|
|
327
|
+
|
|
328
|
+
# Create agent with the client
|
|
329
|
+
agent = MCPAgent(
|
|
330
|
+
llm=ChatAnthropic(model="claude-3-5-sonnet-20240620"),
|
|
331
|
+
client=client
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
try:
|
|
335
|
+
# Run a query that uses tools from multiple servers
|
|
336
|
+
result = await agent.run(
|
|
337
|
+
"Search for a nice place to stay in Barcelona on Airbnb, "
|
|
338
|
+
"then use Google to find nearby restaurants and attractions."
|
|
339
|
+
)
|
|
340
|
+
print(result)
|
|
341
|
+
finally:
|
|
342
|
+
# Clean up all sessions
|
|
343
|
+
await client.close_all_sessions()
|
|
344
|
+
|
|
345
|
+
if __name__ == "__main__":
|
|
346
|
+
asyncio.run(main())
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Roadmap
|
|
350
|
+
|
|
351
|
+
<ul>
|
|
352
|
+
<li>[x] Multiple Servers at once </li>
|
|
353
|
+
<li>[ ] Test remote connectors (http, ws)</li>
|
|
354
|
+
<li>[ ] ... </li>
|
|
355
|
+
</ul>
|
|
356
|
+
|
|
357
|
+
## Contributing
|
|
358
|
+
|
|
359
|
+
We love contributions! Feel free to open issues for bugs or feature requests.
|
|
360
|
+
|
|
361
|
+
## Requirements
|
|
362
|
+
|
|
363
|
+
- Python 3.11+
|
|
364
|
+
- MCP implementation (like Playwright MCP)
|
|
365
|
+
- LangChain and appropriate model libraries (OpenAI, Anthropic, etc.)
|
|
366
|
+
|
|
367
|
+
## Citation
|
|
368
|
+
|
|
369
|
+
If you use MCP-Use in your research or project, please cite:
|
|
370
|
+
|
|
371
|
+
```bibtex
|
|
372
|
+
@software{mcp_use2025,
|
|
373
|
+
author = {Zullo, Pietro},
|
|
374
|
+
title = {MCP-Use: MCP Library for Python},
|
|
375
|
+
year = {2025},
|
|
376
|
+
publisher = {GitHub},
|
|
377
|
+
url = {https://github.com/pietrozullo/mcp-use}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
mcp_use/__init__.py,sha256=PSoxLAu1GPjfIDPcZiJyI3k66MMS3lcfx5kERUgFb1o,723
|
|
2
|
+
mcp_use/client.py,sha256=0rvlJBwvPD19sjDRtXfnp15-F1VHJlXWxLQNt9cHwPA,8275
|
|
3
|
+
mcp_use/config.py,sha256=O9V4pa-shZ2mPokRTrd7KZQ2GpuTcYBGUslefl1fosw,1653
|
|
4
|
+
mcp_use/logging.py,sha256=2-hSB7ZWcHEx_OFHNg8GIbSGCZx3MW4mZGGWxi2Ew3E,2690
|
|
5
|
+
mcp_use/session.py,sha256=Z4EZTUnQUX0QyGMzkJIrMRTX4SDk6qQUoBld408LIJE,3449
|
|
6
|
+
mcp_use/agents/__init__.py,sha256=ukchMTqCOID6ikvLmJ-6sldWTVFIzztGQo4BX6QeQr8,312
|
|
7
|
+
mcp_use/agents/base.py,sha256=bfuldi_89AbSbNc8KeTiCArRT9V62CNxHOWYkLHWjyA,1605
|
|
8
|
+
mcp_use/agents/langchain_agent.py,sha256=q6zIb9J9fc15HRGDjPAhmPdM_8UOqQToy8ESeyry1kc,10035
|
|
9
|
+
mcp_use/agents/mcpagent.py,sha256=lTRutdT1QIMiTbMSKfSbqlqNq_Y6uDPfkjAzJAKb6H0,12727
|
|
10
|
+
mcp_use/agents/prompts/default.py,sha256=tnwt9vOiVBhdpu-lIHhwEJo3rvE6EobPfUgS9JURBzg,941
|
|
11
|
+
mcp_use/connectors/__init__.py,sha256=jnd-7pPPJMb0UNJ6aD9lInj5Tlamc8lA_mFyG8RWJpo,385
|
|
12
|
+
mcp_use/connectors/base.py,sha256=TCLVNJdt6qrflmphgXOZhD6xPKQQegbGqe5REmcLYg0,4813
|
|
13
|
+
mcp_use/connectors/http.py,sha256=vNrVOjO_7SLJv_G6Gio3moRu11omKY6nM3_34yUMpew,2839
|
|
14
|
+
mcp_use/connectors/stdio.py,sha256=36yEY7hbFXgM7zju5BtLJl4cKAZNCXVRrTaU6YOttBI,2606
|
|
15
|
+
mcp_use/connectors/websocket.py,sha256=4xqxl9UncrfU6NitvKfB80Hk2g7o0Gc0G5sm6sY3RAk,9534
|
|
16
|
+
mcp_use/task_managers/__init__.py,sha256=4dgW5N61iiPLpwjU2rrn_uqrL8mmDJFDaF9Lukzk65A,486
|
|
17
|
+
mcp_use/task_managers/base.py,sha256=ksNdxTwq8N-zqymxVoKGnWXq9iqkLYC61uB91o6Mh-4,4888
|
|
18
|
+
mcp_use/task_managers/sse.py,sha256=WysmjwqRI3meXMZY_F4y9tSBMvSiUZfTJQfitM5l6jQ,2529
|
|
19
|
+
mcp_use/task_managers/stdio.py,sha256=DEISpXv4mo3d5a-WT8lkWbrXJwUh7QW0nMT_IM3fHGg,2269
|
|
20
|
+
mcp_use/task_managers/websocket.py,sha256=ZbCqdGgzCRtsXzRGFws-f2OzH8cPAkN4sJNDwEpRmCc,1915
|
|
21
|
+
mcp_use-1.0.1.dist-info/METADATA,sha256=BZm7Zn7K33DKE2fLzRgDPl-oTpQRAuKW3ssxNkpEsxA,10203
|
|
22
|
+
mcp_use-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
23
|
+
mcp_use-1.0.1.dist-info/licenses/LICENSE,sha256=7Pw7dbwJSBw8zH-WE03JnR5uXvitRtaGTP9QWPcexcs,1068
|
|
24
|
+
mcp_use-1.0.1.dist-info/RECORD,,
|
mcp_use/tools/__init__.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Tool conversion utilities.
|
|
3
|
-
|
|
4
|
-
This module provides utilities for converting between MCP tool schemas
|
|
5
|
-
and LLM-specific tool formats.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from .converter import ToolConverter
|
|
9
|
-
from .formats import AnthropicToolFormat, OpenAIToolFormat, ToolFormat
|
|
10
|
-
|
|
11
|
-
__all__ = ["ToolConverter", "ToolFormat", "OpenAIToolFormat", "AnthropicToolFormat"]
|