Skip to main content

database_mcp_sqlite/
handler.rs

1//! MCP handler for the `SQLite` backend.
2//!
3//! Implements [`ServerHandler`] directly on [`SqliteAdapter`] using
4//! rmcp macros for tool dispatch.
5
6use database_mcp_server::server_info;
7use rmcp::model::ServerInfo;
8
9use super::SqliteAdapter;
10
11/// Backend-specific description for `SQLite`.
12const DESCRIPTION: &str = "Database MCP Server for SQLite";
13
14/// Backend-specific instructions for `SQLite`.
15const INSTRUCTIONS: &str = r"## Workflow
16
171. Call `list_tables` to discover tables in the connected database.
182. Call `get_table_schema` with a `table_name` to inspect columns, types, and foreign keys before writing queries.
193. Use `read_query` for read-only SQL (SELECT, EXPLAIN).
204. Use `write_query` for data changes (INSERT, UPDATE, DELETE, CREATE, ALTER, DROP).
21
22## Constraints
23
24- The `write_query` tool is hidden when read-only mode is active.
25- Multi-statement queries are not supported. Send one statement per request.";
26
27#[rmcp::tool_handler(router = self.build_tool_router())]
28impl rmcp::ServerHandler for SqliteAdapter {
29    fn get_info(&self) -> ServerInfo {
30        let mut info = server_info();
31        info.server_info.description = Some(DESCRIPTION.into());
32        info.instructions = Some(INSTRUCTIONS.into());
33        info
34    }
35}