use std::sync::Arc;
use async_trait::async_trait;
use crate::context::McpServerInstruction;
use crate::tool::Tool;
#[async_trait]
pub trait McpServers: Send + Sync {
fn tools(&self) -> Vec<Arc<dyn Tool>>;
async fn refresh_tools(&mut self);
async fn refresh_if_changed(&mut self) -> bool;
fn instructions(&self) -> Vec<McpServerInstruction>;
async fn resolve_resource_refs(&self, text: &str) -> Option<String>;
fn prompt_commands(&self) -> Vec<McpPromptCommand>;
fn has_prompt_command(&self, command: &str) -> bool;
async fn invoke_prompt_command(&self, command: &str, raw_args: &str) -> McpPromptInvocation;
fn granted(&self, servers: Option<&[String]>) -> Box<dyn McpServers>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct McpPromptCommand {
pub command: String,
pub description: String,
pub argument_hint: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct McpPromptInvocation {
pub text: String,
pub is_error: bool,
}
pub struct NoMcpServers;
#[async_trait]
impl McpServers for NoMcpServers {
fn tools(&self) -> Vec<Arc<dyn Tool>> {
Vec::new()
}
async fn refresh_tools(&mut self) {}
async fn refresh_if_changed(&mut self) -> bool {
false
}
fn instructions(&self) -> Vec<McpServerInstruction> {
Vec::new()
}
async fn resolve_resource_refs(&self, _: &str) -> Option<String> {
None
}
fn prompt_commands(&self) -> Vec<McpPromptCommand> {
Vec::new()
}
fn has_prompt_command(&self, _: &str) -> bool {
false
}
async fn invoke_prompt_command(&self, command: &str, _: &str) -> McpPromptInvocation {
McpPromptInvocation {
text: format!("no MCP server provides `/{command}`"),
is_error: true,
}
}
fn granted(&self, _: Option<&[String]>) -> Box<dyn McpServers> {
Box::new(NoMcpServers)
}
}