MCP + Ollama Local Tool Calling Example

by rajeevchandra

8 stars
699 downloads
Not rated
GitHub

Description

# MCP + Ollama Local Tool Calling Example This project demonstrates how a local AI agent can **understand user queries** and **automatically call Python functions** using: - Model Context Protocol (**MCP**) - **Ollama** for running a local LLM (e.g., Llama3) - **Python** MCP…

About

# MCP + Ollama Local Tool Calling Example This project demonstrates how a local AI agent can **understand user queries** and **automatically call Python functions** using: - Model Context Protocol (**MCP**) - **Ollama** for running a local LLM (e.g., Llama3) - **Python** MCP Client and Server --- ## 🔗 Sequence Diagram…

Details

Author
rajeevchandra
GitHub stars
8
Downloads
699
Categories
AI, Developer Tools, Other

- Uses MCP to describe tools for the LLM
- Runs a local LLM (e.g., Llama3) via Ollama
- Python functions (add, multiply) become callable tools
- Fully autonomous – no manual tool selection
- Everything runs offline and locally

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCP + Ollama Local Tool Calling Example
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install dependencies with pip install "mcp[cli] @ git+https://github.com/awslabs/mcp.git" openai==0.28 httpx, ensure Ollama is installed and running, pull a tool-calling‑capable model (e.g., ollama run llama3), run the MCP server (python math_server.py), then start the client with python ollama_client.py math_server.py. Finally, type queries like “What is 5 + 8?” and the system will respond with the computed result.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp + ollama local tool calling example": {
            "mcp-client-server-example": {
                "command": "python",
                "args": [
                    "math_server.py"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-client-server-example": {
        "command": "python",
        "args": [
            "math_server.py"
        ]
    }
}

MCP + Ollama Local Tool Calling Example

This project demonstrates how a local AI agent can understand user queries and automatically call Python functions using: - Model Context Protocol (MCP) - Ollama for running a local LLM (e.g., Llama3) - Python MCP Client and Server ---

🔗 Sequence Diagram

``mermaid sequenceDiagram participant User participant MCP_Client participant Ollama_LLM participant MCP_Server User->>MCP_Client: 1) User types: "What is 5 + 8?" MCP_Client->>Ollama_LLM: 2) Send available tools + user query Ollama_LLM->>Ollama_LLM: 3) Understand query & tool descriptions Ollama_LLM->>Ollama_LLM: 4) Select tool: add(a=5, b=8) Ollama_LLM->>MCP_Client: 5) Return tool_call MCP_Client->>MCP_Server: 6) Execute add(a=5, b=8) MCP_Server-->>MCP_Client: 7) Return result: 13 MCP_Client-->>User: 8) Show final answer: 13 ` ---

📚 Project Structure

` . ├── math_server.py # MCP Server exposing add() and multiply() tools ├── ollama_client.py # MCP Client interacting with Ollama ├── README.md # Project documentation ` ---

🛠️ Setup Instructions

1. Install Requirements

`bash pip install "mcp[cli] @ git+https://github.com/awslabs/mcp.git" openai==0.28 httpx ` Make sure you have Ollama installed and running.

2. Pull or run an LLM model

`bash ollama run llama3 ` (Ensure the model you run supports tool calling.)

3. Run the MCP Server

`bash python math_server.py ` The server exposes two simple tools: - add(a: int, b: int) -> int - multiply(a: int, b: int) -> int

4. Run the MCP Client

`bash python ollama_client.py math_server.py `

5. Interact!

Example queries:
` Query: What is 5 + 8? Response: 13 Query: Multiply 7 and 9 Response: 63 ` The MCP client sends the query and available tools to Ollama. The LLM internally decides which tool to use based on the tool descriptions and user intent. ---

🚀 How It Works

- MCP Client lists available tools. - Sends tools + user query to Ollama LLM. - LLM reasons about the best matching tool. - LLM generates a
tool_call. - MCP Client invokes the function via the MCP Server. - Final result is returned and displayed. ✅ No manual hardcoding! ✅ Everything runs locally! ✅ Fully autonomous! ---

📢 Why This Matters

This pattern enables building smart local AI agents that: - Understand user intent - Dynamically select the correct actions - Operate fully offline and locally It opens doors for: - Autonomous developers - Local intelligent assistants - Secure AI workflows ---

🏷️ Hashtags for Sharing

`text #MCP #ModelContextProtocol #Ollama #LocalLLM #FunctionCalling #Python #AI #DeveloperTools #AIEngineering #AutonomousAgents `` ---

🙌 Credits

- Model Context Protocol - Ollama --- > "Smarter AI agents start with understanding how they think!" --- > Next Steps: Add Streamlit UI or Dockerize this project 🚀
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.