tools: delete old dispatch functions

All dispatch now goes through the Tool registry. Removed:
- memory::dispatch() (20-line match)
- channels::dispatch() and dispatch_blocking()
- channel_list_blocking(), channel_notifications_blocking()

Channel tool functions made pub so registry calls them directly.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 15:13:27 -04:00 committed by Kent Overstreet
parent 03cf13e9eb
commit 112abb2000
3 changed files with 8 additions and 71 deletions

View file

@ -53,49 +53,13 @@ pub fn definitions() -> Vec<ToolDef> {
// ── Dispatch ───────────────────────────────────────────────────
pub async fn dispatch(name: &str, args: &serde_json::Value) -> Result<String> {
match name {
"channel_list" => channel_list().await,
"channel_recv" => channel_recv(args).await,
"channel_send" => channel_send(args).await,
"channel_notifications" => channel_notifications().await,
_ => anyhow::bail!("unknown channel tool: {}", name),
}
}
/// Blocking dispatch for synchronous contexts (MCP server).
pub fn dispatch_blocking(name: &str, args: &serde_json::Value) -> Result<String> {
match name {
"channel_list" => Ok(channel_list_blocking()),
"channel_notifications" => Ok(channel_notifications_blocking()),
"channel_recv" | "channel_send" => {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
let local = tokio::task::LocalSet::new();
local.block_on(&rt, async {
match name {
"channel_recv" => channel_recv(args).await,
"channel_send" => channel_send(args).await,
_ => unreachable!(),
}
})
}
_ => anyhow::bail!("unknown channel tool: {}", name),
}
}
// ── Tool implementations ───────────────────────────────────────
async fn channel_list() -> Result<String> {
pub async fn channel_list() -> Result<String> {
let result = fetch_all_channels().await;
Ok(format_channel_list(&result))
}
fn channel_list_blocking() -> String {
let result = fetch_all_channels_blocking();
format_channel_list(&result)
}
fn format_channel_list(channels: &[(String, bool, u32)]) -> String {
if channels.is_empty() {
@ -119,7 +83,7 @@ struct RecvArgs {
fn default_true() -> bool { true }
fn default_min_count() -> u32 { 20 }
async fn channel_recv(args: &serde_json::Value) -> Result<String> {
pub async fn channel_recv(args: &serde_json::Value) -> Result<String> {
let a: RecvArgs = serde_json::from_value(args.clone())
.context("invalid channel_recv arguments")?;
let sock = daemon_sock(&a.channel)?;
@ -140,7 +104,7 @@ struct SendArgs {
message: String,
}
async fn channel_send(args: &serde_json::Value) -> Result<String> {
pub async fn channel_send(args: &serde_json::Value) -> Result<String> {
let a: SendArgs = serde_json::from_value(args.clone())
.context("invalid channel_send arguments")?;
let sock = daemon_sock(&a.channel)?;
@ -154,15 +118,11 @@ async fn channel_send(args: &serde_json::Value) -> Result<String> {
.map_err(|e| anyhow::anyhow!("{}", e))
}
async fn channel_notifications() -> Result<String> {
pub async fn channel_notifications() -> Result<String> {
let result = fetch_all_channels().await;
Ok(format_notifications(&result))
}
fn channel_notifications_blocking() -> String {
let result = fetch_all_channels_blocking();
format_notifications(&result)
}
fn format_notifications(channels: &[(String, bool, u32)]) -> String {
let unread: Vec<_> = channels.iter().filter(|(_, _, u)| *u > 0).collect();