mcp-use 1.0.0__tar.gz → 1.0.2__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.0 → mcp_use-1.0.2}/PKG-INFO +3 -2
- {mcp_use-1.0.0 → mcp_use-1.0.2}/README.md +2 -1
- mcp_use-1.0.2/docs/README.md +32 -0
- mcp_use-1.0.2/docs/api-reference/introduction.mdx +385 -0
- mcp_use-1.0.2/docs/development.mdx +135 -0
- mcp_use-1.0.2/docs/docs.json +74 -0
- mcp_use-1.0.2/docs/essentials/configuration.mdx +180 -0
- mcp_use-1.0.2/docs/essentials/connection-types.mdx +118 -0
- mcp_use-1.0.2/docs/essentials/llm-integration.mdx +26 -0
- mcp_use-1.0.2/docs/favicon.svg +14 -0
- mcp_use-1.0.2/docs/images/hero-dark.png +0 -0
- mcp_use-1.0.2/docs/images/hero-light.png +0 -0
- mcp_use-1.0.2/docs/introduction.mdx +39 -0
- mcp_use-1.0.2/docs/logo/dark.svg +12 -0
- mcp_use-1.0.2/docs/logo/light.svg +12 -0
- mcp_use-1.0.2/docs/quickstart.mdx +99 -0
- mcp_use-1.0.2/docs/snippets/snippet-intro.mdx +4 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/config.py +3 -3
- mcp_use-1.0.0/mcp_use/connectors/stdio.py → mcp_use-1.0.2/mcp_use/connectors/base.py +13 -62
- mcp_use-1.0.2/mcp_use/connectors/http.py +82 -0
- mcp_use-1.0.2/mcp_use/connectors/stdio.py +78 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/task_managers/__init__.py +2 -1
- mcp_use-1.0.2/mcp_use/task_managers/sse.py +82 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/task_managers/websocket.py +4 -4
- {mcp_use-1.0.0 → mcp_use-1.0.2}/pyproject.toml +1 -1
- mcp_use-1.0.2/pytest.ini +6 -0
- mcp_use-1.0.2/static/image.jpg +0 -0
- mcp_use-1.0.2/tests/conftest.py +37 -0
- mcp_use-1.0.2/tests/unit/test_client.py +471 -0
- mcp_use-1.0.2/tests/unit/test_config.py +135 -0
- mcp_use-1.0.2/tests/unit/test_http_connector.py +338 -0
- mcp_use-1.0.2/tests/unit/test_logging.py +117 -0
- mcp_use-1.0.2/tests/unit/test_session.py +174 -0
- mcp_use-1.0.2/tests/unit/test_stdio_connector.py +353 -0
- mcp_use-1.0.0/mcp_use/connectors/base.py +0 -59
- mcp_use-1.0.0/mcp_use/connectors/http.py +0 -210
- mcp_use-1.0.0/mcp_use/task_managers/http.py +0 -62
- mcp_use-1.0.0/static/image.jpg +0 -0
- mcp_use-1.0.0/tests/unit/test_placeholder.py +0 -16
- {mcp_use-1.0.0 → mcp_use-1.0.2}/.github/workflows/publish.yml +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/.github/workflows/tests.yml +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/.gitignore +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/.pre-commit-config.yaml +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/LICENSE +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/airbnb_mcp.json +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/airbnb_use.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/blender_use.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/browser_mcp.json +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/browser_use.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/chat_example.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/filesystem_use.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/examples/multi_server_example.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/__init__.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/agents/__init__.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/agents/base.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/agents/langchain_agent.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/agents/mcpagent.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/agents/prompts/default.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/client.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/connectors/__init__.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/connectors/websocket.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/logging.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/session.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/task_managers/base.py +0 -0
- {mcp_use-1.0.0 → mcp_use-1.0.2}/mcp_use/task_managers/stdio.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.2
|
|
4
4
|
Summary: MCP Library for LLMs
|
|
5
5
|
Author-email: Pietro Zullo <pietro.zullo@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -38,7 +38,7 @@ Requires-Dist: openai>=1.10.0; extra == 'openai'
|
|
|
38
38
|
Description-Content-Type: text/markdown
|
|
39
39
|
|
|
40
40
|
<picture>
|
|
41
|
-
<img alt="" src="./static/
|
|
41
|
+
<img alt="" src="./static/image.jpg" width="full">
|
|
42
42
|
</picture>
|
|
43
43
|
|
|
44
44
|
<h1 align="center">Open Source MCP CLient Library </h1>
|
|
@@ -47,6 +47,7 @@ Description-Content-Type: text/markdown
|
|
|
47
47
|
[](https://pypi.org/project/mcp_use/)
|
|
48
48
|
[](https://pypi.org/project/mcp_use/)
|
|
49
49
|
[](https://pypi.org/project/mcp_use/)
|
|
50
|
+
[](https://docs.mcp-use.io)
|
|
50
51
|
[](https://github.com/pietrozullo/mcp-use/blob/main/LICENSE)
|
|
51
52
|
[](https://github.com/astral-sh/ruff)
|
|
52
53
|
[](https://github.com/pietrozullo/mcp-use/stargazers)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<picture>
|
|
2
|
-
<img alt="" src="./static/
|
|
2
|
+
<img alt="" src="./static/image.jpg" width="full">
|
|
3
3
|
</picture>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">Open Source MCP CLient Library </h1>
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
[](https://pypi.org/project/mcp_use/)
|
|
9
9
|
[](https://pypi.org/project/mcp_use/)
|
|
10
10
|
[](https://pypi.org/project/mcp_use/)
|
|
11
|
+
[](https://docs.mcp-use.io)
|
|
11
12
|
[](https://github.com/pietrozullo/mcp-use/blob/main/LICENSE)
|
|
12
13
|
[](https://github.com/astral-sh/ruff)
|
|
13
14
|
[](https://github.com/pietrozullo/mcp-use/stargazers)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Mintlify Starter Kit
|
|
2
|
+
|
|
3
|
+
Click on `Use this template` to copy the Mintlify starter kit. The starter kit contains examples including
|
|
4
|
+
|
|
5
|
+
- Guide pages
|
|
6
|
+
- Navigation
|
|
7
|
+
- Customizations
|
|
8
|
+
- API Reference pages
|
|
9
|
+
- Use of popular components
|
|
10
|
+
|
|
11
|
+
### Development
|
|
12
|
+
|
|
13
|
+
Install the [Mintlify CLI](https://www.npmjs.com/package/mintlify) to preview the documentation changes locally. To install, use the following command
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm i -g mintlify
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Run the following command at the root of your documentation (where docs.json is)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
mintlify dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Publishing Changes
|
|
26
|
+
|
|
27
|
+
Install our Github App to auto propagate changes from your repo to your deployment. Changes will be deployed to production automatically after pushing to the default branch. Find the link to install on your dashboard.
|
|
28
|
+
|
|
29
|
+
#### Troubleshooting
|
|
30
|
+
|
|
31
|
+
- Mintlify dev isn't running - Run `mintlify install` it'll re-install dependencies.
|
|
32
|
+
- Page loads as a 404 - Make sure you are running in a folder with `docs.json`
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: API Reference
|
|
3
|
+
description: "Complete mcp_use API Documentation"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# API Reference
|
|
7
|
+
|
|
8
|
+
This section provides comprehensive documentation for the mcp_use API, including all components, methods, their arguments, and when to use different options.
|
|
9
|
+
|
|
10
|
+
## MCPClient
|
|
11
|
+
|
|
12
|
+
The `MCPClient` is the core class for interacting with MCP servers. It handles connection management, session creation, and communication with MCP servers.
|
|
13
|
+
|
|
14
|
+
### Initialization Methods
|
|
15
|
+
|
|
16
|
+
#### From Config File
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from mcp_use import MCPClient
|
|
20
|
+
|
|
21
|
+
client = MCPClient.from_config_file(config_path="config.json")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Parameter | Type | Required | Description |
|
|
25
|
+
| ------------- | ---- | -------- | ----------------------------------- |
|
|
26
|
+
| `config_path` | str | Yes | Path to the JSON configuration file |
|
|
27
|
+
|
|
28
|
+
#### From Dictionary
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from mcp_use import MCPClient
|
|
32
|
+
|
|
33
|
+
config = {
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"my_server": {
|
|
36
|
+
"command": "npx",
|
|
37
|
+
"args": ["@my-mcp/server"],
|
|
38
|
+
"env": {
|
|
39
|
+
"PORT": "3000"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
client = MCPClient.from_dict(config=config)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Parameter | Type | Required | Description |
|
|
49
|
+
| --------- | ---- | -------- | ---------------------------------------------- |
|
|
50
|
+
| `config` | dict | Yes | Dictionary containing MCP server configuration |
|
|
51
|
+
|
|
52
|
+
### Core Methods
|
|
53
|
+
|
|
54
|
+
#### create_session
|
|
55
|
+
|
|
56
|
+
Creates a new session with an MCP server.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
session = await client.create_session(server_name="my_server")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| Parameter | Type | Required | Default | Description |
|
|
63
|
+
| ------------- | ----- | -------- | ------- | --------------------------------------- |
|
|
64
|
+
| `server_name` | str | Yes | - | Name of the server as defined in config |
|
|
65
|
+
| `timeout` | float | No | 30.0 | Connection timeout in seconds |
|
|
66
|
+
| `retry_count` | int | No | 3 | Number of connection retry attempts |
|
|
67
|
+
|
|
68
|
+
**When to use**:
|
|
69
|
+
|
|
70
|
+
- Use a longer `timeout` for servers that take more time to initialize
|
|
71
|
+
- Increase `retry_count` in unstable network environments
|
|
72
|
+
- Use specific `server_name` when working with multiple servers in the same config
|
|
73
|
+
|
|
74
|
+
#### close_session
|
|
75
|
+
|
|
76
|
+
Closes a specific session.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
await client.close_session(session_id="session_id")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Parameter | Type | Required | Description |
|
|
83
|
+
| ------------ | ---- | -------- | -------------------------- |
|
|
84
|
+
| `session_id` | str | Yes | ID of the session to close |
|
|
85
|
+
|
|
86
|
+
#### close_all_sessions
|
|
87
|
+
|
|
88
|
+
Closes all active sessions.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
await client.close_all_sessions()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**When to use**:
|
|
95
|
+
|
|
96
|
+
- Always call this at the end of your application to clean up resources
|
|
97
|
+
- Use when switching between different tasks that require different servers
|
|
98
|
+
|
|
99
|
+
#### get_server
|
|
100
|
+
|
|
101
|
+
Gets a server instance by name.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
server = client.get_server(name="my_server")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
| Parameter | Type | Required | Description |
|
|
108
|
+
| --------- | ---- | -------- | --------------------------------------- |
|
|
109
|
+
| `name` | str | Yes | Name of the server as defined in config |
|
|
110
|
+
|
|
111
|
+
## MCPAgent
|
|
112
|
+
|
|
113
|
+
The `MCPAgent` class combines an LLM with an MCPClient to create an intelligent agent capable of using MCP tools.
|
|
114
|
+
|
|
115
|
+
### Initialization
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from mcp_use import MCPAgent, MCPClient
|
|
119
|
+
from langchain_openai import ChatOpenAI
|
|
120
|
+
|
|
121
|
+
agent = MCPAgent(
|
|
122
|
+
llm=ChatOpenAI(model="gpt-4o", temperature=0.7),
|
|
123
|
+
client=MCPClient.from_config_file("config.json"),
|
|
124
|
+
max_steps=30,
|
|
125
|
+
session_options={"timeout": 60.0},
|
|
126
|
+
auto_initialize=True,
|
|
127
|
+
memory_enabled=True,
|
|
128
|
+
system_prompt=None,
|
|
129
|
+
system_prompt_template=None,
|
|
130
|
+
additional_instructions=None
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
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 |
|
|
148
|
+
|
|
149
|
+
**When to use different parameters**:
|
|
150
|
+
|
|
151
|
+
- **llm**:
|
|
152
|
+
|
|
153
|
+
- mcp_use supports ANY LLM that is compatible with LangChain
|
|
154
|
+
- You can use models from OpenAI, Anthropic, Google, Mistral, Groq, Cohere, or any other provider with a LangChain integration
|
|
155
|
+
- You can even use open source models via LlamaCpp, HuggingFace, or other interfaces
|
|
156
|
+
- Custom or self-hosted models are also supported as long as they implement LangChain's interface
|
|
157
|
+
|
|
158
|
+
- **max_steps**:
|
|
159
|
+
|
|
160
|
+
- Increase for complex tasks that require many interactions
|
|
161
|
+
- Decrease for simpler tasks to improve efficiency
|
|
162
|
+
- Use higher values (50+) for web browsing or multi-stage tasks
|
|
163
|
+
- Use lower values (10-20) for targeted, specific tasks
|
|
164
|
+
|
|
165
|
+
- **system_prompt / system_prompt_template**:
|
|
166
|
+
|
|
167
|
+
- Use to customize the initial instructions given to the LLM
|
|
168
|
+
- Helps shape the agent's behavior and capabilities
|
|
169
|
+
- Use for specialized tasks or custom interaction patterns
|
|
170
|
+
|
|
171
|
+
- **memory_enabled**:
|
|
172
|
+
|
|
173
|
+
- Enable to maintain conversation history
|
|
174
|
+
- Disable for stateless operation or to save on token usage
|
|
175
|
+
|
|
176
|
+
- **session_options**:
|
|
177
|
+
- Customize timeout for long-running server operations
|
|
178
|
+
- Set retry parameters for unstable connections
|
|
179
|
+
|
|
180
|
+
### Core Methods
|
|
181
|
+
|
|
182
|
+
#### run
|
|
183
|
+
|
|
184
|
+
Runs the agent with a given query.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
result = await agent.run(
|
|
188
|
+
query="Find information about Python libraries",
|
|
189
|
+
max_steps=25,
|
|
190
|
+
stop_on_first_result=False
|
|
191
|
+
)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
| Parameter | Type | Required | Default | Description |
|
|
195
|
+
| ---------------------- | ---- | -------- | ------- | -------------------------------- |
|
|
196
|
+
| `query` | str | Yes | - | The query to run |
|
|
197
|
+
| `max_steps` | int | No | None | Overrides the instance max_steps |
|
|
198
|
+
| `stop_on_first_result` | bool | No | False | Whether to stop at first result |
|
|
199
|
+
| `server_name` | str | No | None | Specific server to use |
|
|
200
|
+
| `callbacks` | list | No | None | Callback functions for events |
|
|
201
|
+
|
|
202
|
+
**When to use different parameters**:
|
|
203
|
+
|
|
204
|
+
- **max_steps**: Override the instance default for specific queries
|
|
205
|
+
- **stop_on_first_result**: Use True for simple lookups, False for thorough exploration
|
|
206
|
+
- **server_name**: Specify when using multiple servers for different tasks
|
|
207
|
+
- **callbacks**: Add for monitoring or logging specific runs
|
|
208
|
+
|
|
209
|
+
#### reset
|
|
210
|
+
|
|
211
|
+
Resets the agent state.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
agent.reset()
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**When to use**:
|
|
218
|
+
|
|
219
|
+
- Between different tasks to clear context
|
|
220
|
+
- When starting a new conversation thread
|
|
221
|
+
- When agent gets stuck in a particular strategy
|
|
222
|
+
|
|
223
|
+
#### get_history
|
|
224
|
+
|
|
225
|
+
Gets the agent's interaction history.
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
history = agent.get_history()
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**When to use**:
|
|
232
|
+
|
|
233
|
+
- For debugging agent behavior
|
|
234
|
+
- When implementing custom logging
|
|
235
|
+
- To provide context for follow-up queries
|
|
236
|
+
|
|
237
|
+
## Configuration Details
|
|
238
|
+
|
|
239
|
+
### MCP Server Configuration Schema
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"mcpServers": {
|
|
244
|
+
"server_name": {
|
|
245
|
+
"command": "command_to_run",
|
|
246
|
+
"args": ["arg1", "arg2"],
|
|
247
|
+
"env": {
|
|
248
|
+
"ENV_VAR": "value"
|
|
249
|
+
},
|
|
250
|
+
"timeout": 30.0,
|
|
251
|
+
"retry": {
|
|
252
|
+
"max_attempts": 3,
|
|
253
|
+
"backoff_factor": 1.5
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
| Field | Type | Required | Description |
|
|
261
|
+
| ---------------------- | ------ | -------- | ------------------------------------ |
|
|
262
|
+
| `command` | string | Yes | The command to start the MCP server |
|
|
263
|
+
| `args` | array | No | Arguments to pass to the command |
|
|
264
|
+
| `env` | object | No | Environment variables for the server |
|
|
265
|
+
| `timeout` | number | No | Connection timeout in seconds |
|
|
266
|
+
| `retry` | object | No | Retry configuration |
|
|
267
|
+
| `retry.max_attempts` | number | No | Maximum retry attempts |
|
|
268
|
+
| `retry.backoff_factor` | number | No | Backoff multiplier between retries |
|
|
269
|
+
|
|
270
|
+
**When to use different options**:
|
|
271
|
+
|
|
272
|
+
- **command & args**: Vary based on the specific MCP server implementation
|
|
273
|
+
- **env**:
|
|
274
|
+
|
|
275
|
+
- Set environment-specific variables needed by the server
|
|
276
|
+
- Override default server settings (ports, directories)
|
|
277
|
+
- Set display settings for GUI-based servers
|
|
278
|
+
|
|
279
|
+
- **timeout**:
|
|
280
|
+
|
|
281
|
+
- Increase for servers with longer startup times
|
|
282
|
+
- Lower for simpler servers to fail fast
|
|
283
|
+
|
|
284
|
+
- **retry configuration**:
|
|
285
|
+
- Adjust for different network conditions
|
|
286
|
+
- Increase max_attempts in unstable environments
|
|
287
|
+
- Adjust backoff_factor based on server behavior
|
|
288
|
+
|
|
289
|
+
## Error Handling
|
|
290
|
+
|
|
291
|
+
mcp_use provides several exception types to handle different error scenarios:
|
|
292
|
+
|
|
293
|
+
| Exception | Description | When It Occurs |
|
|
294
|
+
| ------------------------ | --------------------------------- | ----------------------------------- |
|
|
295
|
+
| `MCPConnectionError` | Connection to MCP server failed | Network issues, server not running |
|
|
296
|
+
| `MCPAuthenticationError` | Authentication with server failed | Invalid credentials or tokens |
|
|
297
|
+
| `MCPTimeoutError` | Operation timed out | Server takes too long to respond |
|
|
298
|
+
| `MCPServerError` | Server returned an error | Internal server error |
|
|
299
|
+
| `MCPClientError` | Client-side error | Invalid configuration or parameters |
|
|
300
|
+
| `MCPError` | Generic MCP-related error | Any other MCP-related issue |
|
|
301
|
+
|
|
302
|
+
**Handling Strategies**:
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from mcp_use.exceptions import MCPConnectionError, MCPTimeoutError
|
|
306
|
+
|
|
307
|
+
try:
|
|
308
|
+
result = await agent.run("Find information")
|
|
309
|
+
except MCPConnectionError:
|
|
310
|
+
# Handle connection issues
|
|
311
|
+
print("Failed to connect to the MCP server")
|
|
312
|
+
except MCPTimeoutError:
|
|
313
|
+
# Handle timeout issues
|
|
314
|
+
print("Operation timed out")
|
|
315
|
+
except Exception as e:
|
|
316
|
+
# Handle other exceptions
|
|
317
|
+
print(f"An error occurred: {e}")
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Advanced Usage
|
|
321
|
+
|
|
322
|
+
### Multi-Server Configuration
|
|
323
|
+
|
|
324
|
+
Configure and use multiple MCP servers in a single application:
|
|
325
|
+
|
|
326
|
+
```python
|
|
327
|
+
from mcp_use import MCPClient, MCPAgent
|
|
328
|
+
from langchain_openai import ChatOpenAI
|
|
329
|
+
|
|
330
|
+
# Create client with multiple servers
|
|
331
|
+
client = MCPClient.from_dict({
|
|
332
|
+
"mcpServers": {
|
|
333
|
+
"browser": {
|
|
334
|
+
"command": "npx",
|
|
335
|
+
"args": ["@playwright/mcp@latest"]
|
|
336
|
+
},
|
|
337
|
+
"custom_server": {
|
|
338
|
+
"command": "python",
|
|
339
|
+
"args": ["-m", "my_custom_mcp_server"]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
# Create agent
|
|
345
|
+
agent = MCPAgent(llm=ChatOpenAI(model="gpt-4o"), client=client)
|
|
346
|
+
|
|
347
|
+
# Run with specific server
|
|
348
|
+
result_browser = await agent.run(
|
|
349
|
+
"Search the web for Python libraries",
|
|
350
|
+
server_name="browser"
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
# Run with different server
|
|
354
|
+
result_custom = await agent.run(
|
|
355
|
+
"Perform custom operation",
|
|
356
|
+
server_name="custom_server"
|
|
357
|
+
)
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Custom Output Parsing
|
|
361
|
+
|
|
362
|
+
Implement custom output parsers for specialized MCP servers:
|
|
363
|
+
|
|
364
|
+
```python
|
|
365
|
+
from langchain.schema import OutputParser
|
|
366
|
+
from mcp_use import MCPAgent, MCPClient
|
|
367
|
+
|
|
368
|
+
class CustomOutputParser(OutputParser):
|
|
369
|
+
def parse(self, text):
|
|
370
|
+
# Custom parsing logic
|
|
371
|
+
return processed_result
|
|
372
|
+
|
|
373
|
+
# Use the custom parser
|
|
374
|
+
agent = MCPAgent(
|
|
375
|
+
llm=llm,
|
|
376
|
+
client=client,
|
|
377
|
+
output_parser=CustomOutputParser()
|
|
378
|
+
)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
This approach is useful when:
|
|
382
|
+
|
|
383
|
+
- The MCP server returns structured data that needs special handling
|
|
384
|
+
- You need to extract specific information from responses
|
|
385
|
+
- You're integrating with custom or specialized MCP servers
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Development
|
|
3
|
+
description: "Contributing to mcp_use"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Development Guide
|
|
7
|
+
|
|
8
|
+
This guide will help you set up your development environment and contribute to mcp_use.
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
- Python 3.8 or higher
|
|
13
|
+
- Git
|
|
14
|
+
- Node.js and npm (for MCP server dependencies)
|
|
15
|
+
|
|
16
|
+
## Setting Up Development Environment
|
|
17
|
+
|
|
18
|
+
1. Clone the repository:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/pietrozullo/mcp-use.git
|
|
22
|
+
cd mcp-use
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Install development dependencies:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
3. Install pre-commit hooks:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pre-commit install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Code Style
|
|
38
|
+
|
|
39
|
+
mcp_use uses Ruff for code formatting and linting. The project follows these style guidelines:
|
|
40
|
+
|
|
41
|
+
- Use type hints for all function parameters and return values
|
|
42
|
+
- Follow PEP 8 style guide
|
|
43
|
+
- Use docstrings for all public functions and classes
|
|
44
|
+
- Keep functions focused and single-purpose
|
|
45
|
+
|
|
46
|
+
## Running Tests
|
|
47
|
+
|
|
48
|
+
The project uses pytest for testing. To run the test suite:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pytest
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For more specific test runs:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Run tests with coverage
|
|
58
|
+
pytest --cov=mcp_use
|
|
59
|
+
|
|
60
|
+
# Run specific test file
|
|
61
|
+
pytest tests/test_client.py
|
|
62
|
+
|
|
63
|
+
# Run tests with verbose output
|
|
64
|
+
pytest -v
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Documentation is written in MDX format and uses Mintlify for rendering. To preview documentation changes:
|
|
70
|
+
|
|
71
|
+
1. Install Mintlify CLI:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm i -g mintlify
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
2. Run the development server:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
mintlify dev
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
1. Create a new branch for your feature:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git checkout -b feature/your-feature-name
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
2. Make your changes and commit them:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git add .
|
|
95
|
+
git commit -m "Description of your changes"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
3. Push your changes and create a pull request:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
git push origin feature/your-feature-name
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Project Structure
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
mcp-use/
|
|
108
|
+
├── mcp_use/ # Main package code
|
|
109
|
+
├── tests/ # Test files
|
|
110
|
+
├── examples/ # Example usage
|
|
111
|
+
├── docs/ # Documentation
|
|
112
|
+
├── static/ # Static assets
|
|
113
|
+
└── pyproject.toml # Project configuration
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Adding New MCP Servers
|
|
117
|
+
|
|
118
|
+
To add support for a new MCP server:
|
|
119
|
+
|
|
120
|
+
1. Create a new configuration template in the examples directory
|
|
121
|
+
2. Add necessary server-specific code in the `mcp_use` package
|
|
122
|
+
3. Update documentation with new server information
|
|
123
|
+
4. Add tests for the new server functionality
|
|
124
|
+
|
|
125
|
+
## Release Process
|
|
126
|
+
|
|
127
|
+
1. Update version in `pyproject.toml`
|
|
128
|
+
2. Update CHANGELOG.md
|
|
129
|
+
3. Create a new release tag
|
|
130
|
+
4. Build and publish to PyPI:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
python -m build
|
|
134
|
+
python -m twine upload dist/*
|
|
135
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://mintlify.com/docs.json",
|
|
3
|
+
"theme": "mint",
|
|
4
|
+
"name": "mcp_use",
|
|
5
|
+
"colors": {
|
|
6
|
+
"primary": "#062c24",
|
|
7
|
+
"light": "#55e4c8",
|
|
8
|
+
"dark": "#000000"
|
|
9
|
+
},
|
|
10
|
+
"favicon": "/favicon.svg",
|
|
11
|
+
"navigation": {
|
|
12
|
+
"tabs": [
|
|
13
|
+
{
|
|
14
|
+
"tab": "Documentation",
|
|
15
|
+
"groups": [
|
|
16
|
+
{
|
|
17
|
+
"group": "Getting Started",
|
|
18
|
+
"pages": ["introduction", "quickstart"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"group": "Essentials",
|
|
22
|
+
"pages": ["essentials/configuration", "essentials/llm-integration"]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"group": "API Reference",
|
|
26
|
+
"pages": ["api-reference/introduction"]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"group": "Development",
|
|
30
|
+
"pages": ["development"]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"logo": {
|
|
37
|
+
"light": "/logo/light.svg",
|
|
38
|
+
"dark": "/logo/dark.svg"
|
|
39
|
+
},
|
|
40
|
+
"navbar": {
|
|
41
|
+
"links": [
|
|
42
|
+
{
|
|
43
|
+
"label": "GitHub",
|
|
44
|
+
"href": "https://github.com/pietrozullo/mcp-use"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"footer": {
|
|
49
|
+
"socials": {
|
|
50
|
+
"github": "https://github.com/pietrozullo/mcp-use"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"anchors": [
|
|
54
|
+
{
|
|
55
|
+
"name": "Documentation",
|
|
56
|
+
"icon": "book-open",
|
|
57
|
+
"url": "/"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "API Reference",
|
|
61
|
+
"icon": "code",
|
|
62
|
+
"url": "/api-reference"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "Development",
|
|
66
|
+
"icon": "code-branch",
|
|
67
|
+
"url": "/development"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"feedback": {
|
|
71
|
+
"suggestEdit": true,
|
|
72
|
+
"raiseIssue": true
|
|
73
|
+
}
|
|
74
|
+
}
|