How ziruiwang1996/ai-agent-mcp works
Project Type and Purpose
• This is a full-stack, modular AI agent framework.
• Frontend: Streamlit web UI.
• Backend: FastAPI service exposing chatbot endpoints.
• LLM Host: Gemini (and future HuggingFace) chatbot wrappers.
• Tool/Service Layer: A set of MCP microservices (arXiv, OpenFDA, ClinicalTrials, PDB, filesystem, etc.).
• Purpose: Enable tool-augmented reasoning by combining LLMs + external data sources via the Model Context Protocol.
Main Components
A. Streamlit Frontend
– File: streamlit_app/home_page.py
– Role: User interacts via a browser; sends chat messages.
B. FastAPI Backend
– File: src/fastapi_app.py
– Role: HTTP API gateway between UI and chatbot host.
C. Chatbot Host Layer
– Files: src/host/gemini_chatbot.py (and future HuggingFace_LLM.py)
– Role: Wraps LLM calls, manages conversation state.
D. Chatbot Client/Tool Manager
– File: src/client/gemini_client.py & server_config.json
– Role: Reads MCP server configuration; launches/manages subprocesses for each tool.
E. MCP Microservices
– Directory: src/mcp-server/
– Servers: arxiv_server.py, clinicaltrials_server.py, openfda_server.py, pdb_server.py (plus future rdkit, pubmed, filesystem via Node.js)
– Role: Provide external data/tool functionality via a simple protocol.
F. External Dependencies & Config
– .env (API keys), requirements.txt, Dockerfile (optional containerization), etc/jupyter and share/jupyter (Jupyter extensions)
Relationships & Data Flows
• User → Streamlit UI: user submits query.
• Streamlit UI → FastAPI: REST call (e.g. POST /chat).
• FastAPI → Host Chatbot: passes user message to gemini_chatbot.
• Host → Client/Tool Manager: invokes MCP tools via subprocesses per server_config.json.
• Client → MCP Servers: starts subprocesses (Python scripts or npx commands).
• MCP Servers → External APIs/Data Sources: each microservice queries its designated API or filesystem.
• Results flow back: MCP Servers → Client → Host → FastAPI → Streamlit → User.
Architectural Patterns & Design Principles
• Layered Architecture: UI / API / Host / Tool Manager / Microservices
• Plugin-style / Microservices: each MCP server is a self-contained process.
• Configuration-driven: server_config.json drives tool instantiation.
• Separation of concerns: LLM logic separated from tool logic.
• Incremental streaming: both Streamlit and FastAPI can stream partial responses for a responsive UX.