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.
Save the code above to a file named custom-python-client.py.
Copy
from praisonaiagents import Agent, MCPagent = 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"))# 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.pyagent.start("What is the stock price of Tesla?")
For better security and flexibility, you can modify the client to use environment variables:
Copy
import osfrom praisonaiagents import Agent, MCP# Get paths from environment variables or use defaultspython_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: