Skip to main content
MCP (Model Context Protocol) enables agents to connect to external tool servers using standardized transports - stdio, SSE, HTTP stream, or WebSocket.

Quick Start

1

Install MCP Support

pip install praisonaiagents[mcp]
2

Connect to MCP Server

from praisonaiagents import Agent
from praisonaiagents.mcp import MCP

# Connect to an MCP server
agent = Agent(
    instructions="You are a helpful assistant",
    tools=MCP("python /path/to/mcp_server.py")
)

agent.start("Use the available tools to help me")

Transport Types

TransportURL PatternUse Case
stdioCommand stringLocal subprocess servers
SSEhttp://...​/sseLegacy HTTP+SSE servers
HTTP Streamhttp://...Modern HTTP servers
WebSocketws://... or wss://...Real-time bidirectional

Connection Methods

Stdio (Subprocess)

from praisonaiagents.mcp import MCP

# Method 1: Single command string
tools = MCP("python /path/to/server.py")

# Method 2: Separate command and args
tools = MCP(
    command="/usr/bin/python",
    args=["/path/to/server.py"]
)

# Method 3: NPX for npm packages
tools = MCP("npx -y @anthropic/mcp-server-fetch")

HTTP/SSE

# SSE endpoint (legacy)
tools = MCP("http://localhost:8080/sse")

# HTTP Stream (modern)
tools = MCP("http://localhost:8080/mcp")

WebSocket

# WebSocket connection
tools = MCP("wss://mcp.example.com/ws")

# With authentication
tools = MCP(
    "wss://mcp.example.com/ws",
    auth_token="your-token"
)

Configuration Options

from praisonaiagents.mcp import MCP

mcp = MCP(
    command_or_string="python server.py",  # Command or URL
    args=None,                              # Arguments (for stdio)
    timeout=60,                             # Initialization timeout
    debug=False,                            # Enable debug logging
    # HTTP Stream options
    responseMode="streaming",               # Response mode
    headers={"Authorization": "Bearer ..."},
    # WebSocket options
    auth_token="token",                     # Auth token
)
OptionTypeDefaultDescription
command_or_stringstrRequiredCommand, URL, or command string
argslistNoneArguments for stdio transport
timeoutint60Timeout in seconds
debugboolFalseEnable debug logging
auth_tokenstrNoneAuthentication token (WebSocket)

How It Works

Tool Discovery

MCP automatically discovers tools from the server:
from praisonaiagents.mcp import MCP

mcp = MCP("python server.py")

# Tools are automatically available
print(mcp.tools)  # List of callable functions

Tool Execution

Tools are executed through the MCP protocol:
agent = Agent(
    instructions="You can search the web",
    tools=MCP("npx -y @anthropic/mcp-server-fetch")
)

# Agent automatically uses MCP tools
agent.start("Fetch the content from example.com")

Creating MCP Servers

Expose your tools as an MCP server:
from praisonaiagents.mcp import ToolsMCPServer, launch_tools_mcp_server

def my_tool(query: str) -> str:
    """Search for information."""
    return f"Results for: {query}"

# Create and launch server
server = ToolsMCPServer(tools=[my_tool])
launch_tools_mcp_server(server)

Common Patterns

NPX Servers (Smithery)

# Fetch server
tools = MCP("npx -y @anthropic/mcp-server-fetch")

# Filesystem server
tools = MCP("npx -y @anthropic/mcp-server-filesystem /path/to/dir")

# GitHub server
tools = MCP("npx -y @anthropic/mcp-server-github")

Multi-Server Setup

from praisonaiagents import Agent
from praisonaiagents.mcp import MCP

# Combine tools from multiple servers
fetch_tools = MCP("npx -y @anthropic/mcp-server-fetch")
fs_tools = MCP("npx -y @anthropic/mcp-server-filesystem .")

agent = Agent(
    instructions="You can fetch web content and manage files",
    tools=fetch_tools + fs_tools  # Combine tool lists
)

Best Practices

  • stdio: Best for local tools, simple setup
  • HTTP Stream: Best for remote servers, modern standard
  • WebSocket: Best for real-time, bidirectional communication
Increase timeout for slow-starting servers or network latency.
Use debug=True to see MCP protocol messages when debugging.
MCP servers may not always be available. Handle initialization failures gracefully.