Skip to content

Commit 834bffa

Browse files
authored
large commit adding documentation (#26)
1 parent cd55cdd commit 834bffa

29 files changed

+1793
-434
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ wheels/
1111
.env
1212

1313
# Notebooks
14-
notebooks/
14+
notebooks/
15+
16+
# mkdocs documentation
17+
/site

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.PHONY: sync
2+
sync:
3+
uv sync --all-extras --all-packages --group dev
4+
5+
.PHONY: format
6+
format:
7+
uv run ruff format
8+
uv run ruff check --fix
9+
10+
.PHONY: lint
11+
lint:
12+
uv run ruff check
13+
14+
.PHONY: mypy
15+
mypy:
16+
uv run mypy .
17+
18+
.PHONY: tests
19+
tests:
20+
uv run pytest
21+
22+
.PHONY: coverage
23+
coverage:
24+
25+
uv run coverage run -m pytest
26+
uv run coverage xml -o coverage.xml
27+
uv run coverage report -m --fail-under=95
28+
29+
.PHONY: snapshots-fix
30+
snapshots-fix:
31+
uv run pytest --inline-snapshot=fix
32+
33+
.PHONY: snapshots-create
34+
snapshots-create:
35+
uv run pytest --inline-snapshot=create
36+
37+
.PHONY: old_version_tests
38+
old_version_tests:
39+
UV_PROJECT_ENVIRONMENT=.venv_39 uv run --python 3.9 -m pytest
40+
41+
.PHONY: build-docs
42+
build-docs:
43+
uv run mkdocs build
44+
45+
.PHONY: serve-docs
46+
serve-docs:
47+
uv run mkdocs serve
48+
49+
.PHONY: deploy-docs
50+
deploy-docs:
51+
uv run mkdocs gh-deploy --force --verbose

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can also add multiple framework comma separated if needed.
4747

4848
## Usage
4949

50-
⚠️ **Security Warning**: When using MCP servers, especially over SSE (Server-Sent Events), be extremely cautious and only connect to trusted and verified servers. Some adapters use Python's `exec` function internally, which could potentially allow for remote code execution if connected to a malicious server. Always verify the source and security of any MCP server before connecting.
50+
⚠️ **Security Warning**: When using MCP servers, especially over SSE (Server-Sent Events), be extremely cautious and only connect to trusted and verified servers. Always verify the source and security of any MCP server before connecting.
5151

5252
### Smolagents
5353

@@ -129,3 +129,16 @@ class YourFrameworkAdapter(ToolAdapter):
129129
- [x] support for jupyter notebook
130130
- [x] add tests
131131

132+
## Contributors
133+
134+
We acknowledge the work and thanks every contributors and maintainers for their contributions.
135+
136+
Core Maintainers:
137+
138+
* [@grll](https://github.com/grll)
139+
140+
Contributors:
141+
142+
* [@murawakimitsuhiro](https://github.com/murawakimitsuhiro)
143+
* [@joejoe2](https://github.com/joejoe2)
144+
* [@tisDDM](https://github.com/tisDDM)

docs/assets/logo.png

1.11 MB
Loading

docs/assets/logo_dark.png

1.29 MB
Loading
245 KB
Loading

docs/assets/logo_transparent.png

297 KB
Loading
237 KB
Loading

docs/guide/crewai.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# CrewAI
2+
3+
At the time of writing, MCPAdapt offers integration with CrewAI through its adapter system only. However a PR is underway to integrate directly into CrewAI's framework.
4+
5+
Let's explore how to use MCPAdapt with CrewAI.
6+
7+
## Using MCPAdapt CrewAI Adapter
8+
9+
Ensure you have the necessary dependencies installed and set up your OpenAI API key as required by crewAI:
10+
11+
```bash
12+
pip install mcpadapt[crewai]
13+
```
14+
15+
### Creating a Simple Echo Server
16+
17+
First, create an MCP server using FastMCP notation:
18+
19+
```python
20+
# echo.py
21+
from mcp.server.fastmcp import FastMCP
22+
from pydantic import Field
23+
24+
# Create server
25+
mcp = FastMCP("Echo Server")
26+
27+
28+
@mcp.tool()
29+
def echo_tool(text: str = Field(description="The text to echo")) -> str:
30+
"""Echo the input text
31+
32+
Args:
33+
text (str): The text to echo
34+
35+
Returns:
36+
str: The echoed text
37+
"""
38+
return text
39+
40+
mcp.run()
41+
```
42+
43+
### Using the Echo Server
44+
45+
Here's how to interact with the server using CrewAI:
46+
47+
```python
48+
import os
49+
from crewai import Agent, Crew, Task
50+
from mcp import StdioServerParameters
51+
52+
from mcpadapt.core import MCPAdapt
53+
from mcpadapt.crewai_adapter import CrewAIAdapter
54+
55+
with MCPAdapt(
56+
StdioServerParameters(command="uv", args=["run", "echo.py"]),
57+
CrewAIAdapter(),
58+
) as tools:
59+
# Create an echo agent
60+
agent = Agent(
61+
role="Echo Agent",
62+
goal="Echo messages back to the user",
63+
backstory="You help echo messages back to users",
64+
verbose=True,
65+
tools=[tools[0]],
66+
)
67+
68+
# Create a task
69+
task = Task(
70+
description="Echo 'Hello, World!'",
71+
agent=agent,
72+
expected_output="The echoed message",
73+
)
74+
75+
# Create and run the crew
76+
crew = Crew(agents=[agent], tasks=[task], verbose=True)
77+
crew.kickoff()
78+
```
79+
80+
### Real-World Example: PubMed MCP Server
81+
82+
In the real-world, you are most likely to run MCP server already built by the community.
83+
As an example, here's how to use the PubMed MCP server with CrewAI:
84+
85+
```python
86+
import os
87+
from dotenv import load_dotenv
88+
from crewai import Agent, Crew, Task
89+
from mcp import StdioServerParameters
90+
91+
from mcpadapt.core import MCPAdapt
92+
from mcpadapt.crewai_adapter import CrewAIAdapter
93+
94+
# Load environment variables
95+
load_dotenv()
96+
if not os.environ.get("OPENAI_API_KEY"):
97+
raise ValueError("OPENAI_API_KEY must be set in your environment variables")
98+
99+
# Initialize MCPAdapt with CrewAI adapter
100+
with MCPAdapt(
101+
StdioServerParameters(
102+
command="uvx",
103+
args=["--quiet", "[email protected]"],
104+
env={"UV_PYTHON": "3.12", **os.environ},
105+
),
106+
CrewAIAdapter(),
107+
) as tools:
108+
# Create a research agent
109+
agent = Agent(
110+
role="Research Agent",
111+
goal="Find studies about hangover",
112+
backstory="You help find studies about hangover",
113+
verbose=True,
114+
tools=[tools[0]],
115+
)
116+
117+
# Create a task
118+
task = Task(
119+
description="Find studies about hangover",
120+
agent=agent,
121+
expected_output="A list of studies about hangover",
122+
)
123+
124+
# Create and run the crew
125+
crew = Crew(agents=[agent], tasks=[task], verbose=True)
126+
crew.kickoff()
127+
```
128+
129+
#### Important Notes:
130+
- Always use the `--quiet` flag with uvx to prevent output interference with the stdio transport protocol
131+
- Including `**os.environ` helps resolve paths in the subprocess but consider security implications of sending your environment variables to the MCP server
132+
- Remote MCP servers are supported via Server Sent Events (SSE). See the [quickstart SSE guide](../quickstart.md#sse-server-sent-events-support)
133+
- Make sure to set your OPENAI_API_KEY in your environment variables or .env file
134+
135+
## Full Working Code Example
136+
137+
You can find a fully working script of this example [here](https://github.com/grll/mcpadapt/blob/main/examples/crewai_pubmed.py)
138+

docs/guide/google-genai.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Google GenAI
2+
3+
MCPAdapt offers integration with Google's genai SDK through its adapter system. Let's explore how to use MCPAdapt with Google GenAI.
4+
5+
## Using MCPAdapt Google GenAI Adapter
6+
7+
First, ensure you have the necessary dependencies installed:
8+
9+
```bash
10+
pip install mcpadapt[google-genai]
11+
```
12+
13+
You'll also need to set up your Google API key. You can get this from the Google AI Studio.
14+
15+
### Creating a Simple Echo Server
16+
17+
First, let's create an MCP server using FastMCP notation:
18+
19+
```python
20+
# echo.py
21+
from mcp.server.fastmcp import FastMCP
22+
from pydantic import Field
23+
24+
# Create server
25+
mcp = FastMCP("Echo Server")
26+
27+
@mcp.tool()
28+
def echo_tool(text: str = Field(description="The text to echo")) -> str:
29+
"""Echo the input text
30+
31+
Args:
32+
text (str): The text to echo
33+
34+
Returns:
35+
str: The echoed text
36+
"""
37+
return text
38+
39+
mcp.run()
40+
```
41+
42+
### Using the Echo Server with Google GenAI
43+
44+
Here's how to interact with the server using Google's Generative AI:
45+
46+
```python
47+
import os
48+
from google import genai
49+
from google.genai import types
50+
from mcp import StdioServerParameters
51+
52+
from mcpadapt.core import MCPAdapt
53+
from mcpadapt.google_genai_adapter import GoogleGenAIAdapter
54+
55+
# Initialize Google GenAI client
56+
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
57+
58+
# Create server parameters
59+
server_params = StdioServerParameters(
60+
command="uv",
61+
args=["run", "echo.py"]
62+
)
63+
64+
async def run():
65+
async with MCPAdapt(
66+
server_params,
67+
GoogleGenAIAdapter(),
68+
) as adapted_tools:
69+
# Unpack tools and tool_functions
70+
google_tools, tool_functions = zip(*adapted_tools)
71+
tool_functions = dict(tool_functions)
72+
73+
prompt = "Please echo back 'Hello, World!'"
74+
75+
# Generate content with function declarations
76+
response = client.models.generate_content(
77+
model="gemini-2.0-flash",
78+
contents=prompt,
79+
config=types.GenerateContentConfig(
80+
temperature=0.7,
81+
tools=google_tools,
82+
),
83+
)
84+
85+
# Handle the function call
86+
if response.candidates[0].content.parts[0].function_call:
87+
function_call = response.candidates[0].content.parts[0].function_call
88+
result = await tool_functions[function_call.name](function_call.args)
89+
print(result.content[0].text)
90+
else:
91+
print("No function call found in the response.")
92+
print(response.text)
93+
94+
if __name__ == "__main__":
95+
import asyncio
96+
asyncio.run(run())
97+
```
98+
99+
### Real-World Example: Airbnb MCP Server
100+
101+
Here's a real-world example using the Airbnb MCP server with Google GenAI:
102+
103+
```python
104+
import os
105+
from google import genai
106+
from google.genai import types
107+
from mcp import StdioServerParameters
108+
109+
from mcpadapt.core import MCPAdapt
110+
from mcpadapt.google_genai_adapter import GoogleGenAIAdapter
111+
112+
# Initialize Google GenAI client
113+
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
114+
115+
# Create server parameters for Airbnb MCP
116+
server_params = StdioServerParameters(
117+
command="npx",
118+
args=[
119+
"-y",
120+
"@openbnb/mcp-server-airbnb",
121+
"--ignore-robots-txt",
122+
],
123+
)
124+
125+
async def run():
126+
async with MCPAdapt(
127+
server_params,
128+
GoogleGenAIAdapter(),
129+
) as adapted_tools:
130+
# Unpack tools and tool_functions
131+
google_tools, tool_functions = zip(*adapted_tools)
132+
tool_functions = dict(tool_functions)
133+
134+
prompt = "I want to book an apartment in Paris for 2 nights, March 28-30"
135+
136+
# Generate content with function declarations
137+
response = client.models.generate_content(
138+
model="gemini-2.0-flash",
139+
contents=prompt,
140+
config=types.GenerateContentConfig(
141+
temperature=0.7,
142+
tools=google_tools,
143+
),
144+
)
145+
146+
# Handle the function call
147+
if response.candidates[0].content.parts[0].function_call:
148+
function_call = response.candidates[0].content.parts[0].function_call
149+
result = await tool_functions[function_call.name](function_call.args)
150+
print(result.content[0].text)
151+
else:
152+
print("No function call found in the response.")
153+
print(response.text)
154+
155+
if __name__ == "__main__":
156+
import asyncio
157+
asyncio.run(run())
158+
```
159+
160+
#### Important Notes:
161+
- Make sure to set your `GEMINI_API_KEY` in your environment variables
162+
- The examples work with both synchronous and asynchronous code
163+
- Remote MCP servers are supported via Server Sent Events (SSE). See the [quickstart SSE guide](../quickstart.md#sse-server-sent-events-support)
164+
165+
## Full Working Code Example
166+
167+
You can find a fully working script of the Airbnb example [here](https://github.com/grll/mcpadapt/blob/main/examples/google_genai.py)

0 commit comments

Comments
 (0)