A simple practice project to learn how to create an AI Agent that connects to multiple servers using the Model Context Protocol (MCP) and LangChain.
The main AI Agent automatically routes tasks to either a Database Server (to answer data questions) or a Math Server (to solve equations) depending on what you ask it.
- DB Server (
src/servers/db_server.py): Uses FastMCP to look up database tables and run SQL queries securely. - Math Server (
src/servers/math_server.py): Uses FastMCP to calculate arithmetic expressions. - Client Agent (
src/client.py): Built with LangChain. It connects to both servers over standard input/output (stdio), checks what tools are available, and uses Ollama to think and answer your questions.
├── app.py # Streamlit UI
├── main.py # FastAPI backend
├── src/
│ ├── client.py # LangChain agent
│ ├── db.py # Database connection
│ ├── config.py # Configuration
│ ├── prompt.py # System Prompt
│ └── servers/
│ ├── db_server.py # Database MCP server
│ └── math_server.py # Math MCP server
└── README.md
Run this command to install FastMCP, LangChain adapters, and all required libraries:
poetry installCreate a .env file in the root folder and add model and mssql connection string:
CLOUD_MODEL= model name
MSSQL_CONN_STRING= your mssql connection stringollama serveThis boots up your backend and connects to the background MCP servers automatically:
uvicorn main:app --reloadstreamlit run app.py