use rmcp::{
handler::server::wrapper::Parameters, model::CallToolResult, tool, tool_router,
ErrorData as McpError,
};
use tokio_util::sync::CancellationToken;
use super::{
add::AddParams, doctor::DoctorParams, exec::ExecParams, import::ImportParams, init::InitParams,
ls::LsParams, rm::RmParams, run::RunParams, status::StatusParams, sync::SyncParams,
update::UpdateParams,
};
use crate::GrexMcpServer;
#[tool_router(router = tool_router, vis = "pub(crate)")]
impl GrexMcpServer {
#[tool(
name = "init",
description = "Initialise a grex workspace.",
annotations(read_only_hint = false, destructive_hint = false)
)]
async fn tool_init(&self, params: Parameters<InitParams>) -> Result<CallToolResult, McpError> {
super::init::handle(&self.state, params).await
}
#[tool(
name = "add",
description = "Register and clone a pack.",
annotations(read_only_hint = false, destructive_hint = false)
)]
async fn tool_add(&self, params: Parameters<AddParams>) -> Result<CallToolResult, McpError> {
super::add::handle(&self.state, params).await
}
#[tool(
name = "rm",
description = "Unregister a pack (runs teardown unless --skip-teardown).",
annotations(read_only_hint = false, destructive_hint = true)
)]
async fn tool_rm(&self, params: Parameters<RmParams>) -> Result<CallToolResult, McpError> {
super::rm::handle(&self.state, params).await
}
#[tool(
name = "ls",
description = "List registered packs.",
annotations(read_only_hint = true, destructive_hint = false)
)]
async fn tool_ls(&self, params: Parameters<LsParams>) -> Result<CallToolResult, McpError> {
super::ls::handle(&self.state, params).await
}
#[tool(
name = "status",
description = "Report drift + installed state.",
annotations(read_only_hint = true, destructive_hint = false)
)]
async fn tool_status(
&self,
params: Parameters<StatusParams>,
) -> Result<CallToolResult, McpError> {
super::status::handle(&self.state, params).await
}
#[tool(
name = "sync",
description = "Sync all packs recursively.",
annotations(read_only_hint = false, destructive_hint = false)
)]
async fn tool_sync(
&self,
params: Parameters<SyncParams>,
cancel: CancellationToken,
) -> Result<CallToolResult, McpError> {
super::sync::handle(&self.state, params, cancel).await
}
#[tool(
name = "update",
description = "Update one or more packs (re-resolve refs, reinstall).",
annotations(read_only_hint = false, destructive_hint = false)
)]
async fn tool_update(
&self,
params: Parameters<UpdateParams>,
) -> Result<CallToolResult, McpError> {
super::update::handle(&self.state, params).await
}
#[tool(
name = "doctor",
description = "Check manifest + gitignore + on-disk drift.",
annotations(read_only_hint = true, destructive_hint = false)
)]
async fn tool_doctor(
&self,
params: Parameters<DoctorParams>,
) -> Result<CallToolResult, McpError> {
super::doctor::handle(&self.state, params).await
}
#[tool(
name = "import",
description = "Import packs from a REPOS.json meta-repo index.",
annotations(read_only_hint = false, destructive_hint = false)
)]
async fn tool_import(
&self,
params: Parameters<ImportParams>,
) -> Result<CallToolResult, McpError> {
super::import::handle(&self.state, params).await
}
#[tool(
name = "run",
description = "Run a declared action across matching packs.",
annotations(read_only_hint = false, destructive_hint = true)
)]
async fn tool_run(&self, params: Parameters<RunParams>) -> Result<CallToolResult, McpError> {
super::run::handle(&self.state, params).await
}
#[tool(
name = "exec",
description = "Execute a command across matching packs (no shell).",
annotations(read_only_hint = false, destructive_hint = true)
)]
async fn tool_exec(&self, params: Parameters<ExecParams>) -> Result<CallToolResult, McpError> {
super::exec::handle(&self.state, params).await
}
}