agent_client_protocol_schema/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! [](https://agentclientprotocol.com/)
4//!
5//! # Agent Client Protocol Schema
6//!
7//! Strongly-typed Rust definitions of the Agent Client Protocol (ACP) wire
8//! format. ACP is a JSON-RPC based protocol that standardizes communication
9//! between code editors (IDEs, text-editors, etc.) and coding agents
10//! (programs that use generative AI to autonomously modify code).
11//!
12//! This crate is **only** the schema: the request, response, and
13//! notification types, plus serde plumbing and optional JSON Schema generation.
14//! For the runtime pieces (transport, connection setup, the `Agent` / `Client`
15//! traits, etc.) use the higher-level [`agent-client-protocol`] crate, which
16//! builds on top of these types.
17//!
18//! [`agent-client-protocol`]: https://crates.io/crates/agent-client-protocol
19//!
20//! ## What's in this crate
21//!
22//! - Versioned wire-format types for every ACP method: request, response, and
23//! notification structs grouped by which side handles them, currently under
24//! the [`v1`] module.
25//! - JSON-RPC envelope and routing types: [`v1::JsonRpcMessage`],
26//! [`rpc::JsonRpcBatch`], [`v1::Request`], [`v1::Response`],
27//! [`v1::Notification`], [`v1::RequestId`], [`v1::Error`].
28//! - Aggregated routing enums: [`v1::AgentRequest`], [`v1::AgentResponse`],
29//! [`v1::AgentNotification`], and the matching client-side trio used by SDK
30//! crates to dispatch incoming JSON-RPC messages.
31//!
32//! ## Cargo features
33//!
34//! The `schemars` feature implements `schemars::JsonSchema` for the protocol
35//! types. It is enabled by default to preserve the existing default API.
36//! Consumers that only need serialization can disable default features to omit
37//! the dependency and those trait implementations.
38//!
39//! ## Versioning
40//!
41//! Stable protocol types are exposed through explicit version modules. For
42//! example, use `agent_client_protocol_schema::v1::SessionId` for ACP protocol
43//! version 1 types.
44//!
45//! For the complete protocol specification and documentation, visit
46//! <https://agentclientprotocol.com>.
47
48pub mod rpc;
49mod serde_util;
50pub mod v1;
51#[cfg(feature = "unstable_protocol_v2")]
52pub mod v2;
53mod version;
54
55pub use serde_util::{IntoMaybeUndefined, IntoOption, MaybeUndefined};
56pub use version::*;
57
58#[cfg(test)]
59mod serde_json_feature_tests {
60 #[cfg(feature = "schemars")]
61 use schemars::JsonSchema;
62 use serde_json::Value;
63
64 #[cfg(feature = "schemars")]
65 #[test]
66 fn protocol_types_implement_json_schema_when_enabled() {
67 fn assert_json_schema<T: JsonSchema>() {}
68
69 assert_json_schema::<crate::ProtocolVersion>();
70 assert_json_schema::<crate::v1::InitializeRequest>();
71 }
72
73 #[test]
74 fn serde_json_values_preserve_object_key_order() {
75 let Value::Object(object) =
76 serde_json::from_str::<Value>(r#"{"z":1,"a":2,"m":3}"#).unwrap()
77 else {
78 panic!("expected JSON object");
79 };
80
81 let keys = object.keys().map(String::as_str).collect::<Vec<_>>();
82 assert_eq!(keys, ["z", "a", "m"]);
83 }
84}