subspace_agent_tools/chat_server.rs
1//! The running app's tools for an agent that speaks MCP itself, such as an
2//! ACP chat: one loopback endpoint per chat session, whose write approvals
3//! reach that chat. The app implements it; a chat runtime only opens it.
4use std::sync::Arc;
5
6use async_trait::async_trait;
7use subspace_core::Secret;
8
9use crate::Approval;
10
11#[async_trait]
12pub trait ChatToolServer: Send + Sync {
13 /// Starts serving on the caller's async runtime. Every write asks
14 /// `approval`; the endpoint stops when the returned value is dropped.
15 async fn open(&self, approval: Arc<dyn Approval>) -> Result<ChatToolEndpoint, String>;
16
17 /// What the endpoints serve, as their MCP `instructions` say it.
18 fn instructions(&self) -> String;
19}
20
21/// One open endpoint: Streamable HTTP at `url`, which needs
22/// `Authorization: Bearer <token>`.
23pub struct ChatToolEndpoint {
24 pub url: String,
25 pub token: Secret,
26 /// Stops the endpoint when dropped.
27 pub lease: Box<dyn Send + Sync>,
28}