Skip to content

Commit a4e7da3

Browse files
committed
refactor(sacp-conductor): use explicit endpoints for ConductorToClient
Since the conductor can act as a proxy, it's important to be explicit about which endpoint (Client or Agent) is being used rather than relying on HasDefaultEndpoint. This makes the message flow direction clear in the code. - Change if_request/if_notification to if_request_from/if_notification_from with Client - Change send_notification to send_notification_to with Client
1 parent 04ed33a commit a4e7da3

2 files changed

Lines changed: 42 additions & 37 deletions

File tree

src/sacp-conductor/src/conductor.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl ConductorResponder {
751751
request: Req,
752752
) -> JrResponse<Req::Response> {
753753
if source_component_index == 0 {
754-
client.send_request(request)
754+
client.send_request_to(Client, request)
755755
} else {
756756
self.proxies[source_component_index - 1].send_request(SuccessorMessage {
757757
message: request,
@@ -783,7 +783,7 @@ impl ConductorResponder {
783783
);
784784
if source_component_index == 0 {
785785
tracing::debug!("Sending notification directly to client");
786-
client.send_notification(notification)
786+
client.send_notification_to(Client, notification)
787787
} else {
788788
tracing::debug!(
789789
target_proxy = source_component_index - 1,
@@ -835,21 +835,24 @@ impl ConductorResponder {
835835
tracing::debug!(?message, "forward_client_to_agent_message");
836836

837837
MatchMessageFrom::new(message, connection_cx)
838-
.if_request(async |request: InitializeProxyRequest, request_cx| {
839-
// Proxy forwarding InitializeProxyRequest to its successor
840-
tracing::debug!("forward_client_to_agent_message: InitializeProxyRequest");
841-
// Wrap the request_cx to convert InitializeResponse back to InitializeProxyResponse
842-
self.forward_initialize_request(
843-
target_component_index,
844-
conductor_tx,
845-
connection_cx,
846-
request.initialize,
847-
request_cx,
848-
)
849-
.await
850-
})
838+
.if_request_from(
839+
Client,
840+
async |request: InitializeProxyRequest, request_cx| {
841+
// Proxy forwarding InitializeProxyRequest to its successor
842+
tracing::debug!("forward_client_to_agent_message: InitializeProxyRequest");
843+
// Wrap the request_cx to convert InitializeResponse back to InitializeProxyResponse
844+
self.forward_initialize_request(
845+
target_component_index,
846+
conductor_tx,
847+
connection_cx,
848+
request.initialize,
849+
request_cx,
850+
)
851+
.await
852+
},
853+
)
851854
.await
852-
.if_request(async |request: InitializeRequest, request_cx| {
855+
.if_request_from(Client, async |request: InitializeRequest, request_cx| {
853856
// Direct InitializeRequest (shouldn't happen after initialization, but handle it)
854857
tracing::debug!("forward_client_to_agent_message: InitializeRequest");
855858
self.forward_initialize_request(
@@ -862,7 +865,7 @@ impl ConductorResponder {
862865
.await
863866
})
864867
.await
865-
.if_request(async |request: NewSessionRequest, request_cx| {
868+
.if_request_from(Client, async |request: NewSessionRequest, request_cx| {
866869
// When forwarding "session/new", we adjust MCP servers to manage "acp:" URLs.
867870
self.forward_session_new_request(
868871
target_component_index,
@@ -874,7 +877,8 @@ impl ConductorResponder {
874877
.await
875878
})
876879
.await
877-
.if_request(
880+
.if_request_from(
881+
Client,
878882
async |request: McpOverAcpMessage<UntypedMessage>, request_cx| {
879883
let McpOverAcpMessage {
880884
connection_id,
@@ -894,23 +898,26 @@ impl ConductorResponder {
894898
},
895899
)
896900
.await
897-
.if_notification(async |notification: McpOverAcpMessage<UntypedMessage>| {
898-
let McpOverAcpMessage {
899-
connection_id,
900-
message: mcp_notification,
901-
..
902-
} = notification;
903-
self.bridge_connections
904-
.get_mut(&connection_id)
905-
.ok_or_else(|| {
906-
sacp::util::internal_error(format!(
907-
"unknown connection id: {}",
908-
connection_id
909-
))
910-
})?
911-
.send(MessageCx::Notification(mcp_notification))
912-
.await
913-
})
901+
.if_notification_from(
902+
Client,
903+
async |notification: McpOverAcpMessage<UntypedMessage>| {
904+
let McpOverAcpMessage {
905+
connection_id,
906+
message: mcp_notification,
907+
..
908+
} = notification;
909+
self.bridge_connections
910+
.get_mut(&connection_id)
911+
.ok_or_else(|| {
912+
sacp::util::internal_error(format!(
913+
"unknown connection id: {}",
914+
connection_id
915+
))
916+
})?
917+
.send(MessageCx::Notification(mcp_notification))
918+
.await
919+
},
920+
)
914921
.await
915922
.otherwise(async |message| {
916923
// Otherwise, just send the message along "as is".

src/sacp/src/role.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ impl JrRole for ConductorToClient {
290290
type State = ();
291291
}
292292

293-
impl HasDefaultEndpoint for ConductorToClient {}
294-
295293
impl HasEndpoint<Client> for ConductorToClient {
296294
fn remote_style(_end: Client) -> RemoteRoleStyle {
297295
RemoteRoleStyle::Counterpart

0 commit comments

Comments
 (0)