Skip to content

kamleshcode/fastmcp-multi-server-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastMCP Multi-Server Agent

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.


How It Works

  • 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.

Project Structure

├── 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

Quick Start

1. Install Dependencies

Run this command to install FastMCP, LangChain adapters, and all required libraries:

poetry install

2. Set Up Environment Variables

Create a .env file in the root folder and add model and mssql connection string:

CLOUD_MODEL= model name
MSSQL_CONN_STRING= your mssql connection string

3. Start Ollama

ollama serve

4. Run Backend App (Terminal 1)

This boots up your backend and connects to the background MCP servers automatically:

uvicorn main:app --reload

5. Run UI Frontend (Terminal 2)

streamlit run app.py

Open your browser and navigate to http://localhost:8501 to start testing your agent.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages