Skip to main content

brainwires_agent_network/
handler.rs

1use anyhow::Result;
2use async_trait::async_trait;
3use brainwires_mcp::{CallToolResult, InitializeParams, ServerCapabilities, ServerInfo};
4use serde_json::Value;
5
6use crate::connection::RequestContext;
7use crate::registry::McpToolDef;
8
9/// Trait for handling MCP protocol requests.
10#[async_trait]
11pub trait McpHandler: Send + Sync + 'static {
12    /// Return server identification info.
13    fn server_info(&self) -> ServerInfo;
14    /// Return server capabilities.
15    fn capabilities(&self) -> ServerCapabilities;
16    /// List all available tools.
17    fn list_tools(&self) -> Vec<McpToolDef>;
18    /// Execute a tool call.
19    async fn call_tool(
20        &self,
21        name: &str,
22        args: Value,
23        ctx: &RequestContext,
24    ) -> Result<CallToolResult>;
25
26    /// Called when the client sends an initialize request.
27    async fn on_initialize(&self, _params: &InitializeParams) -> Result<()> {
28        Ok(())
29    }
30
31    /// Called when the server is shutting down.
32    async fn on_shutdown(&self) -> Result<()> {
33        Ok(())
34    }
35}