-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhance MCP Documentation and Integration #436
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| title: "AWS KB Retrieval MCP Integration" | ||
| sidebarTitle: "AWS KB Retrieval" | ||
| description: "Guide for integrating AWS Knowledge Base retrieval capabilities with PraisonAI agents using MCP" | ||
| icon: "aws" | ||
| --- | ||
|
|
||
| ## Add AWS KB Retrieval Tool to AI Agent | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[Query] --> Agent[AI Agent] | ||
| Agent --> Tool[AWS KB Retrieval MCP] | ||
| Tool --> Agent | ||
| Agent --> Out[Answer] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Tool fill:#FF9900,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Install Dependencies"> | ||
| Make sure you have Node.js installed, as the MCP server requires it: | ||
| ```bash | ||
| pip install praisonaiagents mcp | ||
| ``` | ||
| </Step> | ||
| <Step title="Set API Keys"> | ||
| Set your AWS credentials as environment variables in your terminal: | ||
| ```bash | ||
| export AWS_ACCESS_KEY_ID=your_aws_access_key_id_here | ||
| export AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key_here | ||
| export AWS_REGION=your_aws_region_here | ||
| export OPENAI_API_KEY=your_openai_api_key_here | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Create a file"> | ||
| Create a new file `aws_kb_retrieval.py` with the following code: | ||
| ```python | ||
| from praisonaiagents import Agent, MCP | ||
| import os | ||
|
|
||
| # Get AWS credentials from environment | ||
| aws_access_key = os.getenv("AWS_ACCESS_KEY_ID") | ||
| aws_secret_key = os.getenv("AWS_SECRET_ACCESS_KEY") | ||
| aws_region = os.getenv("AWS_REGION") | ||
|
|
||
| # Use a single string command with AWS KB Retrieval configuration | ||
| aws_kb_agent = Agent( | ||
| instructions="""You are a helpful assistant that can interact with AWS Knowledge Base. | ||
| Use the available tools when relevant to retrieve and process AWS information.""", | ||
| llm="gpt-4o-mini", | ||
| tools=MCP("npx -y @modelcontextprotocol/server-aws-kb-retrieval", | ||
| env={ | ||
| "AWS_ACCESS_KEY_ID": aws_access_key, | ||
| "AWS_SECRET_ACCESS_KEY": aws_secret_key, | ||
| "AWS_REGION": aws_region | ||
| }) | ||
| ) | ||
|
|
||
| aws_kb_agent.start("Search AWS documentation about EC2 instances") | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| python aws_kb_retrieval.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - Node.js installed on your system | ||
| - AWS credentials (Access Key ID, Secret Access Key, and Region) | ||
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,14 @@ description: "Guide for integrating Brave Search capabilities with PraisonAI age | |
| icon: "searchengin" | ||
| --- | ||
|
|
||
| # Brave Search MCP Integration | ||
| ## Add Brave Search Tool to AI Agent | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[In] --> Agent[AI Agent] | ||
| In[Query] --> Agent[AI Agent] | ||
| Agent --> Tool[Brave Search MCP] | ||
| Tool --> Agent | ||
| Agent --> Out[Out] | ||
| Agent --> Out[Answer] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
|
|
@@ -23,6 +23,12 @@ flowchart LR | |
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Install Dependencies"> | ||
| Make sure you have Node.js installed, as the MCP server requires it: | ||
| ```bash | ||
| pip install praisonaiagents mcp | ||
| ``` | ||
|
Comment on lines
+26
to
+30
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. |
||
| </Step> | ||
| <Step title="Set API Key"> | ||
| Set your Brave Search API key as an environment variable in your terminal: | ||
| ```bash | ||
|
|
@@ -54,13 +60,6 @@ flowchart LR | |
| ``` | ||
| </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 | ||
|
|
@@ -76,20 +75,3 @@ flowchart LR | |
| - 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> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| --- | ||
| title: "Custom Python MCP Client" | ||
| sidebarTitle: "Custom Python Client" | ||
| description: "Guide for creating a client to interact with a custom Python MCP server" | ||
| icon: "person-digging" | ||
| --- | ||
|
|
||
| ## Custom Python MCP Client | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[Query] --> Agent[AI Agent] | ||
| Agent --> Client[Python MCP Client] | ||
| Client --> Server[Python MCP Server] | ||
| Server --> Client | ||
| Client --> Agent | ||
| Agent --> Out[Answer] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Client fill:#3776AB,color:#fff | ||
| style Server fill:#3776AB,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Overview | ||
|
|
||
| The Custom Python MCP Client demonstrates how to integrate a custom Python MCP server with a PraisonAI agent. This client connects to a stock price MCP server to retrieve real-time stock information. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Install Dependencies"> | ||
| Install the required packages: | ||
| ```bash | ||
| pip install praisonaiagents mcp | ||
| ``` | ||
| </Step> | ||
| <Step title="Set Up the Server"> | ||
| First, set up the Custom Python MCP Server. | ||
| </Step> | ||
| <Step title="Create Custom Python Client"> | ||
| Save the code above to a file named `custom-python-client.py`. | ||
| ```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("/Users/praison/miniconda3/envs/mcp/bin/python /Users/praison/stockprice/custom-python-server.py") | ||
| ) | ||
|
Comment on lines
+51
to
+52
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. This line contains a hardcoded path to the Python interpreter and the custom server script. This makes the example less portable. Suggest using environment variables or a more flexible path configuration. |
||
|
|
||
| # NOTE: Python Path replace with yours: /Users/praison/miniconda3/envs/mcp/bin/python | ||
| # NOTE: custom-python-server.py file path, replace it with yours: /Users/praison/stockprice/custom-python-server.py | ||
|
|
||
| agent.start("What is the stock price of Tesla?") | ||
| ``` | ||
|
Comment on lines
+43
to
+58
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. Consider adding error handling to the client code to catch potential exceptions during the MCP call. This would improve the robustness of the example and guide users on how to handle errors in their own implementations. |
||
| </Step> | ||
| <Step title="Run the Client"> | ||
| Execute the client script: | ||
| ```bash | ||
| python custom-python-client.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - praisonaiagents and mcp packages | ||
| - A properly configured custom Python MCP server | ||
| - OpenAI API key (for the agent's LLM) | ||
| </Note> | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| For better security and flexibility, you can modify the client to use environment variables: | ||
|
|
||
| ```python | ||
| import os | ||
| from praisonaiagents import Agent, MCP | ||
|
|
||
| # Get paths from environment variables or use defaults | ||
| python_path = os.getenv("PYTHON_PATH", "/path/to/python") | ||
| server_path = os.getenv("SERVER_PATH", "/path/to/server.py") | ||
|
|
||
| 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(f"{python_path} {server_path}") | ||
| ) | ||
|
|
||
| agent.start("What is the stock price of Tesla?") | ||
| ``` | ||
|
|
||
| This approach allows you to set the paths using environment variables: | ||
|
|
||
| ```bash | ||
| export PYTHON_PATH=/Users/praison/miniconda3/envs/mcp/bin/python | ||
| export SERVER_PATH=/Users/praison/stockprice/app.py | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| --- | ||
| title: "Custom Python MCP Server" | ||
| sidebarTitle: "Custom Python Server" | ||
| description: "Guide for creating a custom Python MCP server for stock price retrieval" | ||
| icon: "server" | ||
| --- | ||
|
|
||
| ## Custom Python MCP Server | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| In[Query] --> Agent[AI Agent] | ||
| Agent --> Client[Python MCP Client] | ||
| Client --> Server[Python MCP Server] | ||
| Server --> Client | ||
| Client --> Agent | ||
| Agent --> Out[Answer] | ||
|
|
||
| style In fill:#8B0000,color:#fff | ||
| style Agent fill:#2E8B57,color:#fff | ||
| style Client fill:#3776AB,color:#fff | ||
| style Server fill:#3776AB,color:#fff | ||
| style Out fill:#8B0000,color:#fff | ||
| ``` | ||
|
|
||
| ## Overview | ||
|
|
||
| The Custom Python MCP Server is a simple implementation of the Model Context Protocol (MCP) that provides stock price information using the yfinance library. This server can be used with PraisonAI agents to retrieve real-time stock prices. | ||
|
|
||
| ## Server Implementation | ||
|
|
||
| Below is the complete implementation of the custom Python MCP server: | ||
|
|
||
|
Comment on lines
+30
to
+33
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. The section "Server Implementation" is followed by "Below is the complete implementation of the custom Python MCP server:", but the actual code is missing here. Please include the code snippet for the server implementation. |
||
|
|
||
| ## Quick Start | ||
|
|
||
| <Steps> | ||
| <Step title="Install Dependencies"> | ||
| Install the required packages: | ||
| ```bash | ||
| pip install yfinance mcp | ||
| ``` | ||
| </Step> | ||
| <Step title="Save the Server Code"> | ||
| Save the code above to a file named `custom-python-server.py`. | ||
| ```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> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - yfinance package | ||
| - mcp package | ||
| </Note> | ||
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.
This step installs
praisonaiagentsandmcpusing pip. Ensure this is consistent across all MCP integration guides. Consider mentioning the need for a virtual environment to avoid conflicts with system-level packages.