mcp-server-sqlite 1.0.0

An MCP server for SQLite with fine-grained access control
Documentation
//! MCP tool implementations. Each submodule defines a single tool by
//! implementing `SqliteServerTool` and providing the associated input, output,
//! error, and value types.

use std::fmt::Display;

use rmcp::model::{Content, IntoContents};

pub mod backup_tool;
pub mod create_fts_index_tool;
pub mod database_info_tool;
pub mod describe_table_tool;
pub mod execute_tool;
pub mod explain_query_tool;
pub mod list_foreign_keys_tool;
pub mod list_indexes_tool;
pub mod list_tables_tool;
pub mod list_triggers_tool;
pub mod list_views_tool;
pub mod search_fts_tool;
pub mod vacuum_tool;

/// The top-level error type returned by all MCP tools. Wraps errors common to
/// every tool (connection pool failures, access control denials) and delegates
/// to a tool-specific inner error for anything unique to the individual tool's
/// logic.
#[derive(Debug, thiserror::Error)]
pub enum ToolError<E: Display> {
    /// Failed to check out or configure a database connection.
    #[error("failed to acquire a database connection: {source}")]
    Connection {
        /// The underlying connection error.
        source: crate::mcp::ConnectionError,
    },
    /// The SQL statement was rejected by the access control authorizer. The
    /// query was syntactically valid but the configured permissions forbid the
    /// requested operation.
    #[error("access denied: {message}")]
    AccessDenied {
        /// A human-readable description of why the operation was denied.
        message: String,
    },
    /// An error specific to the tool's own logic, forwarded from the tool's
    /// dedicated error type.
    #[error("{0}")]
    Tool(E),
}

/// Converts the error into MCP content by rendering the display string as text.
/// This covers both the shared variants and the tool-specific inner error.
impl<E: Display> IntoContents for ToolError<E> {
    fn into_contents(self) -> Vec<Content> {
        vec![Content::text(self.to_string())]
    }
}