Skip to main content

MCP Server API

Expose PraisonAI tools as MCP (Model Context Protocol) servers that can be consumed by Claude Desktop, Cursor, and other MCP clients.

Transport Types

MCP servers support two transport types:
TransportUse CaseEndpoint
stdioLocal CLI tools, Claude DesktopStandard input/output
SSERemote HTTP access/sse and /messages/

Starting the Server

Using ToolsMCPServer

from praisonaiagents.mcp import ToolsMCPServer

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

server = ToolsMCPServer(name="my-tools")
server.register_tool(search)
server.run(transport="stdio")  # or "sse"

Using launch_tools_mcp_server

from praisonaiagents.mcp import launch_tools_mcp_server

def my_tool(query: str) -> str:
    """Process a query."""
    return f"Processed: {query}"

launch_tools_mcp_server(
    tools=[my_tool],
    transport="sse",
    port=8080
)

Using Agent.launch with MCP

from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are helpful."
)

agent.launch(port=8080, protocol="mcp")

SSE Transport Endpoints

When using SSE transport, the server exposes:

GET /sse

Server-Sent Events endpoint for MCP communication. Connection
curl -N http://localhost:8080/sse
Response: SSE stream with MCP protocol messages.

POST /messages/

Send messages to the MCP server. Request
curl -X POST http://localhost:8080/messages/ \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
Response
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "search",
        "description": "Search the web for information.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "query": {"type": "string"}
          },
          "required": ["query"]
        }
      }
    ]
  }
}

MCP Protocol Methods

MethodDescription
tools/listList available tools
tools/callExecute a tool
initializeInitialize MCP session

tools/call Example

curl -X POST http://localhost:8080/messages/ \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "tools/call",
    "params": {
      "name": "search",
      "arguments": {"query": "AI news"}
    },
    "id": 2
  }'

Configuration

ToolsMCPServer Options

server = ToolsMCPServer(
    name="my-tools",      # Server name
    tools=[func1, func2], # Initial tools
    debug=True            # Enable debug logging
)

SSE Server Options

server.run_sse(
    host="0.0.0.0",  # Bind address
    port=8080        # Port number
)

Claude Desktop Configuration

Add to claude_desktop_config.json:
{
  "mcpServers": {
    "praisonai-tools": {
      "command": "python",
      "args": ["/path/to/mcp_server.py"]
    }
  }
}
For SSE transport:
{
  "mcpServers": {
    "praisonai-tools": {
      "url": "http://localhost:8080/sse"
    }
  }
}

Built-in Tools

Load built-in tools by name:
launch_tools_mcp_server(
    tool_names=["tavily_search", "exa_search", "wikipedia_search"],
    transport="stdio"
)

Error Responses

MCP errors follow JSON-RPC 2.0 format:
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}
CodeMessage
-32700Parse error
-32600Invalid request
-32601Method not found
-32602Invalid params
-32603Internal error

Installation

pip install "praisonaiagents[mcp]"

# For SSE transport
pip install uvicorn starlette

See Also