An MCP-powered assistant that can use math, weather, translation, web search, and Gmail tools from one ReAct loop.
The current implementation uses one main entrypoint:
- API mode:
client.pystarts a FastAPI app on port 8080 - CLI mode:
client.py --clistarts an interactive terminal chat
- ReAct tool-calling loop with duplicate-call protection
- Multi-step tool chaining handled by the model
- FAISS memory with periodic conversation summarization
- FastAPI endpoints for chat, clear, and health
- 5 MCP stdio tool servers:
mathserver.py->solve_mathweather.py->get_weather,get_air_qualitytranslate.py->translatewebsearch.py->web_searchgmail.py->send_email,read_emails
flowchart TD
A[User Input] --> B{Entry Mode}
B -->|Web| C[FastAPI app in client.py]
B -->|CLI| D[Interactive loop in client.py --cli]
C --> E[initialize_backend]
D --> E
E --> E1[Load .env and rotate GROQ keys]
E1 --> E2[Load or create FAISS index]
E2 --> E3[Start MCP stdio tool servers]
E3 --> F[Bind tools to agent LLM]
F --> G[Build messages with system prompt + history + summary]
G --> H{ReAct step <= MAX_REACT_STEPS}
H -->|No tool call| I[Return final assistant response]
H -->|Tool call| J[Execute selected MCP tool]
J --> J1[Math server]
J --> J2[Weather/Air quality server]
J --> J3[Translation server]
J --> J4[Web search server]
J --> J5[Gmail server]
J1 --> K[Append ToolMessage observation]
J2 --> K
J3 --> K
J4 --> K
J5 --> K
K --> H
I --> L[Persist user+assistant turns to FAISS]
L --> M{History >= SUMMARIZE_AFTER}
M -->|Yes| N[Summarize older conversation]
M -->|No| O[Send response]
N --> O
- Input enters through web endpoint or CLI loop.
- Backend initializes model, memory, and MCP tool connections.
- Agent runs a ReAct loop and decides whether to call tools.
- Tool results are fed back as observations until a final answer is produced.
- Conversation is saved in FAISS, and older turns are summarized periodically.
agenticaimcp/
├── client.py
├── client_changes.py
├── server.py
├── main.py
├── executioner.py
├── intent_router.py
├── rule_based_verifier.py
├── mathserver.py
├── weather.py
├── translate.py
├── websearch.py
├── gmail.py
├── debug_script.py
├── website.html
├── Dockerfile
├── requirements.txt
├── pyproject.toml
└── faiss_index/
Notes:
client.pyis the primary runtime path.server.py,executioner.py,intent_router.py, andrule_based_verifier.pyare still present as alternate/legacy components.main.pycurrently does not contain runtime logic.
pip install -r requirements.txtCreate a .env file in the project root:
# Agent keys used by client.py (rotation supported)
GROQ_API_KEY_1=gsk_xxx
GROQ_API_KEY_2=gsk_xxx
GROQ_API_KEY_3=gsk_xxx
# Math tool currently reads GROQ_API_KEY directly
# You can set this to the same value as GROQ_API_KEY_1.
GROQ_API_KEY=gsk_xxx
# Required for web search tool
TAVILY_API_KEY=tvly-xxx
# Optional: Gmail token for local/headless usage (base64 encoded token.json)
# GMAIL_TOKEN_JSON=eyJ0eXBlIjogLi4ugmail.py supports either:
/app/token.jsonmounted into the container or runtime filesystemGMAIL_TOKEN_JSONenvironment variable (base64-encoded JSON token)
If neither is provided, Gmail tools will return an auth error.
python client.pyOr directly with uvicorn:
uvicorn client:app --host 0.0.0.0 --port 8080 --reloadOpen:
http://localhost:8080/for the HTML chat pagehttp://localhost:8080/healthfor health status
python client.py --cliCLI commands:
clearresets FAISS/chat memoryexit,quit, orqexits
POST /chat- Body:
{"message": "your prompt"} - Returns:
{"response": "...", "status": "success|error"}
- Body:
POST /clear- Resets memory and conversation state
GET /health- Returns service status, loaded tools, and state metadata
Example:
curl -X POST http://localhost:8080/chat \
-H "Content-Type: application/json" \
-d '{"message": "weather in London"}'Build:
docker build -t my-app:latest .Run (PowerShell example on Windows):
docker run -p 8080:8080 --env-file .env -v "D:\agenticaimcp\token.json:/app/token.json" my-app:latestThe container starts:
python -m uvicorn client:app --host 0.0.0.0 --port 8080python debug_script.pyThis validates each MCP tool server can start and reports discovered tools.
In client.py:
SUMMARIZE_AFTER = 6
MAX_REACT_STEPS = 6
TOOL_TIMEOUT = 60- FastAPI
- LangChain
- MCP / FastMCP
- Groq chat models
- FAISS + sentence-transformers embeddings
- Tavily search
- Gmail API
- SymPy + SciPy
- LangChain
- Groq
- Tavily
- FastMCP