pub struct DcpClient { /* private fields */ }Expand description
DCP client for AI tool communication
Provides high-performance binary protocol communication with DCP servers, with automatic fallback to MCP when DCP is unavailable.
Implementations§
Source§impl DcpClient
impl DcpClient
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new DCP client with default configuration
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Get the current connection state
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected (either DCP or MCP)
Sourcepub fn is_dcp_connected(&self) -> bool
pub fn is_dcp_connected(&self) -> bool
Check if connected via DCP
Sourcepub fn is_mcp_connected(&self) -> bool
pub fn is_mcp_connected(&self) -> bool
Check if connected via MCP
Sourcepub fn prefer_dcp(&self) -> bool
pub fn prefer_dcp(&self) -> bool
Check if DCP should be preferred over MCP
Sourcepub fn set_prefer_dcp(&mut self, prefer: bool)
pub fn set_prefer_dcp(&mut self, prefer: bool)
Set DCP preference
Sourcepub fn enable_dcp(&mut self)
pub fn enable_dcp(&mut self)
Enable DCP protocol
Sourcepub fn disable_dcp(&mut self)
pub fn disable_dcp(&mut self)
Disable DCP protocol (will use MCP only)
Sourcepub fn is_dcp_enabled(&self) -> bool
pub fn is_dcp_enabled(&self) -> bool
Check if DCP is enabled
Sourcepub fn current_protocol(&self) -> Option<Protocol>
pub fn current_protocol(&self) -> Option<Protocol>
Get the current protocol in use
Sourcepub fn select_protocol(&self) -> Option<Protocol>
pub fn select_protocol(&self) -> Option<Protocol>
Select the best protocol for a given operation
Returns DCP if connected via DCP and DCP is preferred, otherwise returns MCP if available.
Sourcepub fn invoke_tool_auto(
&self,
tool_id: u32,
args: &[u8],
) -> Result<InvocationResult>
pub fn invoke_tool_auto( &self, tool_id: u32, args: &[u8], ) -> Result<InvocationResult>
Invoke a tool using the best available protocol
Automatically selects DCP or MCP based on connection state and preferences.
Sourcepub fn capabilities(&self) -> &CapabilityManifest
pub fn capabilities(&self) -> &CapabilityManifest
Get the capability manifest
Sourcepub fn capabilities_mut(&mut self) -> &mut CapabilityManifest
pub fn capabilities_mut(&mut self) -> &mut CapabilityManifest
Get a mutable reference to the capability manifest
Sourcepub fn connect(&mut self, endpoint: &str) -> Result<()>
pub fn connect(&mut self, endpoint: &str) -> Result<()>
Connect to a DCP server
If DCP connection fails and MCP fallback is available, will fall back to MCP.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnect from the server
Sourcepub fn register_tool(
&mut self,
name: &str,
description: &str,
schema_hash: [u8; 32],
capabilities: u64,
) -> u32
pub fn register_tool( &mut self, name: &str, description: &str, schema_hash: [u8; 32], capabilities: u64, ) -> u32
Register a tool
Sourcepub fn get_tool(&self, id: u32) -> Option<&ToolDefinition>
pub fn get_tool(&self, id: u32) -> Option<&ToolDefinition>
Get a registered tool by ID
Sourcepub fn list_tools(&self) -> Vec<&ToolDefinition>
pub fn list_tools(&self) -> Vec<&ToolDefinition>
List all registered tools
Sourcepub fn invoke_tool(&self, tool_id: u32, args: &[u8]) -> Result<Vec<u8>>
pub fn invoke_tool(&self, tool_id: u32, args: &[u8]) -> Result<Vec<u8>>
Invoke a tool via DCP binary protocol
Uses Zero-Copy Tool Invocation (ZCTI) for maximum performance.
Sourcepub fn encode_message(
&self,
message_type: MessageType,
payload: &[u8],
) -> Vec<u8> ⓘ
pub fn encode_message( &self, message_type: MessageType, payload: &[u8], ) -> Vec<u8> ⓘ
Encode a DCP message with BME envelope
Sourcepub fn decode_message(&self, bytes: &[u8]) -> Result<DcpMessage>
pub fn decode_message(&self, bytes: &[u8]) -> Result<DcpMessage>
Decode a DCP message from bytes
Sourcepub fn create_tool_message(
&self,
tool_id: u32,
args: &[u8],
) -> Result<DcpMessage>
pub fn create_tool_message( &self, tool_id: u32, args: &[u8], ) -> Result<DcpMessage>
Create a tool invocation message
Sourcepub fn create_resource_message(&self, resource_uri: &str) -> DcpMessage
pub fn create_resource_message(&self, resource_uri: &str) -> DcpMessage
Create a resource request message
Sourcepub fn create_prompt_message(&self, prompt: &str) -> DcpMessage
pub fn create_prompt_message(&self, prompt: &str) -> DcpMessage
Create a prompt message
Sourcepub fn create_response_message(&self, response: &[u8]) -> DcpMessage
pub fn create_response_message(&self, response: &[u8]) -> DcpMessage
Create a response message
Sourcepub fn create_error_message(
&self,
error_code: u32,
error_msg: &str,
) -> DcpMessage
pub fn create_error_message( &self, error_code: u32, error_msg: &str, ) -> DcpMessage
Create an error message
Sourcepub fn create_stream_builder(&self, chunk_size: usize) -> StreamBuilder
pub fn create_stream_builder(&self, chunk_size: usize) -> StreamBuilder
Create a streaming message builder
Sourcepub fn create_stream_assembler(&self) -> StreamAssembler
pub fn create_stream_assembler(&self) -> StreamAssembler
Create a stream assembler for receiving chunked data
Sourcepub fn create_zcti_builder(&self, tool_id: u32) -> Result<ZctiBuilder>
pub fn create_zcti_builder(&self, tool_id: u32) -> Result<ZctiBuilder>
Create a ZCTI builder for the given tool
Sourcepub fn invoke_tool_zcti(&self, builder: ZctiBuilder) -> Result<Vec<u8>>
pub fn invoke_tool_zcti(&self, builder: ZctiBuilder) -> Result<Vec<u8>>
Invoke a tool using ZCTI (Zero-Copy Tool Invocation)
Sourcepub fn parse_tool_invocation<'a>(
&self,
message: &'a DcpMessage,
) -> Result<ZctiReader<'a>>
pub fn parse_tool_invocation<'a>( &self, message: &'a DcpMessage, ) -> Result<ZctiReader<'a>>
Parse a tool invocation from a received message
Create a shared argument buffer
Sourcepub fn mcp_adapter(&self) -> Option<&McpAdapter>
pub fn mcp_adapter(&self) -> Option<&McpAdapter>
Get the MCP adapter for JSON-RPC compatibility
Sourcepub fn mcp_adapter_mut(&mut self) -> Option<&mut McpAdapter>
pub fn mcp_adapter_mut(&mut self) -> Option<&mut McpAdapter>
Get a mutable reference to the MCP adapter
Sourcepub fn register_tool_mcp(&mut self, name: &str, tool_id: u32)
pub fn register_tool_mcp(&mut self, name: &str, tool_id: u32)
Register a tool with the MCP adapter for JSON-RPC compatibility
Sourcepub fn handle_mcp_request(&self, json: &str) -> Result<String>
pub fn handle_mcp_request(&self, json: &str) -> Result<String>
Handle an MCP JSON-RPC request and return a JSON-RPC response
This provides seamless fallback to MCP when DCP is unavailable.
Sourcepub fn has_mcp_fallback(&self) -> bool
pub fn has_mcp_fallback(&self) -> bool
Check if MCP fallback is available
Sourcepub fn dcp_to_mcp(&self, message: &DcpMessage) -> Result<String>
pub fn dcp_to_mcp(&self, message: &DcpMessage) -> Result<String>
Convert a DCP message to MCP JSON-RPC format
Sourcepub fn mcp_to_dcp(&self, json: &str) -> Result<DcpMessage>
pub fn mcp_to_dcp(&self, json: &str) -> Result<DcpMessage>
Convert an MCP JSON-RPC request to DCP message
Sourcepub fn invoke_tool_mcp(&self, request: &str) -> Result<String>
pub fn invoke_tool_mcp(&self, request: &str) -> Result<String>
Invoke a tool via MCP JSON-RPC protocol
Used as fallback when DCP is unavailable.
Sourcepub fn sign_tool_def(&self, tool_id: u32) -> Result<SignedToolDef>
pub fn sign_tool_def(&self, tool_id: u32) -> Result<SignedToolDef>
Create a signed tool definition
Sourcepub fn verify_tool_def(&self, def: &SignedToolDef) -> Result<()>
pub fn verify_tool_def(&self, def: &SignedToolDef) -> Result<()>
Verify a signed tool definition
Sourcepub fn sign_invocation(
&self,
tool_id: u32,
nonce: u64,
timestamp: u64,
args: &[u8],
) -> Result<SignedInvocation>
pub fn sign_invocation( &self, tool_id: u32, nonce: u64, timestamp: u64, args: &[u8], ) -> Result<SignedInvocation>
Sign a tool invocation
Creates a signed invocation that can be verified by the server. Requires signing to be enabled.
Sourcepub fn verify_invocation(
&self,
inv: &SignedInvocation,
public_key: &[u8; 32],
) -> Result<()>
pub fn verify_invocation( &self, inv: &SignedInvocation, public_key: &[u8; 32], ) -> Result<()>
Verify a signed invocation
Verifies that the invocation was signed by the holder of the given public key.
Sourcepub fn verify_args_hash(&self, inv: &SignedInvocation, args: &[u8]) -> bool
pub fn verify_args_hash(&self, inv: &SignedInvocation, args: &[u8]) -> bool
Verify that the args hash in a signed invocation matches the provided arguments
Sourcepub fn generate_signer() -> Signer
pub fn generate_signer() -> Signer
Generate a random signer (for testing or ephemeral keys)
Sourcepub fn parse_capability_manifest(bytes: &[u8]) -> Result<&CapabilityManifest>
pub fn parse_capability_manifest(bytes: &[u8]) -> Result<&CapabilityManifest>
Parse a capability manifest from bytes
This is used when receiving a capability manifest from a remote server during capability negotiation.
Sourcepub fn serialize_capabilities(&self) -> Vec<u8> ⓘ
pub fn serialize_capabilities(&self) -> Vec<u8> ⓘ
Serialize the current capability manifest to bytes
Sourcepub fn register_resource(&mut self, resource_id: u16)
pub fn register_resource(&mut self, resource_id: u16)
Register a resource in the capability manifest
Sourcepub fn unregister_resource(&mut self, resource_id: u16)
pub fn unregister_resource(&mut self, resource_id: u16)
Unregister a resource from the capability manifest
Sourcepub fn has_resource(&self, resource_id: u16) -> bool
pub fn has_resource(&self, resource_id: u16) -> bool
Check if a resource is registered
Sourcepub fn register_prompt(&mut self, prompt_id: u16)
pub fn register_prompt(&mut self, prompt_id: u16)
Register a prompt in the capability manifest
Sourcepub fn unregister_prompt(&mut self, prompt_id: u16)
pub fn unregister_prompt(&mut self, prompt_id: u16)
Unregister a prompt from the capability manifest
Sourcepub fn has_prompt(&self, prompt_id: u16) -> bool
pub fn has_prompt(&self, prompt_id: u16) -> bool
Check if a prompt is registered
Sourcepub fn set_extension(&mut self, bit: u8)
pub fn set_extension(&mut self, bit: u8)
Set an extension flag in the capability manifest
Sourcepub fn clear_extension(&mut self, bit: u8)
pub fn clear_extension(&mut self, bit: u8)
Clear an extension flag from the capability manifest
Sourcepub fn has_extension(&self, bit: u8) -> bool
pub fn has_extension(&self, bit: u8) -> bool
Check if an extension is enabled
Sourcepub fn enforce_tool(&self, tool_id: u32) -> Result<()>
pub fn enforce_tool(&self, tool_id: u32) -> Result<()>
Enforce that a tool is available before invocation
Returns an error if the tool is not registered in the capability manifest.
Sourcepub fn enforce_resource(&self, resource_id: u16) -> Result<()>
pub fn enforce_resource(&self, resource_id: u16) -> Result<()>
Enforce that a resource is available before access
Returns an error if the resource is not registered in the capability manifest.
Sourcepub fn enforce_prompt(&self, prompt_id: u16) -> Result<()>
pub fn enforce_prompt(&self, prompt_id: u16) -> Result<()>
Enforce that a prompt is available before use
Returns an error if the prompt is not registered in the capability manifest.
Sourcepub fn negotiate_capabilities(
&mut self,
server_manifest: &CapabilityManifest,
) -> CapabilityManifest
pub fn negotiate_capabilities( &mut self, server_manifest: &CapabilityManifest, ) -> CapabilityManifest
Negotiate capabilities with a remote server
Takes the server’s capability manifest and computes the intersection, updating the local capabilities to only include mutually supported features.
Sourcepub fn capability_stats(&self) -> CapabilityStats
pub fn capability_stats(&self) -> CapabilityStats
Get statistics about the current capabilities
Sourcepub fn tool_ids(&self) -> impl Iterator<Item = u16> + '_
pub fn tool_ids(&self) -> impl Iterator<Item = u16> + '_
Get an iterator over all registered tool IDs
Sourcepub fn resource_ids(&self) -> impl Iterator<Item = u16> + '_
pub fn resource_ids(&self) -> impl Iterator<Item = u16> + '_
Get an iterator over all registered resource IDs
Sourcepub fn prompt_ids(&self) -> impl Iterator<Item = u16> + '_
pub fn prompt_ids(&self) -> impl Iterator<Item = u16> + '_
Get an iterator over all registered prompt IDs
Sourcepub fn intersect_capabilities(
&self,
other: &CapabilityManifest,
) -> CapabilityManifest
pub fn intersect_capabilities( &self, other: &CapabilityManifest, ) -> CapabilityManifest
Compute capability intersection with another manifest
Sourcepub fn enable_signing(&mut self, seed: [u8; 32])
pub fn enable_signing(&mut self, seed: [u8; 32])
Enable signing with a seed
Sourcepub fn disable_signing(&mut self)
pub fn disable_signing(&mut self)
Disable signing
Sourcepub fn public_key(&self) -> Option<[u8; 32]>
pub fn public_key(&self) -> Option<[u8; 32]>
Get the public key if signing is enabled
Auto Trait Implementations§
impl !Freeze for DcpClient
impl RefUnwindSafe for DcpClient
impl Send for DcpClient
impl Sync for DcpClient
impl Unpin for DcpClient
impl UnsafeUnpin for DcpClient
impl UnwindSafe for DcpClient
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.