Skip to main content

mcp_server_sqlite/tools/
mod.rs

1//! MCP tool implementations. Each submodule defines a single tool by
2//! implementing `SqliteServerTool` and providing the associated input, output,
3//! error, and value types.
4
5use std::fmt::Display;
6
7use rmcp::model::{Content, IntoContents};
8
9pub mod backup_tool;
10pub mod create_fts_index_tool;
11pub mod database_info_tool;
12pub mod describe_table_tool;
13pub mod execute_tool;
14pub mod explain_query_tool;
15pub mod list_foreign_keys_tool;
16pub mod list_indexes_tool;
17pub mod list_tables_tool;
18pub mod list_triggers_tool;
19pub mod list_views_tool;
20pub mod search_fts_tool;
21pub mod vacuum_tool;
22
23/// The top-level error type returned by all MCP tools. Wraps errors common to
24/// every tool (connection pool failures, access control denials) and delegates
25/// to a tool-specific inner error for anything unique to the individual tool's
26/// logic.
27#[derive(Debug, thiserror::Error)]
28pub enum ToolError<E: Display> {
29    /// Failed to check out or configure a database connection.
30    #[error("failed to acquire a database connection: {source}")]
31    Connection {
32        /// The underlying connection error.
33        source: crate::mcp::ConnectionError,
34    },
35    /// The SQL statement was rejected by the access control authorizer. The
36    /// query was syntactically valid but the configured permissions forbid the
37    /// requested operation.
38    #[error("access denied: {message}")]
39    AccessDenied {
40        /// A human-readable description of why the operation was denied.
41        message: String,
42    },
43    /// An error specific to the tool's own logic, forwarded from the tool's
44    /// dedicated error type.
45    #[error("{0}")]
46    Tool(E),
47}
48
49/// Converts the error into MCP content by rendering the display string as text.
50/// This covers both the shared variants and the tool-specific inner error.
51impl<E: Display> IntoContents for ToolError<E> {
52    fn into_contents(self) -> Vec<Content> {
53        vec![Content::text(self.to_string())]
54    }
55}