use rmcp::model::{Content, IntoContents};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use super::ToolError;
use crate::{mcp::McpServerSqlite, traits::SqliteServerTool};
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Default,
Serialize,
Deserialize,
JsonSchema,
)]
pub struct VacuumTool;
impl SqliteServerTool for VacuumTool {
const NAME: &str = "vacuum";
type Context = McpServerSqlite;
type Error = ToolError<VacuumError>;
type Input = VacuumInput;
type Output = VacuumOutput;
fn handle(
ctx: &Self::Context,
_input: Self::Input,
) -> Result<Self::Output, Self::Error> {
let conn = ctx
.connection()
.map_err(|source| ToolError::Connection { source })?;
conn.execute_batch("VACUUM").map_err(|source| {
ToolError::Tool(VacuumError::Vacuum { source })
})?;
Ok(VacuumOutput { success: true })
}
}
#[derive(
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
schemars::JsonSchema,
)]
pub struct VacuumInput {}
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
schemars::JsonSchema,
)]
pub struct VacuumOutput {
pub success: bool,
}
#[derive(Debug, thiserror::Error)]
pub enum VacuumError {
#[error("failed to vacuum database: {source}")]
Vacuum {
source: rusqlite::Error,
},
}
impl IntoContents for VacuumError {
fn into_contents(self) -> Vec<Content> {
vec![Content::text(self.to_string())]
}
}