Skip to content

Commit 57c4cf9

Browse files
Merge pull request #433 from MervinPraison/develop
Update navigation and MCP integration
2 parents 44b6140 + 17f4a5c commit 57c4cf9

File tree

9 files changed

+424
-13
lines changed

9 files changed

+424
-13
lines changed

docs/mcp/airbnb.mdx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "Airbnb MCP Integration"
3+
sidebarTitle: "Airbnb"
4+
description: "Guide for integrating Airbnb booking capabilities with PraisonAI agents using MCP"
5+
icon: "airbnb"
6+
---
7+
8+
# Airbnb MCP Integration
9+
10+
```mermaid
11+
flowchart LR
12+
In[In] --> Agent[AI Agent]
13+
Agent --> Tool[Airbnb MCP]
14+
Tool --> Agent
15+
Agent --> Out[Out]
16+
17+
style In fill:#8B0000,color:#fff
18+
style Agent fill:#2E8B57,color:#fff
19+
style Tool fill:#FF5A5F,color:#fff
20+
style Out fill:#8B0000,color:#fff
21+
```
22+
23+
## Quick Start
24+
25+
<Steps>
26+
<Step title="Set API Key">
27+
Set your OpenAI API key as an environment variable in your terminal:
28+
```bash
29+
export OPENAI_API_KEY=your_openai_api_key_here
30+
```
31+
</Step>
32+
33+
<Step title="Create a file">
34+
Create a new file `airbnb_search.py` with the following code:
35+
```python
36+
from praisonaiagents import Agent, MCP
37+
38+
search_agent = Agent(
39+
instructions="""You help book apartments on Airbnb.""",
40+
llm="gpt-4o-mini",
41+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
42+
)
43+
44+
search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults")
45+
```
46+
</Step>
47+
48+
<Step title="Install Dependencies">
49+
Make sure you have Node.js installed, as the MCP server requires it:
50+
```bash
51+
pip install praisonaiagents
52+
```
53+
</Step>
54+
55+
<Step title="Run the Agent">
56+
Execute your script:
57+
```bash
58+
python airbnb_search.py
59+
```
60+
</Step>
61+
</Steps>
62+
63+
<Note>
64+
**Requirements**
65+
- Python 3.10 or higher
66+
- Node.js installed on your system
67+
- OpenAI API key (for the agent's LLM)
68+
</Note>
69+
70+
## Features
71+
72+
<CardGroup cols={2}>
73+
<Card title="Accommodation Search" icon="hotel">
74+
Search for accommodations on Airbnb with natural language queries.
75+
</Card>
76+
<Card title="MCP Integration" icon="plug">
77+
Seamless integration with Model Context Protocol.
78+
</Card>
79+
<Card title="Booking Details" icon="calendar">
80+
Specify dates, guests, and location preferences in natural language.
81+
</Card>
82+
<Card title="NPM Package" icon="js">
83+
Leverages the official Airbnb MCP server package.
84+
</Card>
85+
</CardGroup>

docs/mcp/bravesearch.mdx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "Brave Search MCP Integration"
3+
sidebarTitle: "Brave Search"
4+
description: "Guide for integrating Brave Search capabilities with PraisonAI agents using MCP"
5+
icon: "searchengin"
6+
---
7+
8+
# Brave Search MCP Integration
9+
10+
```mermaid
11+
flowchart LR
12+
In[In] --> Agent[AI Agent]
13+
Agent --> Tool[Brave Search MCP]
14+
Tool --> Agent
15+
Agent --> Out[Out]
16+
17+
style In fill:#8B0000,color:#fff
18+
style Agent fill:#2E8B57,color:#fff
19+
style Tool fill:#4169E1,color:#fff
20+
style Out fill:#8B0000,color:#fff
21+
```
22+
23+
## Quick Start
24+
25+
<Steps>
26+
<Step title="Set API Key">
27+
Set your Brave Search API key as an environment variable in your terminal:
28+
```bash
29+
export BRAVE_API_KEY=your_brave_api_key_here
30+
export OPENAI_API_KEY=your_openai_api_key_here
31+
```
32+
33+
You can obtain a Brave Search API key from [Brave Search API](https://brave.com/search/api/).
34+
</Step>
35+
36+
<Step title="Create a file">
37+
Create a new file `brave_search.py` with the following code:
38+
```python
39+
from praisonaiagents import Agent, MCP
40+
import os
41+
42+
# Use the API key from environment or set it directly
43+
brave_api_key = os.getenv("BRAVE_API_KEY") or "your_brave_api_key_here"
44+
45+
# Use a single string command with environment variables
46+
search_agent = Agent(
47+
instructions="""You are a helpful assistant that can search the web for information.
48+
Use the available tools when relevant to answer user questions.""",
49+
llm="gpt-4o-mini",
50+
tools=MCP("npx -y @modelcontextprotocol/server-brave-search", env={"BRAVE_API_KEY": brave_api_key})
51+
)
52+
53+
search_agent.start("Search more information about AI News")
54+
```
55+
</Step>
56+
57+
<Step title="Install Dependencies">
58+
Make sure you have Node.js installed, as the MCP server requires it:
59+
```bash
60+
pip install praisonaiagents
61+
```
62+
</Step>
63+
64+
<Step title="Run the Agent">
65+
Execute your script:
66+
```bash
67+
python brave_search.py
68+
```
69+
</Step>
70+
</Steps>
71+
72+
<Note>
73+
**Requirements**
74+
- Python 3.10 or higher
75+
- Node.js installed on your system
76+
- Brave Search API key
77+
- OpenAI API key (for the agent's LLM)
78+
</Note>
79+
80+
## Features
81+
82+
<CardGroup cols={2}>
83+
<Card title="Web Search" icon="globe">
84+
Search the web for up-to-date information.
85+
</Card>
86+
<Card title="MCP Integration" icon="plug">
87+
Seamless integration with Model Context Protocol.
88+
</Card>
89+
<Card title="Environment Variables" icon="key">
90+
Secure API key handling through environment variables.
91+
</Card>
92+
<Card title="NPM Package" icon="js">
93+
Leverages the official Brave Search MCP server package.
94+
</Card>
95+
</CardGroup>

docs/mcp/custom.mdx

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
title: "Custom Python MCP Server"
3+
sidebarTitle: "Custom Python MCP"
4+
description: "Guide for creating and using custom Python MCP servers with PraisonAI agents"
5+
icon: "python"
6+
---
7+
8+
# Custom Python MCP Server
9+
10+
```mermaid
11+
flowchart LR
12+
In[In] --> Agent[AI Agent]
13+
Agent --> Tool[Custom Python MCP]
14+
Tool --> Agent
15+
Agent --> Out[Out]
16+
17+
style In fill:#8B0000,color:#fff
18+
style Agent fill:#2E8B57,color:#fff
19+
style Tool fill:#3776AB,color:#fff
20+
style Out fill:#8B0000,color:#fff
21+
```
22+
23+
## Quick Start
24+
25+
<Steps>
26+
<Step title="Create MCP Server">
27+
Create a new file `app.py` with your custom MCP server implementation:
28+
```python
29+
import yfinance as yf
30+
from mcp.server.fastmcp import FastMCP
31+
32+
mcp = FastMCP("stock_prices")
33+
34+
@mcp.tool()
35+
async def get_stock_price(ticker: str) -> str:
36+
"""Get the current stock price for a given ticker symbol.
37+
38+
Args:
39+
ticker: Stock ticker symbol (e.g., AAPL, MSFT, GOOG)
40+
41+
Returns:
42+
Current stock price as a string
43+
"""
44+
if not ticker:
45+
return "No ticker provided"
46+
try:
47+
stock = yf.Ticker(ticker)
48+
info = stock.info
49+
current_price = info.get('currentPrice') or info.get('regularMarketPrice')
50+
if not current_price:
51+
return f"Could not retrieve price for {ticker}"
52+
return f"${current_price:.2f}"
53+
54+
except Exception as e:
55+
return f"Error: {str(e)}"
56+
57+
if __name__ == "__main__":
58+
mcp.run(transport='stdio')
59+
```
60+
</Step>
61+
62+
<Step title="Install Dependencies">
63+
Install the required dependencies in a conda environment:
64+
```bash
65+
conda create -n mcp python=3.10
66+
conda activate mcp
67+
pip install yfinance mcp-python-sdk
68+
```
69+
</Step>
70+
71+
<Step title="Create Agent Integration">
72+
Create a new file `stock_agent.py` with the following code:
73+
```python
74+
from praisonaiagents import Agent, MCP
75+
76+
agent = Agent(
77+
instructions="""You are a helpful assistant that can check stock prices and perform other tasks.
78+
Use the available tools when relevant to answer user questions.""",
79+
llm="gpt-4o-mini",
80+
tools = MCP("/path/to/python /path/to/app.py")
81+
)
82+
83+
# NOTE: Replace with your actual Python path and app.py file path
84+
85+
agent.start("What is the stock price of Tesla?")
86+
```
87+
</Step>
88+
89+
<Step title="Run the Agent">
90+
Execute your script:
91+
```bash
92+
zsh -c "source $(conda info --base)/etc/profile.d/conda.sh && conda activate windsurf && python stock_agent.py"
93+
```
94+
</Step>
95+
</Steps>
96+
97+
<Note>
98+
**Requirements**
99+
- Python 3.10 or higher
100+
- Conda for environment management
101+
- yfinance package for stock data
102+
- mcp-python-sdk for MCP server implementation
103+
- OpenAI API key (for the agent's LLM)
104+
</Note>
105+
106+
## Features
107+
108+
<CardGroup cols={2}>
109+
<Card title="Custom Tools" icon="wrench">
110+
Create your own custom tools with Python.
111+
</Card>
112+
<Card title="MCP Integration" icon="plug">
113+
Seamless integration with Model Context Protocol.
114+
</Card>
115+
<Card title="Type Hints" icon="code">
116+
Strong typing for better code reliability.
117+
</Card>
118+
<Card title="Async Support" icon="bolt">
119+
Built-in support for asynchronous functions.
120+
</Card>
121+
</CardGroup>
122+
123+
## Implementation Details
124+
125+
### FastMCP Class
126+
127+
The `FastMCP` class from the `mcp-python-sdk` package provides a simple way to create MCP servers in Python:
128+
129+
```python
130+
from mcp.server.fastmcp import FastMCP
131+
132+
# Create an MCP server with a name
133+
mcp = FastMCP("my_tools")
134+
135+
# Define a tool using the @mcp.tool decorator
136+
@mcp.tool()
137+
async def my_tool(param1: str, param2: int) -> str:
138+
"""Tool description with clear documentation.
139+
140+
Args:
141+
param1: Description of param1
142+
param2: Description of param2
143+
144+
Returns:
145+
Description of the return value
146+
"""
147+
# Tool implementation
148+
return f"Processed {param1} with {param2}"
149+
150+
# Run the server with stdio transport
151+
if __name__ == "__main__":
152+
mcp.run(transport='stdio')
153+
```
154+
155+
### Agent Integration
156+
157+
To use your custom MCP server with PraisonAI agents, use the `MCP` class to specify the command to run your Python script:
158+
159+
```python
160+
from praisonaiagents import Agent, MCP
161+
162+
agent = Agent(
163+
instructions="Agent instructions",
164+
llm="gpt-4o-mini",
165+
tools=MCP(
166+
command="python", # Or full path to Python
167+
args=["path/to/your/mcp_server.py"] # Path to your MCP server script
168+
)
169+
)
170+
```

docs/mint.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"name": "Tools",
7676
"url": "/tools"
7777
},
78+
{
79+
"name": "MCP",
80+
"url": "/mcp"
81+
},
7882
{
7983
"name": "JS",
8084
"url": "/js"
@@ -230,6 +234,14 @@
230234
"agents/recommendation"
231235
]
232236
},
237+
{
238+
"group": "MCP",
239+
"pages": [
240+
"mcp/bravesearch",
241+
"mcp/airbnb",
242+
"mcp/custom"
243+
]
244+
},
233245
{
234246
"group": "Tools",
235247
"pages": [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="gpt-4o-mini",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults")

0 commit comments

Comments
 (0)