aimdb-mcp 0.8.0

Model Context Protocol (MCP) server for AimDB - enables LLM-powered introspection
Documentation
//! MCP tools implementation
//!
//! Tools for discovering and interacting with AimDB instances.

use crate::connection::ConnectionPool;
use once_cell::sync::OnceCell;

pub mod architecture;
pub mod buffer_metrics;
pub mod graph;
pub mod instance;
pub mod profiling;
pub mod record;
pub mod schema;

// Global connection pool (initialized once)
static CONNECTION_POOL: OnceCell<ConnectionPool> = OnceCell::new();

// Default socket path set by --socket at startup (takes precedence over AIMDB_SOCKET env var)
static DEFAULT_SOCKET: OnceCell<String> = OnceCell::new();

/// Initialize the connection pool for tools
pub fn init_connection_pool(pool: ConnectionPool) {
    CONNECTION_POOL.set(pool).ok();
}

/// Set the default socket path (called once at startup from --socket flag).
pub fn set_default_socket(path: String) {
    DEFAULT_SOCKET.set(path).ok();
}

/// Get the connection pool
pub(crate) fn connection_pool() -> Option<&'static ConnectionPool> {
    CONNECTION_POOL.get()
}

/// Resolve the socket path from an explicit argument, the `--socket` flag, or
/// the `AIMDB_SOCKET` env var (checked in that order).
///
/// Returns an error if none are set.
pub(crate) fn resolve_socket_path(explicit: Option<String>) -> crate::error::McpResult<String> {
    explicit
        .or_else(|| DEFAULT_SOCKET.get().cloned())
        .or_else(|| std::env::var("AIMDB_SOCKET").ok())
        .filter(|s| !s.is_empty())
        .ok_or_else(|| {
            crate::error::McpError::InvalidParams(
                "Missing socket_path (pass it explicitly, use --socket, or set AIMDB_SOCKET env var)".into(),
            )
        })
}

// Re-export tool functions
pub use architecture::{
    get_architecture, propose_add_binary, propose_add_connector, propose_add_record,
    propose_add_task, propose_modify_buffer, propose_modify_fields, propose_modify_key_variants,
    remove_binary, remove_record, remove_task, rename_record, reset_session, resolve_proposal,
    save_memory, validate_against_instance,
};
pub use buffer_metrics::{get_buffer_metrics, reset_buffer_metrics};
pub use graph::{graph_edges, graph_nodes, graph_topo_order};
pub use instance::{discover_instances, get_instance_info};
pub use profiling::{get_stage_profiling, reset_stage_profiling};
pub use record::{drain_record, get_record, list_records, set_record};
pub use schema::query_schema;