mcp-use 0.1.0__tar.gz → 1.0.1__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/.github/workflows/publish.yml +78 -0
- mcp_use-1.0.1/.github/workflows/tests.yml +31 -0
- mcp_use-1.0.1/.gitignore +124 -0
- mcp_use-1.0.1/.pre-commit-config.yaml +24 -0
- mcp_use-1.0.1/PKG-INFO +383 -0
- mcp_use-1.0.1/README.md +344 -0
- mcp_use-1.0.1/docs/README.md +32 -0
- mcp_use-1.0.1/docs/api-reference/introduction.mdx +385 -0
- mcp_use-1.0.1/docs/development.mdx +135 -0
- mcp_use-1.0.1/docs/docs.json +74 -0
- mcp_use-1.0.1/docs/essentials/configuration.mdx +180 -0
- mcp_use-1.0.1/docs/essentials/connection-types.mdx +118 -0
- mcp_use-1.0.1/docs/essentials/llm-integration.mdx +26 -0
- mcp_use-1.0.1/docs/favicon.svg +14 -0
- mcp_use-1.0.1/docs/images/hero-dark.png +0 -0
- mcp_use-1.0.1/docs/images/hero-light.png +0 -0
- mcp_use-1.0.1/docs/introduction.mdx +39 -0
- mcp_use-1.0.1/docs/logo/dark.svg +12 -0
- mcp_use-1.0.1/docs/logo/light.svg +12 -0
- mcp_use-1.0.1/docs/quickstart.mdx +99 -0
- mcp_use-1.0.1/docs/snippets/snippet-intro.mdx +4 -0
- mcp_use-1.0.1/examples/airbnb_mcp.json +8 -0
- mcp_use-1.0.1/examples/airbnb_use.py +51 -0
- mcp_use-1.0.1/examples/blender_use.py +53 -0
- mcp_use-1.0.1/examples/browser_mcp.json +11 -0
- mcp_use-1.0.1/examples/browser_use.py +46 -0
- mcp_use-1.0.1/examples/chat_example.py +80 -0
- mcp_use-1.0.1/examples/filesystem_use.py +58 -0
- mcp_use-1.0.1/examples/multi_server_example.py +66 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/__init__.py +6 -6
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/agents/langchain_agent.py +88 -64
- mcp_use-1.0.1/mcp_use/agents/mcpagent.py +313 -0
- mcp_use-1.0.1/mcp_use/agents/prompts/default.py +22 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/client.py +93 -68
- mcp_use-1.0.1/mcp_use/config.py +59 -0
- mcp_use-1.0.1/mcp_use/connectors/base.py +139 -0
- mcp_use-1.0.1/mcp_use/connectors/http.py +82 -0
- mcp_use-1.0.1/mcp_use/connectors/stdio.py +78 -0
- mcp_use-1.0.1/mcp_use/connectors/websocket.py +245 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/session.py +0 -55
- mcp_use-1.0.1/mcp_use/task_managers/__init__.py +19 -0
- mcp_use-1.0.1/mcp_use/task_managers/base.py +151 -0
- mcp_use-1.0.1/mcp_use/task_managers/sse.py +82 -0
- mcp_use-1.0.1/mcp_use/task_managers/stdio.py +73 -0
- mcp_use-1.0.1/mcp_use/task_managers/websocket.py +63 -0
- mcp_use-1.0.1/pyproject.toml +83 -0
- mcp_use-1.0.1/pytest.ini +6 -0
- mcp_use-1.0.1/static/image.jpg +0 -0
- mcp_use-1.0.1/tests/conftest.py +37 -0
- mcp_use-1.0.1/tests/unit/test_client.py +471 -0
- mcp_use-1.0.1/tests/unit/test_config.py +135 -0
- mcp_use-1.0.1/tests/unit/test_http_connector.py +338 -0
- mcp_use-1.0.1/tests/unit/test_logging.py +117 -0
- mcp_use-1.0.1/tests/unit/test_session.py +174 -0
- mcp_use-1.0.1/tests/unit/test_stdio_connector.py +353 -0
- mcp_use-0.1.0/PKG-INFO +0 -287
- mcp_use-0.1.0/README.md +0 -236
- mcp_use-0.1.0/mcp_use/agents/mcpagent.py +0 -149
- mcp_use-0.1.0/mcp_use/config.py +0 -113
- mcp_use-0.1.0/mcp_use/connectors/base.py +0 -61
- mcp_use-0.1.0/mcp_use/connectors/http.py +0 -126
- mcp_use-0.1.0/mcp_use/connectors/stdio.py +0 -124
- mcp_use-0.1.0/mcp_use/connectors/websocket.py +0 -142
- mcp_use-0.1.0/mcp_use/tools/__init__.py +0 -11
- mcp_use-0.1.0/mcp_use/tools/converter.py +0 -108
- mcp_use-0.1.0/mcp_use/tools/formats.py +0 -181
- mcp_use-0.1.0/mcp_use/types.py +0 -33
- mcp_use-0.1.0/mcp_use.egg-info/PKG-INFO +0 -287
- mcp_use-0.1.0/mcp_use.egg-info/SOURCES.txt +0 -27
- mcp_use-0.1.0/mcp_use.egg-info/dependency_links.txt +0 -1
- mcp_use-0.1.0/mcp_use.egg-info/requires.txt +0 -24
- mcp_use-0.1.0/mcp_use.egg-info/top_level.txt +0 -1
- mcp_use-0.1.0/pyproject.toml +0 -31
- mcp_use-0.1.0/setup.cfg +0 -4
- mcp_use-0.1.0/setup.py +0 -60
- {mcp_use-0.1.0 → mcp_use-1.0.1}/LICENSE +0 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/agents/__init__.py +0 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/agents/base.py +0 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/connectors/__init__.py +0 -0
- {mcp_use-0.1.0 → mcp_use-1.0.1}/mcp_use/logging.py +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Check Version Bump and Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'pyproject.toml'
|
|
9
|
+
|
|
10
|
+
# Required for PyPI trusted publishing
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
contents: write # Required for creating tags and releases
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
check-version-and-publish:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
with:
|
|
21
|
+
fetch-depth: 0 # This fetches all history for comparing versions
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v4
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.11"
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
pip install build twine wheel tomli
|
|
32
|
+
|
|
33
|
+
- name: Check for version bump
|
|
34
|
+
id: check-version
|
|
35
|
+
run: |
|
|
36
|
+
# Extract current version directly from pyproject.toml
|
|
37
|
+
# This is more reliable than using importlib.metadata
|
|
38
|
+
CURRENT_VERSION=$(python -c "
|
|
39
|
+
import tomli
|
|
40
|
+
with open('pyproject.toml', 'rb') as f:
|
|
41
|
+
data = tomli.load(f)
|
|
42
|
+
print(data['project']['version'])
|
|
43
|
+
")
|
|
44
|
+
|
|
45
|
+
echo "Current version: $CURRENT_VERSION"
|
|
46
|
+
|
|
47
|
+
# Check if this version already has a tag
|
|
48
|
+
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
|
|
49
|
+
echo "Version $CURRENT_VERSION already has a tag. Skipping release."
|
|
50
|
+
echo "is_new_version=false" >> $GITHUB_OUTPUT
|
|
51
|
+
else
|
|
52
|
+
echo "New version detected: $CURRENT_VERSION"
|
|
53
|
+
echo "is_new_version=true" >> $GITHUB_OUTPUT
|
|
54
|
+
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
- name: Build package
|
|
58
|
+
if: steps.check-version.outputs.is_new_version == 'true'
|
|
59
|
+
run: |
|
|
60
|
+
python -m build
|
|
61
|
+
|
|
62
|
+
- name: Create Release
|
|
63
|
+
if: steps.check-version.outputs.is_new_version == 'true'
|
|
64
|
+
id: create_release
|
|
65
|
+
uses: actions/create-release@v1
|
|
66
|
+
env:
|
|
67
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
68
|
+
with:
|
|
69
|
+
tag_name: v${{ steps.check-version.outputs.new_version }}
|
|
70
|
+
release_name: Release v${{ steps.check-version.outputs.new_version }}
|
|
71
|
+
draft: false
|
|
72
|
+
prerelease: false
|
|
73
|
+
|
|
74
|
+
- name: Publish to PyPI
|
|
75
|
+
if: steps.check-version.outputs.is_new_version == 'true'
|
|
76
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
77
|
+
with:
|
|
78
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Python Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v3
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v4
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip
|
|
25
|
+
pip install .[dev,anthropic,openai]
|
|
26
|
+
- name: Lint with ruff
|
|
27
|
+
run: |
|
|
28
|
+
ruff check .
|
|
29
|
+
- name: Test with pytest
|
|
30
|
+
run: |
|
|
31
|
+
pytest
|
mcp_use-1.0.1/.gitignore
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
*.manifest
|
|
30
|
+
*.spec
|
|
31
|
+
|
|
32
|
+
# Installer logs
|
|
33
|
+
pip-log.txt
|
|
34
|
+
pip-delete-this-directory.txt
|
|
35
|
+
|
|
36
|
+
# Unit test / coverage reports
|
|
37
|
+
htmlcov/
|
|
38
|
+
.tox/
|
|
39
|
+
.nox/
|
|
40
|
+
.coverage
|
|
41
|
+
.coverage.*
|
|
42
|
+
.cache
|
|
43
|
+
nosetests.xml
|
|
44
|
+
coverage.xml
|
|
45
|
+
*.cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Django stuff:
|
|
54
|
+
*.log
|
|
55
|
+
local_settings.py
|
|
56
|
+
db.sqlite3
|
|
57
|
+
db.sqlite3-journal
|
|
58
|
+
|
|
59
|
+
# Flask stuff:
|
|
60
|
+
instance/
|
|
61
|
+
.webassets-cache
|
|
62
|
+
|
|
63
|
+
# Scrapy stuff:
|
|
64
|
+
.scrapy
|
|
65
|
+
|
|
66
|
+
# Sphinx documentation
|
|
67
|
+
docs/_build/
|
|
68
|
+
|
|
69
|
+
# PyBuilder
|
|
70
|
+
target/
|
|
71
|
+
|
|
72
|
+
# Jupyter Notebook
|
|
73
|
+
.ipynb_checkpoints
|
|
74
|
+
|
|
75
|
+
# IPython
|
|
76
|
+
profile_default/
|
|
77
|
+
ipython_config.py
|
|
78
|
+
|
|
79
|
+
# pyenv
|
|
80
|
+
.python-version
|
|
81
|
+
|
|
82
|
+
# pipenv
|
|
83
|
+
Pipfile.lock
|
|
84
|
+
|
|
85
|
+
# poetry
|
|
86
|
+
poetry.lock
|
|
87
|
+
|
|
88
|
+
# Environment variables
|
|
89
|
+
.env
|
|
90
|
+
.venv
|
|
91
|
+
env/
|
|
92
|
+
venv/
|
|
93
|
+
ENV/
|
|
94
|
+
env.bak/
|
|
95
|
+
venv.bak/
|
|
96
|
+
|
|
97
|
+
# Spyder project settings
|
|
98
|
+
.spyderproject
|
|
99
|
+
.spyproject
|
|
100
|
+
|
|
101
|
+
# Rope project settings
|
|
102
|
+
.ropeproject
|
|
103
|
+
|
|
104
|
+
# mkdocs documentation
|
|
105
|
+
/site
|
|
106
|
+
|
|
107
|
+
# mypy
|
|
108
|
+
.mypy_cache/
|
|
109
|
+
.dmypy.json
|
|
110
|
+
dmypy.json
|
|
111
|
+
|
|
112
|
+
# Pyre type checker
|
|
113
|
+
.pyre/
|
|
114
|
+
|
|
115
|
+
# VS Code
|
|
116
|
+
.vscode/
|
|
117
|
+
*.code-workspace
|
|
118
|
+
|
|
119
|
+
# PyCharm
|
|
120
|
+
.idea/
|
|
121
|
+
*.iml
|
|
122
|
+
|
|
123
|
+
# macOS
|
|
124
|
+
.DS_Store
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
# Ruff version.
|
|
4
|
+
rev: v0.3.2
|
|
5
|
+
hooks:
|
|
6
|
+
- id: ruff
|
|
7
|
+
args: [--fix, --exit-non-zero-on-fix, --config=pyproject.toml]
|
|
8
|
+
types: [python]
|
|
9
|
+
- id: ruff-format
|
|
10
|
+
args: [--config=pyproject.toml]
|
|
11
|
+
types: [python]
|
|
12
|
+
|
|
13
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
14
|
+
rev: v4.5.0
|
|
15
|
+
hooks:
|
|
16
|
+
- id: trailing-whitespace
|
|
17
|
+
- id: end-of-file-fixer
|
|
18
|
+
- id: check-yaml
|
|
19
|
+
- id: check-added-large-files
|
|
20
|
+
- id: debug-statements
|
|
21
|
+
|
|
22
|
+
# Define configuration for the Python checks
|
|
23
|
+
default_language_version:
|
|
24
|
+
python: python3.11
|
mcp_use-1.0.1/PKG-INFO
ADDED
|
@@ -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
|