Use MCP with Any LLM

Pair any MCP connector or server with OpenAI, Anthropic, Google Gemini, Ollama, Groq, OpenRouter, Mistral, or xAI by changing one llm= string

Every PraisonAI MCP connector and server works identically with any supported LLM provider — switch between OpenAI, Anthropic, Google Gemini, local Ollama, Groq, OpenRouter, Mistral, or xAI by changing a single llm= string on Agent(...).

python
from praisonaiagents import Agent, MCP

agent = Agent(
    name="Researcher",
    instructions="Use the connected MCP tools to answer accurately.",
    llm="anthropic/claude-sonnet-4-20250514",  # swap to any provider below
    tools=MCP("https://mcp.deepwiki.com/mcp"),
)

agent.start("Explain how MervinPraison/PraisonAI structures its multi-agent workflows")

The user swaps only the llm= parameter; PraisonAI translates the MCP server’s tool schemas automatically for whichever model provider runs the agent.

Diagram

👤 User

🤖 PraisonAI Agent

🧠 Any LLM Provider
OpenAI · Claude · Gemini · Ollama · Groq

🔌 Any MCP Connector
Remote HTTP · Local STDIO

✅ Grounded Answer


Quick Start by Provider

  1. Install PraisonAI with LLM & MCP support
    bash
    pip install "praisonai[mcp]"
  2. Choose your LLM provider

    OpenAI

    bash
    export OPENAI_API_KEY="${OPENAI_API_KEY:?Set OPENAI_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="openai/gpt-4o",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    Anthropic

    bash
    export ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:?Set ANTHROPIC_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="anthropic/claude-sonnet-4-20250514",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    Google Gemini

    bash
    export GEMINI_API_KEY="${GEMINI_API_KEY:?Set GEMINI_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="gemini/gemini-2.5-flash",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    Ollama (Local / Keyless)

    If Ollama is running locally, PraisonAI works with no API key — see Keyless Local-First Run.

    bash
    ollama pull llama3.2
    python
    import sys
    from praisonaiagents import Agent, MCP
    
    # Works with remote MCP servers OR local Python / Node.js MCP servers:
    agent = Agent(
        instructions="Use connected MCP tools to answer accurately.",
        llm="ollama/llama3.2",
        tools=MCP(command=sys.executable, args=["path/to/your/mcp_server.py"]),
    )
    agent.start("Run my local Python MCP tool")

    Groq

    bash
    export GROQ_API_KEY="${GROQ_API_KEY:?Set GROQ_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="groq/llama-3.3-70b-versatile",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    OpenRouter

    bash
    export OPENROUTER_API_KEY="${OPENROUTER_API_KEY:?Set OPENROUTER_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="openrouter/openai/gpt-4o-mini",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    Mistral

    bash
    export MISTRAL_API_KEY="${MISTRAL_API_KEY:?Set MISTRAL_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="mistral/mistral-large-latest",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

    xAI (Grok)

    bash
    export XAI_API_KEY="${XAI_API_KEY:?Set XAI_API_KEY in your shell}"
    python
    from praisonaiagents import Agent, MCP
    
    agent = Agent(
        instructions="Use connected MCP tools to help the user.",
        llm="xai/grok-3-mini",
        tools=MCP("https://mcp.deepwiki.com/mcp"),
    )
    agent.start("Summarize the architecture of MervinPraison/PraisonAI")

Provider Requirements at a Glance

ProviderModel PrefixEnvironment VariableLocal / Offline?
OpenAIopenai/...OPENAI_API_KEYNo
Anthropicanthropic/...ANTHROPIC_API_KEYNo
Google Geminigemini/...GEMINI_API_KEYNo
Ollamaollama/...None (local server)Yes
Groqgroq/...GROQ_API_KEYNo
OpenRouteropenrouter/...OPENROUTER_API_KEYNo
Mistralmistral/...MISTRAL_API_KEYNo
xAI (Grok)xai/...XAI_API_KEYNo

Best Practices

Use tool-calling capable models for MCP

Choose models with reliable function/tool calling (for example gpt-4o, claude-sonnet-4, gemini-2.5-flash, or ollama/llama3.2 / qwen2.5). Smaller base models without tool-calling support may ignore MCP tool schemas.

Keep your LLM API key out of MCP subprocess env

Pass your LLM key in your shell environment for Agent(...) — only pass service-specific tokens (like SLACK_BOT_TOKEN or DATABASE_URL) inside MCP(..., env={...}).

Run 100% locally with Ollama + local STDIO MCP

Pair llm="ollama/llama3.2" with local STDIO connectors like Filesystem Connector or PostgreSQL Connector so neither prompts nor tool data ever leave your machine.


Related