-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update navigation and MCP integration #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| title: "Airbnb MCP Integration" | ||
| sidebarTitle: "Airbnb" | ||
| description: "Guide for integrating Airbnb booking capabilities with PraisonAI agents using MCP" | ||
| icon: "airbnb" | ||
| --- | ||
|
|
||
| # Airbnb MCP Integration | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[In] --> Agent[AI Agent] | ||
| Agent --> Tool[Airbnb MCP] | ||
| Tool --> Agent | ||
| Agent --> Out[Out] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Tool fill:#FF5A5F,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Set API Key"> | ||
| Set your OpenAI API key as an environment variable in your terminal: | ||
| ```bash | ||
| export OPENAI_API_KEY=your_openai_api_key_here | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Create a file"> | ||
| Create a new file `airbnb_search.py` with the following code: | ||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
|
|
||
| search_agent = Agent( | ||
| instructions="""You help book apartments on Airbnb.""", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") | ||
| ) | ||
|
|
||
| search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults") | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Install Dependencies"> | ||
| Make sure you have Node.js installed, as the MCP server requires it: | ||
| ```bash | ||
| pip install praisonaiagents | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| python airbnb_search.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - Node.js installed on your system | ||
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
|
|
||
| ## Features | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="Accommodation Search" icon="hotel"> | ||
| Search for accommodations on Airbnb with natural language queries. | ||
| </Card> | ||
| <Card title="MCP Integration" icon="plug"> | ||
| Seamless integration with Model Context Protocol. | ||
| </Card> | ||
| <Card title="Booking Details" icon="calendar"> | ||
| Specify dates, guests, and location preferences in natural language. | ||
| </Card> | ||
| <Card title="NPM Package" icon="js"> | ||
| Leverages the official Airbnb MCP server package. | ||
| </Card> | ||
| </CardGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| title: "Brave Search MCP Integration" | ||
| sidebarTitle: "Brave Search" | ||
| description: "Guide for integrating Brave Search capabilities with PraisonAI agents using MCP" | ||
| icon: "searchengin" | ||
| --- | ||
|
|
||
| # Brave Search MCP Integration | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[In] --> Agent[AI Agent] | ||
| Agent --> Tool[Brave Search MCP] | ||
| Tool --> Agent | ||
| Agent --> Out[Out] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Tool fill:#4169E1,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Set API Key"> | ||
| Set your Brave Search API key as an environment variable in your terminal: | ||
| ```bash | ||
| export BRAVE_API_KEY=your_brave_api_key_here | ||
| export OPENAI_API_KEY=your_openai_api_key_here | ||
| ``` | ||
|
|
||
| You can obtain a Brave Search API key from [Brave Search API](https://brave.com/search/api/). | ||
| </Step> | ||
|
|
||
| <Step title="Create a file"> | ||
| Create a new file `brave_search.py` with the following code: | ||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
| import os | ||
|
|
||
| # Use the API key from environment or set it directly | ||
| brave_api_key = os.getenv("BRAVE_API_KEY") or "your_brave_api_key_here" | ||
|
|
||
| # Use a single string command with environment variables | ||
| search_agent = Agent( | ||
| instructions="""You are a helpful assistant that can search the web for information. | ||
| Use the available tools when relevant to answer user questions.""", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @modelcontextprotocol/server-brave-search", env={"BRAVE_API_KEY": brave_api_key}) | ||
| ) | ||
|
|
||
| search_agent.start("Search more information about AI News") | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Install Dependencies"> | ||
| Make sure you have Node.js installed, as the MCP server requires it: | ||
| ```bash | ||
| pip install praisonaiagents | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| python brave_search.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - Node.js installed on your system | ||
| - Brave Search API key | ||
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
|
|
||
| ## Features | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="Web Search" icon="globe"> | ||
| Search the web for up-to-date information. | ||
| </Card> | ||
| <Card title="MCP Integration" icon="plug"> | ||
| Seamless integration with Model Context Protocol. | ||
| </Card> | ||
| <Card title="Environment Variables" icon="key"> | ||
| Secure API key handling through environment variables. | ||
| </Card> | ||
| <Card title="NPM Package" icon="js"> | ||
| Leverages the official Brave Search MCP server package. | ||
| </Card> | ||
| </CardGroup> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| --- | ||
| title: "Custom Python MCP Server" | ||
| sidebarTitle: "Custom Python MCP" | ||
| description: "Guide for creating and using custom Python MCP servers with PraisonAI agents" | ||
| icon: "python" | ||
| --- | ||
|
|
||
| # Custom Python MCP Server | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[In] --> Agent[AI Agent] | ||
| Agent --> Tool[Custom Python MCP] | ||
| Tool --> Agent | ||
| Agent --> Out[Out] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Tool fill:#3776AB,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Create MCP Server"> | ||
| Create a new file `app.py` with your custom MCP server implementation: | ||
| ```python | ||
| import yfinance as yf | ||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| mcp = FastMCP("stock_prices") | ||
|
|
||
| @mcp.tool() | ||
| async def get_stock_price(ticker: str) -> str: | ||
| """Get the current stock price for a given ticker symbol. | ||
|
|
||
| Args: | ||
| ticker: Stock ticker symbol (e.g., AAPL, MSFT, GOOG) | ||
|
|
||
| Returns: | ||
| Current stock price as a string | ||
| """ | ||
| if not ticker: | ||
| return "No ticker provided" | ||
| try: | ||
| stock = yf.Ticker(ticker) | ||
| info = stock.info | ||
| current_price = info.get('currentPrice') or info.get('regularMarketPrice') | ||
| if not current_price: | ||
| return f"Could not retrieve price for {ticker}" | ||
| return f"${current_price:.2f}" | ||
|
|
||
| except Exception as e: | ||
| return f"Error: {str(e)}" | ||
|
|
||
| if __name__ == "__main__": | ||
| mcp.run(transport='stdio') | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Install Dependencies"> | ||
| Install the required dependencies in a conda environment: | ||
| ```bash | ||
| conda create -n mcp python=3.10 | ||
| conda activate mcp | ||
| pip install yfinance mcp-python-sdk | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Create Agent Integration"> | ||
| Create a new file `stock_agent.py` with the following code: | ||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
|
|
||
| agent = Agent( | ||
| instructions="""You are a helpful assistant that can check stock prices and perform other tasks. | ||
| Use the available tools when relevant to answer user questions.""", | ||
| llm="gpt-4o-mini", | ||
| tools = MCP("/path/to/python /path/to/app.py") | ||
| ) | ||
|
Comment on lines
+80
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the path to the Python interpreter and the |
||
|
|
||
| # NOTE: Replace with your actual Python path and app.py file path | ||
|
|
||
| agent.start("What is the stock price of Tesla?") | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| zsh -c "source $(conda info --base)/etc/profile.d/conda.sh && conda activate windsurf && python stock_agent.py" | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - Conda for environment management | ||
| - yfinance package for stock data | ||
| - mcp-python-sdk for MCP server implementation | ||
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
|
|
||
| ## Features | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="Custom Tools" icon="wrench"> | ||
| Create your own custom tools with Python. | ||
| </Card> | ||
| <Card title="MCP Integration" icon="plug"> | ||
| Seamless integration with Model Context Protocol. | ||
| </Card> | ||
| <Card title="Type Hints" icon="code"> | ||
| Strong typing for better code reliability. | ||
| </Card> | ||
| <Card title="Async Support" icon="bolt"> | ||
| Built-in support for asynchronous functions. | ||
| </Card> | ||
| </CardGroup> | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### FastMCP Class | ||
|
|
||
| The `FastMCP` class from the `mcp-python-sdk` package provides a simple way to create MCP servers in Python: | ||
|
|
||
| ```python | ||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| # Create an MCP server with a name | ||
| mcp = FastMCP("my_tools") | ||
|
|
||
| # Define a tool using the @mcp.tool decorator | ||
| @mcp.tool() | ||
| async def my_tool(param1: str, param2: int) -> str: | ||
| """Tool description with clear documentation. | ||
|
|
||
| Args: | ||
| param1: Description of param1 | ||
| param2: Description of param2 | ||
|
|
||
| Returns: | ||
| Description of the return value | ||
| """ | ||
| # Tool implementation | ||
| return f"Processed {param1} with {param2}" | ||
|
|
||
| # Run the server with stdio transport | ||
| if __name__ == "__main__": | ||
| mcp.run(transport='stdio') | ||
| ``` | ||
|
|
||
| ### Agent Integration | ||
|
|
||
| To use your custom MCP server with PraisonAI agents, use the `MCP` class to specify the command to run your Python script: | ||
|
|
||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
|
|
||
| agent = Agent( | ||
| instructions="Agent instructions", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP( | ||
| command="python", # Or full path to Python | ||
| args=["path/to/your/mcp_server.py"] # Path to your MCP server script | ||
| ) | ||
| ) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from praisonaiagents import Agent, MCP | ||
|
|
||
| search_agent = Agent( | ||
| instructions="""You help book apartments on Airbnb.""", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") | ||
| ) | ||
|
|
||
| search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While using environment variables is great, providing a default value directly in the code can be a security risk. It's better to force users to explicitly set the environment variable to avoid accidental exposure of the API key. Consider raising an error if the environment variable is not set.