Ollama Python MCP Integration

Guide for integrating Ollama models with Python MCP servers using PraisonAI agents

Add Ollama Python Tool to AI Agent

Diagram

In

AI Agent

Stock Price MCP

Out

Quick Start

  1. Set Up Ollama

    Make sure you have Ollama installed and running locally:

    bash
    # Install Ollama from https://ollama.ai/
    # Pull the llama3.2 model
    ollama pull llama3.2
  2. Create a file

    Create a new file ollama_stock.py with the following code:

    python
    from praisonaiagents import Agent, MCP
    
    stock_agent = Agent(
        instructions="""You are a Stock Price Assistant.""",
        llm="ollama/llama3.2",
        tools=MCP("/path/to/your/venv/bin/python /path/to/your/app.py")
    )
    
    # NOTE: Python Path replace with yours: /path/to/your/venv/bin/python
    # NOTE: app.py file path, replace it with yours: /path/to/your/app.py
    
    stock_agent.start("What is the Stock Price of Apple?")
  3. Install Dependencies

    Make sure you have the required packages installed:

    bash
    pip install "praisonaiagents[llm]" yfinance mcp
  4. Run the Agent

    Execute your script:

    bash
    python ollama_stock.py

Features