zeph_commands/handlers/mcp.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! MCP management handler: `/mcp`.
5//!
6//! Delegates to `AgentAccess::handle_mcp`, which in turn calls the
7//! `Agent<C>` inherent methods in `zeph-core::agent::mcp`. Status messages
8//! (`send_status`) are emitted as channel side effects inside the `Agent<C>`
9//! implementation; only the final user-facing message is surfaced as the
10//! command return value.
11
12use std::future::Future;
13use std::pin::Pin;
14
15use crate::context::CommandContext;
16use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
17
18/// Manage MCP server connections.
19///
20/// Subcommands: `add`, `list`, `tools`, `remove`.
21///
22/// Delegates to `AgentAccess::handle_mcp`, which collects all output into
23/// a `String` and returns it. The registry sends the string to the channel
24/// as a `Message` output.
25pub struct McpCommand;
26
27impl CommandHandler<CommandContext<'_>> for McpCommand {
28 fn name(&self) -> &'static str {
29 "/mcp"
30 }
31
32 fn description(&self) -> &'static str {
33 "Manage MCP server connections"
34 }
35
36 fn args_hint(&self) -> &'static str {
37 "add|list|tools|remove"
38 }
39
40 fn category(&self) -> SlashCategory {
41 SlashCategory::Integration
42 }
43
44 fn handle<'a>(
45 &'a self,
46 ctx: &'a mut CommandContext<'_>,
47 args: &'a str,
48 ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
49 Box::pin(async move {
50 let output = ctx.agent.handle_mcp(args).await?;
51 Ok(CommandOutput::Message(output))
52 })
53 }
54}