Ollama MCP AI Agents: Build POWERFUL & FREE Local AI in Minutes

By Mervin Praison

Share:

Key Concepts

  • Local AI Processing: Running AI models directly on your device, ensuring data privacy and eliminating reliance on cloud services.
  • Ollama: A tool for running large language models (LLMs) locally.
  • mCP (Model Context Protocol): A universal AI tool standard that allows AI agents to access and utilize various tools.
  • AI Agents: Software entities designed to perform specific tasks autonomously, often leveraging LLMs.
  • Prais Agents: A Python library simplifying the creation of AI agents with LLMs and mCP tools.
  • Gradio: A Python library for creating user interfaces for machine learning models.

Local AI Agents with mCP Tools using Ollama

Introduction

The video demonstrates how to create AI agents that run 100% locally using Ollama and leverage mCP tools for enhanced functionality. This approach offers privacy, cost-effectiveness, and unlimited usage compared to cloud-based AI services.

Benefits of Local AI Processing

  • Privacy: Data never leaves your device.
  • Cost: No monthly subscription fees.
  • Unlimited Usage: No API rate limits.

Ollama Setup

  1. Download Ollama: Go to https://ollama.com/ and download the appropriate version for your operating system.
  2. Pull the LLM: Open your terminal and run ollama pull llama3:latest to download the Llama 3 model.

Creating an AI Agent with Prais Agents and mCP

  1. Install Required Libraries: Run pip install prais agents gradio in your terminal.

  2. Create app.py: Create a new Python file named app.py and open it in your code editor.

  3. Import Libraries: Add the following lines to app.py:

    from praison_agents import agent, mcp
    import gradio as gr
    
  4. Define the Agent: Create an AI agent using the agent function, specifying the model and instructions:

    def search_airbnb(query):
        search_agent = agent(
            instruction="You help book apartments on Airbnb",
            llm="llama3:latest",
            tools=["airbnb"]
        )
        result = search_agent.start(query)
        return result
    
    • instruction: Defines the agent's purpose.
    • llm: Specifies the LLM to use (in this case, Llama 3).
    • tools: A list of mCP tools the agent can access.

Adding mCP Tools

  • mCP Servers: The video mentions a list of available mCP servers, including Airbnb.
  • Adding a Tool: Each mCP server has a specific command to add it to the agent. For example, the Airbnb tool requires running a command like npx -y @modelcontext/cli add airbnb --ignore-robots-txt.
  • Environment Variables: Some mCP tools require API keys or tokens, which can be set as environment variables (e.g., BRAVE_API_KEY for the Brave Search tool).

Creating a User Interface with Gradio

  1. Define the Interface: Use Gradio to create a user interface for interacting with the agent:

    iface = gr.Interface(
        fn=search_airbnb,
        inputs=gr.Textbox(lines=2, placeholder="Search for apartments in Paris for two nights 5th and 6th April 2025"),
        outputs="text",
        title="Airbnb Booking Assistant",
        description="Enter your search query to find apartments on Airbnb."
    )
    iface.launch()
    
    • fn: The function to call when the user submits the query (in this case, search_airbnb).
    • inputs: Defines the input field (a text box).
    • outputs: Specifies the output type (text).
    • title and description: Set the title and description of the user interface.
  2. Launch the Interface: Run demo.launch() to start the Gradio interface.

Running the Application

  1. Run the Script: Open your terminal and run python app.py.
  2. Access the Interface: Open the URL provided in the terminal (usually http://127.0.0.1:7860/) in your web browser.
  3. Enter a Query: Type your search query in the text box and click "Submit."
  4. View the Results: The AI agent will process the query using the Airbnb mCP tool and display the results in the output area.

Example Query

  • "Paris for two nights 5th and 6th April 2025"

Additional Resources

  • mCP Documentation: Clear documentation is available for mCP.
  • Example mCP Servers: Examples are provided for Brave Search, GitHub, and Google Maps.

Conclusion

The video demonstrates a simple and powerful way to create local AI agents with access to various tools using Ollama, Prais Agents, and mCP. This approach offers privacy, cost-effectiveness, and flexibility, enabling users to build custom AI solutions tailored to their specific needs. The use of Gradio further simplifies the process by providing an easy-to-use interface for interacting with the agents.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Ready to summarize another video?

Summarize YouTube Video