How openagentplatform/dive-mcp-host works
Project type and purpose
• Dive MCP Host is a Python-based language-model hosting service.
• It exposes both an HTTP/WebSocket API and a CLI, manages conversation state, persists to a database, and brokers calls to multiple external LLM providers.
File structure
• Top-level package: dive_mcp_host
• cli – command-line interface layer
• host – core “Model Context Protocol” engine, agents, chat orchestration, context/checkpoint helpers
• httpd – HTTP service (routers, middlewares, dependency injection, database migrations, msg_store abstractions)
• models – fake/example models for testing
• scheduler – (future) async task scheduling
• Configuration & infra: alembic.ini, mcp_config.json, model_config.json, scripts/run_pg.sh
• Tests cover host logic, HTTP routers, database stores, CLI, tools, etc.
README for additional insights
• Confirms feature set: unified LLM interface, persistence, HTTP+WebSocket API, CLI, multithreading.
• Mentions use of LangChain/LangGraph.
Main components
a. Interface Layer
• HTTP Server (FastAPI/Starlette app in dive_mcp_host/httpd)
• Routers (chat, config, models, tools, openai proxy, utils)
• Middlewares (general, kwargs parsing, rate limiter)
• CLI Client (dive_cli entry point in dive_mcp_host/cli)
b. Core Host Engine
• HostConfig & DiveMcpHost (lifecycle management)
• Agent Factory & ChatAgent (message sequencing, tool-in-prompt handling)
• Prompt & System Prompt modules
• Checkpointer, Context Manager
c. Data Layer
• Message Store abstraction (SQLite, PostgreSQL) in host/store and httpd/database/msg_store
• ORM models & Alembic migrations
• Cache & Local store for ephemeral data
d. External Dependencies
• LLM providers (OpenAI, Anthropic, Google, etc.)
• Local tools (echo, local_http_server, stdio_server, mcp_server)
e. Supporting Services
• Scheduler (background tasks)
• Logging subsystem
Relationships & interactions
• HTTP Server and CLI both depend on the Core Host Engine APIs.
• Core Engine invokes agents which request LLM responses via provider adapters.
• Core Engine reads/writes conversation state to the Data Layer.
• Database migrations are applied at startup via Alembic.
• Scheduler may trigger periodic jobs (e.g., cleaning up old contexts).
• Tools can be invoked in-prompt by agents (tool-in-prompt pattern).
Architectural patterns & design principles
• Layered architecture: Interface → Core → Data
• Dependency inversion: msg_store and model providers are abstract interfaces with concrete implementations (plugin-style)
• CQRS-style separation: routers handle HTTP concerns, delegating to host business logic
• Asynchronous concurrency: HTTP/WebSocket handlers and host chat sessions are async
Technologies, frameworks, and libraries
• Python 3.12+
• FastAPI/Starlette (HTTP service)
• Click or Typer (CLI)
• SQLAlchemy + Alembic (ORM & migrations)
• SQLite / PostgreSQL (message storage)
• LangChain / LangGraph (workflow orchestration)
• uv (uv pip, uv sync, uv run) for environment management
• PyTest for testing