This project demonstrates how to build a Model Context Protocol (MCP) server using FastMCP and connect it to an LLM agent powered by the Groq API.
The demo consists of two main components:
banking_mcp_server.py: A FastMCP server that exposes a tool to fetch a list of available banks from the public Open Bank Project sandbox API.llm_agent.py: A ReAct-style LLM agent that connects to the MCP server, discovers the available tools, and uses them to answer user questions.
This architecture showcases how to securely and standardly provide external tools and context to any LLM-powered application or chatbot.
🤖 Starting ReAct LLM Agent...
🔌 Connecting to MCP Server at http://127.0.0.1:8080/mcp...
Which banks can I have information about?
--- Turn 1 ---
🧠 Thinking...
🤔 Thought: The user is asking for a list of banks. I should use the 'get_available_banks' tool to fetch this information. The tool has no parameters.
🎬 Action: tool_calls
👀 Observation sent to LLM.
--- Turn 2 ---
🧠 Thinking...
🤔 Thought: The user is asking for a list of banks. I should use the 'get_available_banks' tool to fetch this information. The tool has no parameters.
🎬 Action: tool_calls
👀 Observation sent to LLM.
--- Turn 3 ---
🧠 Thinking...
🤔 Thought: The user is asking for a list of banks. I should use the 'get_available_banks' tool to fetch this information. The tool has no parameters.
🎬 Action: tool_call
-> Calling tool 'get_available_banks' via MCP server...
-> Tool executed successfully.
👀 Observation sent to LLM.
--- Turn 4 ---
🧠 Thinking...
🤔 Thought: I have successfully retrieved the list of available banks. I will now present this list to the user to answer their question.
🎬 Action: finish
==================================================
🤖 Final LLM Response:
==================================================
I can provide information on the following banks: Royal Bank of Scotland, Test Bank, Testowy bank, Nordea Bank AB, Hongkong and Shanghai Bank, Erste Bank Test, Deutche Bank Test, Bank X, Bank Y, Abanca, Banca March, Banco Santander, Banco Pastor, Banco Popular, Bankia, Bankinter, BBVA, BMN, CaixaBank, Cetelem, Deutsche Bank, Ibercaja, ING, Kutxabank, Liberbank, Open Bank, Sabadell, Unicaja, and many more.- Python 3.10+
- An API key from GroqCloud.
-
Clone the repository:
git clone https://github.com/cbarkinozer/mcp-demo cd mcp-demo -
Install dependencies: It's recommended to use a virtual environment.
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install -r requirements.txt
-
Set Environment Variable: You only need to set one environment variable for the Groq API key.
On Linux/macOS:
export GROQ_API_KEY="your_groq_api_key_here"
On Windows (Command Prompt):
set GROQ_API_KEY="your_groq_api_key_here"
Note: You may need to restart your terminal for the variable to be recognized.
You need to run the server and the agent in two separate terminals.
Terminal 1: Start the MCP Server
Navigate to the project directory and run:
python banking_mcp_server.pyYou should see output indicating the server has started and is listening on http://127.0.0.1:8080.
Terminal 2: Run the LLM Agent
In a new terminal (with the same environment variable set), run the agent:
python llm_agent.pyThe agent will:
- Connect to the MCP server.
- Discover the
get_available_bankstool. - Use its ReAct loop to think, decide to use the tool, and call it via the MCP server.
- Receive the bank data and send it back to Groq for a final, summarized answer.
- Print the final, human-friendly response.