pub struct Client { /* private fields */ }Expand description
ZAP client for connecting to ZAP gateways
The client manages a Cap’n Proto RPC connection and provides high-level async methods for MCP operations (tools, resources, prompts).
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect_tcp(addr: &str) -> Result<Self>
pub async fn connect_tcp(addr: &str) -> Result<Self>
Sourcepub async fn from_tcp_stream(stream: TcpStream) -> Result<Self>
pub async fn from_tcp_stream(stream: TcpStream) -> Result<Self>
Create a client from an existing TCP stream.
This is useful for testing or when you have a pre-established connection.
Sourcepub async fn list_tools(&self) -> Result<Vec<Tool>>
pub async fn list_tools(&self) -> Result<Vec<Tool>>
Sourcepub async fn call_tool_with_id(
&self,
id: &str,
name: &str,
args: Value,
) -> Result<Value>
pub async fn call_tool_with_id( &self, id: &str, name: &str, args: Value, ) -> Result<Value>
Call a tool with a specific request ID.
This is useful for request tracking and correlation.
Sourcepub async fn list_resources(&self) -> Result<Vec<Resource>>
pub async fn list_resources(&self) -> Result<Vec<Resource>>
Sourcepub async fn read_resource(&self, uri: &str) -> Result<ResourceContent>
pub async fn read_resource(&self, uri: &str) -> Result<ResourceContent>
Sourcepub async fn subscribe(&self, uri: &str) -> Result<ResourceStream>
pub async fn subscribe(&self, uri: &str) -> Result<ResourceStream>
Sourcepub async fn list_prompts(&self) -> Result<Vec<Prompt>>
pub async fn list_prompts(&self) -> Result<Vec<Prompt>>
Sourcepub async fn get_prompt(
&self,
name: &str,
args: &[(&str, &str)],
) -> Result<Vec<PromptMessage>>
pub async fn get_prompt( &self, name: &str, args: &[(&str, &str)], ) -> Result<Vec<PromptMessage>>
Get a prompt with the given arguments.
§Arguments
name- The name of the promptargs- Key-value pairs for prompt arguments
§Example
ⓘ
let messages = client.get_prompt("code_review", &[
("language", "rust"),
("file", "main.rs"),
]).await?;
for msg in &messages {
println!("{:?}: {:?}", msg.role, msg.content);
}Sourcepub async fn log(
&self,
level: LogLevel,
message: &str,
data: Option<Value>,
) -> Result<()>
pub async fn log( &self, level: LogLevel, message: &str, data: Option<Value>, ) -> Result<()>
Send a log message to the server.
§Arguments
level- Log level (debug, info, warn, error)message- The log messagedata- Optional structured data as JSON
§Example
ⓘ
use serde_json::json;
client.log(LogLevel::Info, "Operation completed", Some(json!({
"duration_ms": 42,
"items_processed": 100
}))).await?;Sourcepub async fn disconnect(self) -> Result<()>
pub async fn disconnect(self) -> Result<()>
Disconnect from the server gracefully.
This will complete any pending requests before closing the connection.
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl !Send for Client
impl !Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more