pub struct Connection { /* private fields */ }Expand description
A configured server, connected on demand.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(
entry: ServerEntry,
cwd: PathBuf,
agent_dir: PathBuf,
on_tools: ToolsListener,
readable_resources: Arc<dyn Fn(&str) -> bool + Send + Sync>,
provider_token: Option<ProviderToken>,
) -> Arc<Connection> ⓘ
pub fn new( entry: ServerEntry, cwd: PathBuf, agent_dir: PathBuf, on_tools: ToolsListener, readable_resources: Arc<dyn Fn(&str) -> bool + Send + Sync>, provider_token: Option<ProviderToken>, ) -> Arc<Connection> ⓘ
A connection for entry, not yet connected, with OAuth credentials
kept in agent_dir. Its callbacks:
on_tools: learns of tool and resource changesreadable_resources: tells whether the resource tools reach a serverprovider_token: reads the token of servers withauth.provider
Sourcepub async fn sign_in(&self, prompt: &SignInPrompt) -> Result<(), AuthError>
pub async fn sign_in(&self, prompt: &SignInPrompt) -> Result<(), AuthError>
Signs in to an OAuth server. The caller reconnects afterwards.
Sourcepub async fn remove_credentials(&self) -> Result<bool, McpError>
pub async fn remove_credentials(&self) -> Result<bool, McpError>
Removes the server’s stored OAuth credentials. Returns whether any were stored.
Sourcepub async fn signed_in_elsewhere(&self) -> bool
pub async fn signed_in_elsewhere(&self) -> bool
Whether the server needs a sign-in and its stored credentials changed since it came to, as when another process signed in.
Sourcepub fn entry(&self) -> &ServerEntry
pub fn entry(&self) -> &ServerEntry
The configured entry.
Sourcepub fn readable_resources(&self) -> bool
pub fn readable_resources(&self) -> bool
Whether read_mcp_resource reaches this server.
Sourcepub async fn client(self: &Arc<Self>) -> Result<McpClient, McpError>
pub async fn client(self: &Arc<Self>) -> Result<McpClient, McpError>
The connected client, connecting when needed.
Sourcepub async fn call_tool(
self: &Arc<Self>,
name: &str,
args: Value,
options: RequestOptions,
) -> Result<Value, McpError>
pub async fn call_tool( self: &Arc<Self>, name: &str, args: Value, options: RequestOptions, ) -> Result<Value, McpError>
Calls one of the server’s tools. Not retried, since it may have run.
Sourcepub async fn read_resource(
self: &Arc<Self>,
uri: &str,
options: RequestOptions,
) -> Result<Value, McpError>
pub async fn read_resource( self: &Arc<Self>, uri: &str, options: RequestOptions, ) -> Result<Value, McpError>
Reads a resource.
Sourcepub async fn resources_page(
self: &Arc<Self>,
kind: ResourceKind,
cursor: Option<String>,
options: RequestOptions,
) -> Result<(Vec<Value>, Option<String>), McpError>
pub async fn resources_page( self: &Arc<Self>, kind: ResourceKind, cursor: Option<String>, options: RequestOptions, ) -> Result<(Vec<Value>, Option<String>), McpError>
One page of resources or resource templates, with no templates for servers without the method.
Sourcepub async fn all_resources(
self: &Arc<Self>,
kind: ResourceKind,
options: RequestOptions,
) -> Result<Vec<Value>, McpError>
pub async fn all_resources( self: &Arc<Self>, kind: ResourceKind, options: RequestOptions, ) -> Result<Vec<Value>, McpError>
Every resource or resource template, with no templates for servers without the method.