Skip to main content

agent_client_protocol_schema/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! [![Agent Client Protocol](https://zed.dev/img/acp/banner-dark.webp)](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(crate) use serde_util::SkipListener;
56pub use serde_util::{IntoMaybeUndefined, IntoOption, MaybeUndefined};
57pub use version::*;
58
59#[cfg(test)]
60mod serde_json_feature_tests {
61    #[cfg(feature = "schemars")]
62    use schemars::JsonSchema;
63    use serde_json::Value;
64
65    #[cfg(feature = "schemars")]
66    #[test]
67    fn protocol_types_implement_json_schema_when_enabled() {
68        fn assert_json_schema<T: JsonSchema>() {}
69
70        assert_json_schema::<crate::ProtocolVersion>();
71        assert_json_schema::<crate::v1::InitializeRequest>();
72    }
73
74    #[test]
75    fn serde_json_values_preserve_object_key_order() {
76        let Value::Object(object) =
77            serde_json::from_str::<Value>(r#"{"z":1,"a":2,"m":3}"#).unwrap()
78        else {
79            panic!("expected JSON object");
80        };
81
82        let keys = object.keys().map(String::as_str).collect::<Vec<_>>();
83        assert_eq!(keys, ["z", "a", "m"]);
84    }
85}