A LangChain + Ollama agent that talks to a FastMCP server using Llama 3.1 8B
This project demonstrates a fully functional AI agent that:
- Connects to a FastMCP JSON-RPC server over HTTP
- Discovers tools via
tools.list - Uses Llama 3.1 8B (via Ollama) to decide when to call tools
- Calls tools like
lunch_menu(date)andreport_absence(date, reason) - Returns natural language responses
No empty args. No missing parameters. 100% working.
mcp-school-tools/
├── mcp_server_fixed.py # MCP JSON-RPC server (manual registry)
├── mcp_agent_final_fixed.py # LangChain + Ollama agent (structured JSON)
├── README.md # This file
└── requirements.txt # Python dependencies
| Feature | Status |
|---|---|
| MCP Protocol (initialize, tools.list, tools.call) | Working |
| Tool Schema Discovery | Working |
| Structured Tool Calling | Working |
| Pydantic Validation | Working |
| JSON Response Parsing | Working |
| Ollama + Llama 3.1 8B | Working |
| No LangChain Agent Bugs | Working |
- Python 3.11+
- Ollama installed and running
- Llama 3.1 8B model pulled
ollama pull llama3.1:8bgit clone https://github.com/yourusername/mcp-school-tools.git
cd mcp-school-toolspip install -r requirements.txtrequirements.txt:
fastapi
uvicorn
langchain
langchain-ollama
langchain-core
pydantic
requestspython mcp_server_fixed.pyServer runs at: http://127.0.0.1:8000
python mcp_agent_final_fixed.py
### Ollama Start Up
Ollama serveYou: what is for lunch on 2025-11-09
LLM response: {'tool': 'lunch_menu', 'args': {'date': '2025-11-09'}}
Sending to MCP: lunch_menu(args={'date': '2025-11-09'})
Agent: Veggie Burger, Sweet Potato Fries, Orange Wedges
You: report absence on 2025-11-12 because I'm sick
LLM response: {'tool': 'report_absence', 'args': {'date': '2025-11-12', 'reason': "I'm sick"}}
Agent: Absence reported for 2025-11-12. Reason: I'm sick
- Agent sends
initialize→notifications/initialized→tools.list - Server returns full JSON schema for each tool
- Agent prompts Llama 3.1 with escaped JSON examples
- LLM outputs structured JSON:
{"tool": "...", "args": {...}} - Agent validates args with Pydantic
- Agent calls MCP server with
tools.call - Server executes tool and returns result
- Check MCP server logs for incoming
tools.call - Check agent logs for
Sending to MCP - Use
curlto test server directly:
curl -X POST http://127.0.0.1:8000 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools.call","params":{"tool":"lunch_menu","args":{"date":"2025-11-08"}},"id":1}'- Add function in
mcp_server_fixed.py - Register in
TOOLSdict withparameters - Add Pydantic model in
mcp_agent_final_fixed.py - Add to
TOOL_SCHEMAS
| Error | Fix |
|---|---|
missing 1 required positional argument |
Args not sent → use escaped JSON in prompt |
INVALID_PROMPT_INPUT |
Escape {{ and }} in prompt |
Unsupported function |
Don’t pass StructuredTool to with_structured_output |
| Ollama not responding | Run ollama serve |
- Web UI (Streamlit/Gradio)
- Conversation memory
- Async support
- Authentication
- More tools (grades, schedule, etc.)
MIT
Built with love for hackathons, demos, and learning.
Let me know when you're ready to deploy!