base/interface/
mcp_servers.rs1use std::sync::Arc;
10
11use async_trait::async_trait;
12
13use crate::context::McpServerInstruction;
14use crate::tool::Tool;
15
16#[async_trait]
17pub trait McpServers: Send + Sync {
18 fn tools(&self) -> Vec<Arc<dyn Tool>>;
20 async fn refresh_tools(&mut self);
22 async fn refresh_if_changed(&mut self) -> bool;
25 fn instructions(&self) -> Vec<McpServerInstruction>;
26 async fn resolve_resource_refs(&self, text: &str) -> Option<String>;
29 fn prompt_commands(&self) -> Vec<McpPromptCommand>;
30 fn has_prompt_command(&self, command: &str) -> bool;
31 async fn invoke_prompt_command(&self, command: &str, raw_args: &str) -> McpPromptInvocation;
34 fn granted(&self, servers: Option<&[String]>) -> Box<dyn McpServers>;
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct McpPromptCommand {
42 pub command: String,
43 pub description: String,
44 pub argument_hint: String,
45}
46
47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct McpPromptInvocation {
49 pub text: String,
50 pub is_error: bool,
51}
52
53pub struct NoMcpServers;
54
55#[async_trait]
56impl McpServers for NoMcpServers {
57 fn tools(&self) -> Vec<Arc<dyn Tool>> {
58 Vec::new()
59 }
60 async fn refresh_tools(&mut self) {}
61 async fn refresh_if_changed(&mut self) -> bool {
62 false
63 }
64 fn instructions(&self) -> Vec<McpServerInstruction> {
65 Vec::new()
66 }
67 async fn resolve_resource_refs(&self, _: &str) -> Option<String> {
68 None
69 }
70 fn prompt_commands(&self) -> Vec<McpPromptCommand> {
71 Vec::new()
72 }
73 fn has_prompt_command(&self, _: &str) -> bool {
74 false
75 }
76 async fn invoke_prompt_command(&self, command: &str, _: &str) -> McpPromptInvocation {
77 McpPromptInvocation {
78 text: format!("no MCP server provides `/{command}`"),
79 is_error: true,
80 }
81 }
82 fn granted(&self, _: Option<&[String]>) -> Box<dyn McpServers> {
83 Box::new(NoMcpServers)
84 }
85}