Skip to content

Latest commit

 

History

History

agent-client-protocol-derive

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

agent-client-protocol-derive

Procedural derives for custom JSON-RPC messages in the Agent Client Protocol Rust SDK.

The core agent-client-protocol crate re-exports these macros, so applications normally do not need a direct dependency on this crate.

[dependencies]
agent-client-protocol = "3"
serde = { version = "1", features = ["derive"] }
use agent_client_protocol::{JsonRpcMessage, JsonRpcRequest, JsonRpcResponse};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, JsonRpcRequest)]
#[request(method = "_com.example/hello", response = HelloResponse)]
struct HelloRequest {
    name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonRpcResponse)]
struct HelloResponse {
    greeting: String,
}

fn main() {
    let request = HelloRequest { name: "Ada".into() };
    assert_eq!(request.method(), "_com.example/hello");
}

JsonRpcNotification provides the corresponding notification derive through #[notification(method = "...")]. The derives use Serde for message bodies and do not require the core's schemars feature.

Custom crate paths are supported by the crate attribute on request, notification, and response. See the macro reference for attributes and generic-type support.

License

Apache-2.0. The published package includes LICENSE.