saurav-samantray/ollama-agent-with-mcp
If you are the rightful owner of ollama-agent-with-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCP Server and Ollama AI Agent project demonstrates an AI pattern where an autonomous agent uses external tools to answer questions.
get_weather
Fetches weather information for a specified location.
get_stock_price
Retrieves the current stock price for a specified company.
currency_converter
Converts currency values based on current exchange rates.
calculator
Performs basic arithmetic calculations.
MCP Server and Ollama AI Agent
This project demonstrates a powerful AI pattern: an autonomous agent that uses external tools to answer questions. It consists of two applications:
- MCP Server: A FastAPI server that provides a set of tools (Weather, Stocks, Currency, Calculator) via a REST API.
- AI Agent: A command-line agent powered by a local Ollama LLM that can intelligently decide which tool to use to respond to a user's query.
Prerequisites
- Python: You must have Python 3.8+ installed.
- Ollama: You must have Ollama installed and running on your machine.
- Ollama Model: You need to have a model pulled. We recommend
llama3
. You can get it by running:Once you see theollama run llama3
>>>
prompt, you can type/bye
to exit. The model is now available for the agent to use.
Step 1: Set Up and Run the MCP Server
The server provides the tools for the agent.
-
Navigate to the server directory:
cd mcp_server
-
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Run the server:
python server.py
You should see output indicating the server is running on http://127.0.0.1:8000
. Keep this terminal window open. You can verify it's working by opening http://127.0.0.1:8000/docs
in your browser.
Step 2: Set Up and Run the AI Agent
The agent will connect to the server you just started.
-
Open a new terminal window.
-
Navigate to the agent directory:
cd ai_agent
-
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Run the agent:
python agent.py
Step 3: Interact with the Agent
Once the agent is running, you will see a >
prompt. You can now ask it questions that require it to use its tools. The agent will print its "thought process" in real-time.
Example Questions:
What is the weather like in London?
(Uses theget_weather
tool)What is the price of Apple stock?
(Uses theget_stock_price
tool)How many US dollars is 100 Euros?
(This requires two steps: first getting the exchange rate, then using the calculator)What is 55 times 3.14?
(Uses thecalculator
tool)What is the weather in Tokyo and what is the price of Microsoft stock?
(Uses multiple tools)Who is the president of the United States?
(The agent should answer this from its own knowledge, without using a tool)