Skip to content

Architecture

┌─────────────────────────────────────────────────┐
│ MCP Host (any client) │
│ Claude Code, Codex CLI, Cursor, ... │
└──────────────────────┬──────────────────────────┘
│ MCP (stdio)
┌──────────────────────▼──────────────────────────┐
│ Hive MCP Server │
│ │
│ server.py (registration + resources + prompts) │
│ _context.py (ServerContext shared state) │
│ │
│ ┌─────────────┐ ┌────────────┐ ┌──────────┐ │
│ │ Vault+Session│ │Worker Tools│ │Resources │ │
│ │ _vault_read │ │ _workers │ │(5 URIs) │ │
│ │ _vault_write │ │ (2 tools) │ └──────────┘ │
│ │ _vault_health│ └─────┬──────┘ │
│ │ (8 tools) │ │ │
│ └──────┬──────┘ ┌─────▼──────┐ │
│ │ │ clients │ │
│ ┌──────▼──────┐ │ budget │ │
│ │ _helpers │ │ config │ │
│ │ frontmatter │ └────────────┘ │
│ │ usage │ │
│ └─────────────┘ │
└──────────────────────────────────────────────────┘
│ │
┌────▼────┐ ┌─────────▼──────────┐
│ Obsidian │ │ Ollama (local) │
│ Vault │ │ OpenRouter (cloud)│
└─────────┘ └────────────────────┘
ModuleRole
server.pyThin registration layer — resources, prompts, create_server()
_context.pyServerContext dataclass — shared state for all tool handlers
_helpers.pyPure functions — path resolution, formatting, git ops, tracking
_vault_read.pyRead tools — vault_list, vault_query, vault_search, session_briefing
_vault_write.pyWrite tools — vault_write, vault_patch
_vault_health.pyHealth tools — vault_health, health report builder
_workers.pyWorker tools — capture_lesson, delegate_task, worker_status
config.pypydantic-settings configuration with HIVE_ env prefix
frontmatter.pyYAML frontmatter parsing, validation, and generation
clients.pyAsync HTTP clients for Ollama and OpenRouter
budget.pySQLite budget tracker with WAL mode ($1/mo default cap)
relevance.pyEMA-based section relevance scoring for adaptive context
usage.pyTool call analytics and token estimation

Vault and worker functionality are served from a single FastMCP instance. Internally, tools are organized into domain modules (_vault_read, _vault_write, _vault_health, _workers) that register themselves via register_*(mcp, ctx) functions. Shared state lives in a ServerContext dataclass (_context.py), and pure utility functions live in _helpers.py.

create_server() accepts optional overrides for vault path, clients, and trackers. This enables testing without real infrastructure.

All vault writes auto-commit to git. This provides full history and enables vault_search(since_days=N) to detect changes via git log.

Worker delegation uses a SQLite database with WAL mode and explicit threading.Lock for thread-safe concurrent access. Monthly caps and per-request limits prevent cost overruns.