The MCP (Model Context Protocol) module enables seamless integration of MCP-compliant tools and servers with PraisonAI agents, supporting multiple transport methods.
from praisonaiagents import Agent, MCP# Use the memory MCP server from NPXagent = Agent( name="Memory Assistant", instructions="You can store and retrieve memories.", tools=MCP("npx @modelcontextprotocol/server-memory"))response = agent.start("Remember that my favourite colour is blue")
# Python MCP serveragent = Agent( name="Data Assistant", tools=MCP("/usr/bin/python3 /path/to/mcp_server.py"))# Or with separate command and argsagent = Agent( tools=MCP( command="/usr/bin/python3", args=["/path/to/mcp_server.py", "--config", "config.json"] ))
PraisonAI supports passing multiple MCP server instances directly to an agent. You can combine different MCP servers along with regular Python functions.
from praisonaiagents import Agent, MCP# Pass multiple MCP instances directly in a listagent = Agent( name="Multi-Tool Assistant", instructions="You can manage files, memories, and check time.", tools=[ MCP("uvx mcp-server-time"), # Time tools MCP("npx @modelcontextprotocol/server-memory"), # Memory tools MCP("npx @modelcontextprotocol/server-filesystem /tmp") # File tools ])response = agent.start("What time is it in Tokyo? Then save this to memory.")
from praisonaiagents import Agent, MCPdef my_custom_tool(query: str) -> str: """A custom Python function tool.""" return f"Custom result for: {query}"# Combine MCP servers with regular Python functionsagent = Agent( name="Hybrid Assistant", instructions="You have access to time tools and a custom search.", tools=[ MCP("uvx mcp-server-time"), # MCP server my_custom_tool # Regular function ])
from praisonaiagents import Agent, MCP# Alternative: spread MCP tools into a listmemory_tools = MCP("npx @modelcontextprotocol/server-memory")file_tools = MCP("npx @modelcontextprotocol/server-filesystem")agent = Agent( name="Multi-Tool Assistant", tools=[*memory_tools, *file_tools])
from praisonaiagents import Agent, Task, AgentTeam, MCPimport os# Set up environmentos.environ["GITHUB_TOKEN"] = "ghp_..."# Create agent with multiple MCP toolsagent = Agent( name="DevOps Assistant", instructions="""You are a DevOps assistant that can: - Manage files and directories - Interact with GitHub repositories - Store and retrieve important information Use your tools wisely to help with development tasks.""", tools=[ MCP("npx @modelcontextprotocol/server-filesystem"), MCP("npx @modelcontextprotocol/server-github"), MCP("npx @modelcontextprotocol/server-memory") ])# Create taskstasks = [ Task( description="Check the current directory structure", agent=agent, expected_output="Directory listing with key files identified" ), Task( description="Remember the project structure for future reference", agent=agent, expected_output="Confirmation that structure is memorised" )]# Run the systemagents = AgentTeam(agents=[agent], tasks=tasks)result = agents.start()