1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # sacp-proxy
//!
//! Framework for building ACP proxy components that extend agent functionality.
//!
//! ## What are proxies?
//!
//! Proxies are modular components that sit between an editor and an agent, intercepting and transforming messages.
//! They enable **composable agent architectures** where functionality can be added without modifying the base agent.
//!
//! ```text
//! Editor → Proxy 1 → Proxy 2 → Agent
//! ```
//!
//! Use cases:
//! - Add MCP tools/resources/prompts to any agent
//! - Inject context or modify prompts before they reach the agent
//! - Filter or transform agent responses
//! - Add logging, metrics, or policy enforcement
//!
//! ## Quick Start
//!
//! The simplest proxy just forwards messages unchanged:
//!
//! ```rust,no_run
//! use sacp::JrHandlerChain;
//! use sacp_proxy::{AcpProxyExt, McpServiceRegistry};
//! use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! JrHandlerChain::new()
//! .name("my-proxy")
//! .provide_mcp(McpServiceRegistry::default()) // Provide MCP services
//! .proxy() // Enable proxy mode
//! .serve(sacp::ByteStreams::new(
//! tokio::io::stdout().compat_write(),
//! tokio::io::stdin().compat()
//! ))
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! To add MCP tools to the proxy, provide an MCP server:
//!
//! ```rust,no_run
//! use sacp::JrHandlerChain;
//! use sacp_proxy::{AcpProxyExt, McpServiceRegistry};
//! use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! JrHandlerChain::new()
//! .name("my-proxy")
//! // Add MCP servers to provide tools/resources/prompts
//! .provide_mcp(
//! McpServiceRegistry::default()
//! // .with_rmcp_server("my-server", || MyMcpServer::new())?
//! )
//! .proxy()
//! .serve(sacp::ByteStreams::new(
//! tokio::io::stdout().compat_write(),
//! tokio::io::stdin().compat()
//! ))
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! See the `with_mcp_server.rs` example for a complete implementation.
//!
//! ## Key Concepts
//!
//! **Predecessor vs Successor:**
//! - **Predecessor** - The component closer to the editor (could be editor or another proxy)
//! - **Successor** - The component farther from the editor (could be agent or another proxy)
//!
//! Messages flow: `Predecessor → This Proxy → Successor`
//!
//! **Extension Traits:**
//! - [`AcpProxyExt`] - Adds proxy-specific methods to [`JrConnection`](sacp::JrConnection)
//! - [`JrCxExt`] - Adds forwarding methods (`send_to_predecessor`, `send_to_successor`)
//!
//! ## Examples
//!
//! See the [examples directory](https://github.com/symposium-org/symposium-acp/tree/main/src/sacp-proxy/examples):
//!
//! - **[`minimal.rs`](https://github.com/symposium-org/symposium-acp/blob/main/src/sacp-proxy/examples/minimal.rs)** - Simplest possible proxy that forwards everything unchanged
//! - **[`with_mcp_server.rs`](https://github.com/symposium-org/symposium-acp/blob/main/src/sacp-proxy/examples/with_mcp_server.rs)** - Proxy that adds MCP tools to any agent
//!
//! ## How Proxies Work
//!
//! When you call `.proxy()`, the framework:
//! 1. Handles capability negotiation with predecessor and successor
//! 2. Sets up message routing between components
//! 3. Wraps your handlers to intercept specific message types
//! 4. Forwards everything else automatically
//!
//! You only need to handle the messages you want to intercept or transform.
//!
//! ## Related Crates
//!
//! - **[sacp](https://crates.io/crates/sacp)** - Core ACP SDK
//! - **[sacp-conductor](https://crates.io/crates/sacp-conductor)** - Binary for orchestrating proxy chains
//! - **[sacp-tokio](https://crates.io/crates/sacp-tokio)** - Tokio utilities for spawning agents
/// Re-export component types from sacp
pub use Component;
/// Proxying MCP messages over ACP.
pub use *;
/// Proxying and sending messages to/from the successor component
pub use *;
pub use *;
pub use *;