How gomezzz299/mcp works
Project type and purpose
• This is a full-stack, multi-agent question-routing system (“MCP”) with:
• A backend (FastAPI) that hosts core logic, agent orchestration and a SQLite database
• A frontend GUI (Streamlit) that sends user requests to the backend
• Modular “agents” that can call LLMs or each other to answer queries
File structure
─ Top-level containers and orchestration
• Dockerfile.frontend, Dockerfile.backend, docker-compose.yml
─ Frontend
• gui/app.py (Streamlit GUI)
• .streamlit/secrets.toml (backend URL)
─ Backend
• server/api.py (FastAPI endpoints)
• server/mcp_server.py (agent registry, message dispatch)
─ Core logic
• core/router_llm.py (smart router that picks an agent)
• core/context_loader.py (loads contextual data from DB)
• core/ollama_wrapper.py (calls Ollama LLM)
─ Agents
• agentes/*.py (fecha_hora, ubicacion, clima, estado_servidor) all inheriting from utils/agente_base.py
─ Utilities & DB
• utils/db_utils.py, json_parser.py
• database/context.db (SQLite), create_db.py, comprobar_db.py
─ Configuration
• config.py (central flags, paths, model names)
README for additional insights
• Features: modular agents, LLM wrapper, containerized frontend+backend
• Deployment: docker-compose elevates two containers (frontend:8501, backend:8000)
• Agent collaboration: e.g. clima agent calls ubicacion agent for geo-coordinates
a. Main components
• Frontend Container (Streamlit GUI)
• Backend Container (FastAPI App)
• Core Services within backend:
– API Layer (server/api.py)
– Dispatcher/Server (server/mcp_server.py)
– Router (core/router_llm.py)
– Context Loader (core/context_loader.py)
– LLM Wrapper (core/ollama_wrapper.py)
• Agent Module (agentes/*.py)
• Database (SQLite context.db)
• External Services:
– Ollama LLM endpoint
– (Optionally) third-party weather or geolocation APIs
b. Relationships and data flow
1. User interacts with Streamlit GUI → sends HTTP POST to FastAPI /process
2. API Layer receives request → forwards to mcp_server dispatch
3. mcp_server registers available agents → delegates to router_llm
4. router_llm analyzes user query → picks appropriate agent(s)
5. Chosen agent:
• (Optionally) calls other agents (e.g. clima → ubicacion)
• Queries context Loader → may hit SQLite via db_utils
• Calls LLM via ollama_wrapper if natural language generation is needed
6. Agent returns structured response → mcp_server wraps it → API returns to GUI
c. Architectural patterns and principles
• Modular plugin pattern for agents (inherit from AgenteBase)
• Layered architecture: GUI → API → Dispatcher → Router → Agents → DB/LLM
• Hexagonal/adapters for external integrations (DB, LLM service)
• Containerized micro-services style separation (frontend vs backend)
d. Key technologies and frameworks
• Python 3.x
• FastAPI (server/api.py)
• Streamlit (gui/app.py)
• SQLite (database/context.db)
• Docker & Docker Compose
• Ollama LLM via core/ollama_wrapper.py