mcp_core/client/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
pub mod basic;
pub mod secure;
pub mod types;

use crate::{
    error::McpError,
    prompts::{ListPromptsResponse, PromptResult},
    protocol::ProtocolHandle,
    resource::{ListResourcesResponse, ReadResourceResponse},
    tools::{ListToolsResponse, ToolResult},
};
use async_trait::async_trait;
use serde_json::Value;

use types::{ClientInfo, InitializeResult, ServerCapabilities};

#[async_trait]
pub trait Client: Send + Sync {
    async fn connect<T: crate::transport::Transport + Send + Sync + 'static>(
        &mut self,
        transport: T,
    ) -> Result<ProtocolHandle, McpError>;

    async fn initialize(&mut self, client_info: ClientInfo) -> Result<InitializeResult, McpError>;

    async fn list_resources(
        &self,
        cursor: Option<String>,
    ) -> Result<ListResourcesResponse, McpError>;

    async fn read_resource(&self, uri: String) -> Result<ReadResourceResponse, McpError>;

    async fn subscribe_to_resource(&self, uri: String) -> Result<(), McpError>;

    async fn list_prompts(&self, cursor: Option<String>) -> Result<ListPromptsResponse, McpError>;

    async fn get_prompt(
        &self,
        name: String,
        arguments: Option<Value>,
    ) -> Result<PromptResult, McpError>;

    async fn list_tools(&self, cursor: Option<String>) -> Result<ListToolsResponse, McpError>;

    async fn call_tool(&self, name: String, arguments: Value) -> Result<ToolResult, McpError>;

    async fn set_log_level(&self, level: String) -> Result<(), McpError>;

    async fn shutdown(&mut self) -> Result<(), McpError>;

    async fn get_server_capabilities(&self) -> Option<ServerCapabilities>;

    async fn has_capability(&self, capability: &str) -> bool;

    async fn get_client_info(&self) -> Option<ClientInfo>;

    async fn has_client_info(&self) -> bool;

    async fn assert_initialized(&self) -> Result<(), McpError>;

    async fn assert_capability(&self, capability: &str) -> Result<(), McpError>;

    async fn cleanup_resources(&mut self) -> Result<(), McpError>;

    async fn wait_for_shutdown(&mut self) -> Result<(), McpError>;
}