Skip to main content

DcpClient

Struct DcpClient 

Source
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

Source

pub fn new(config: DcpConfig) -> Self

Create a new DCP client with the given configuration

Source

pub fn with_defaults() -> Self

Create a new DCP client with default configuration

Source

pub fn state(&self) -> ConnectionState

Get the current connection state

Source

pub fn is_connected(&self) -> bool

Check if connected (either DCP or MCP)

Source

pub fn is_dcp_connected(&self) -> bool

Check if connected via DCP

Source

pub fn is_mcp_connected(&self) -> bool

Check if connected via MCP

Source

pub fn prefer_dcp(&self) -> bool

Check if DCP should be preferred over MCP

Source

pub fn set_prefer_dcp(&mut self, prefer: bool)

Set DCP preference

Source

pub fn enable_dcp(&mut self)

Enable DCP protocol

Source

pub fn disable_dcp(&mut self)

Disable DCP protocol (will use MCP only)

Source

pub fn is_dcp_enabled(&self) -> bool

Check if DCP is enabled

Source

pub fn current_protocol(&self) -> Option<Protocol>

Get the current protocol in use

Source

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.

Source

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.

Source

pub fn capabilities(&self) -> &CapabilityManifest

Get the capability manifest

Source

pub fn capabilities_mut(&mut self) -> &mut CapabilityManifest

Get a mutable reference to the capability manifest

Source

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.

Source

pub fn disconnect(&mut self)

Disconnect from the server

Source

pub fn register_tool( &mut self, name: &str, description: &str, schema_hash: [u8; 32], capabilities: u64, ) -> u32

Register a tool

Source

pub fn get_tool(&self, id: u32) -> Option<&ToolDefinition>

Get a registered tool by ID

Source

pub fn list_tools(&self) -> Vec<&ToolDefinition>

List all registered tools

Source

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.

Source

pub fn encode_message( &self, message_type: MessageType, payload: &[u8], ) -> Vec<u8>

Encode a DCP message with BME envelope

Source

pub fn decode_message(&self, bytes: &[u8]) -> Result<DcpMessage>

Decode a DCP message from bytes

Source

pub fn create_tool_message( &self, tool_id: u32, args: &[u8], ) -> Result<DcpMessage>

Create a tool invocation message

Source

pub fn create_resource_message(&self, resource_uri: &str) -> DcpMessage

Create a resource request message

Source

pub fn create_prompt_message(&self, prompt: &str) -> DcpMessage

Create a prompt message

Source

pub fn create_response_message(&self, response: &[u8]) -> DcpMessage

Create a response message

Source

pub fn create_error_message( &self, error_code: u32, error_msg: &str, ) -> DcpMessage

Create an error message

Source

pub fn create_stream_builder(&self, chunk_size: usize) -> StreamBuilder

Create a streaming message builder

Source

pub fn create_stream_assembler(&self) -> StreamAssembler

Create a stream assembler for receiving chunked data

Source

pub fn create_zcti_builder(&self, tool_id: u32) -> Result<ZctiBuilder>

Create a ZCTI builder for the given tool

Source

pub fn invoke_tool_zcti(&self, builder: ZctiBuilder) -> Result<Vec<u8>>

Invoke a tool using ZCTI (Zero-Copy Tool Invocation)

Source

pub fn parse_tool_invocation<'a>( &self, message: &'a DcpMessage, ) -> Result<ZctiReader<'a>>

Parse a tool invocation from a received message

Source

pub fn create_shared_buffer(&self, capacity: usize) -> SharedArgBuffer

Create a shared argument buffer

Source

pub fn mcp_adapter(&self) -> Option<&McpAdapter>

Get the MCP adapter for JSON-RPC compatibility

Source

pub fn mcp_adapter_mut(&mut self) -> Option<&mut McpAdapter>

Get a mutable reference to the MCP adapter

Source

pub fn register_tool_mcp(&mut self, name: &str, tool_id: u32)

Register a tool with the MCP adapter for JSON-RPC compatibility

Source

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.

Source

pub fn has_mcp_fallback(&self) -> bool

Check if MCP fallback is available

Source

pub fn dcp_to_mcp(&self, message: &DcpMessage) -> Result<String>

Convert a DCP message to MCP JSON-RPC format

Source

pub fn mcp_to_dcp(&self, json: &str) -> Result<DcpMessage>

Convert an MCP JSON-RPC request to DCP message

Source

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.

Source

pub fn sign_tool_def(&self, tool_id: u32) -> Result<SignedToolDef>

Create a signed tool definition

Source

pub fn verify_tool_def(&self, def: &SignedToolDef) -> Result<()>

Verify a signed tool definition

Source

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.

Source

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.

Source

pub fn verify_args_hash(&self, inv: &SignedInvocation, args: &[u8]) -> bool

Verify that the args hash in a signed invocation matches the provided arguments

Source

pub fn generate_signer() -> Signer

Generate a random signer (for testing or ephemeral keys)

Source

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.

Source

pub fn serialize_capabilities(&self) -> Vec<u8>

Serialize the current capability manifest to bytes

Source

pub fn register_resource(&mut self, resource_id: u16)

Register a resource in the capability manifest

Source

pub fn unregister_resource(&mut self, resource_id: u16)

Unregister a resource from the capability manifest

Source

pub fn has_resource(&self, resource_id: u16) -> bool

Check if a resource is registered

Source

pub fn register_prompt(&mut self, prompt_id: u16)

Register a prompt in the capability manifest

Source

pub fn unregister_prompt(&mut self, prompt_id: u16)

Unregister a prompt from the capability manifest

Source

pub fn has_prompt(&self, prompt_id: u16) -> bool

Check if a prompt is registered

Source

pub fn set_extension(&mut self, bit: u8)

Set an extension flag in the capability manifest

Source

pub fn clear_extension(&mut self, bit: u8)

Clear an extension flag from the capability manifest

Source

pub fn has_extension(&self, bit: u8) -> bool

Check if an extension is enabled

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn capability_stats(&self) -> CapabilityStats

Get statistics about the current capabilities

Source

pub fn tool_ids(&self) -> impl Iterator<Item = u16> + '_

Get an iterator over all registered tool IDs

Source

pub fn resource_ids(&self) -> impl Iterator<Item = u16> + '_

Get an iterator over all registered resource IDs

Source

pub fn prompt_ids(&self) -> impl Iterator<Item = u16> + '_

Get an iterator over all registered prompt IDs

Source

pub fn intersect_capabilities( &self, other: &CapabilityManifest, ) -> CapabilityManifest

Compute capability intersection with another manifest

Source

pub fn enable_signing(&mut self, seed: [u8; 32])

Enable signing with a seed

Source

pub fn disable_signing(&mut self)

Disable signing

Source

pub fn public_key(&self) -> Option<[u8; 32]>

Get the public key if signing is enabled

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more