Skip to content

Commit 3d7202e

Browse files
committed
refactor(sacp)!: remove to_future_hack from tool_fn API
- Introduce JrResponder trait at jsonrpc level for background tasks - Add Responder type parameter to JrConnectionBuilder and JrConnection - Replace with_spawned usage in with_mcp_server with with_responder - Refactor with_client to use run_until + try_join! instead of select! - with_client now returns generic T instead of just () - tool_fn now uses FnMut + Future bounds instead of AsyncFn BREAKING CHANGE: tool_fn no longer requires the to_future_hack parameter
1 parent 4882eec commit 3d7202e

14 files changed

Lines changed: 311 additions & 190 deletions

File tree

src/sacp-conductor/tests/mcp_integration/proxy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ impl Component for ProxyComponent {
3434
result: format!("Echo: {}", params.message),
3535
})
3636
},
37-
sacp::tool_fn!(),
3837
)
3938
.build();
4039

src/sacp-conductor/tests/mcp_server_handler_chain.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl Component for ProxyWithMcpAndHandler {
8282
result: format!("Echo: {}", params.message),
8383
})
8484
},
85-
sacp::tool_fn!(),
8685
)
8786
.build();
8887

src/sacp-conductor/tests/scoped_mcp_server.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ async fn test_scoped_mcp_server_through_session() -> Result<(), sacp::Error> {
8383

8484
struct ScopedProxy;
8585

86-
fn make_mcp_server<Role: JrRole>(values: &Mutex<Vec<String>>) -> McpServer<'_, Role>
86+
fn make_mcp_server<Role: JrRole>(
87+
values: &Mutex<Vec<String>>,
88+
) -> McpServer<Role, impl sacp::JrResponder + use<'_, Role>>
8789
where
8890
Role: HasEndpoint<Agent>,
8991
{
@@ -102,17 +104,11 @@ where
102104
values.extend(input.elements);
103105
Ok(values.len())
104106
},
105-
sacp::tool_fn!(),
106-
)
107-
.tool_fn(
108-
"get",
109-
"Get the collected values",
110-
async |(): (), _cx| {
111-
let values = values.lock().expect("not poisoned");
112-
Ok(values.clone())
113-
},
114-
sacp::tool_fn!(),
115107
)
108+
.tool_fn("get", "Get the collected values", async |(): (), _cx| {
109+
let values = values.lock().expect("not poisoned");
110+
Ok(values.clone())
111+
})
116112
.build()
117113
}
118114

src/sacp-conductor/tests/test_session_id_in_mcp_tools.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ fn create_echo_proxy() -> Result<sacp::DynComponent, sacp::Error> {
4040
acp_url: context.acp_url(),
4141
})
4242
},
43-
sacp::tool_fn!(),
4443
)
4544
.build();
4645

4746
// Create proxy component
4847
Ok(sacp::DynComponent::new(ProxyWithEchoServer { mcp_server }))
4948
}
5049

51-
struct ProxyWithEchoServer {
52-
mcp_server: McpServer<'static, ProxyToConductor>,
50+
struct ProxyWithEchoServer<R: sacp::JrResponder> {
51+
mcp_server: McpServer<ProxyToConductor, R>,
5352
}
5453

55-
impl Component for ProxyWithEchoServer {
54+
impl<R: sacp::JrResponder + 'static> Component for ProxyWithEchoServer<R> {
5655
async fn serve(self, client: impl Component) -> Result<(), sacp::Error> {
5756
ProxyToConductor::builder()
5857
.name("echo-proxy")

src/sacp-rmcp/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use rmcp::ServiceExt;
2424
use sacp::mcp_server::{McpContext, McpServer, McpServerConnect};
25-
use sacp::{Agent, ByteStreams, Component, DynComponent, HasEndpoint, JrRole};
25+
use sacp::{Agent, ByteStreams, Component, DynComponent, HasEndpoint, JrRole, NullResponder};
2626
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
2727

2828
pub trait McpServerExt<Role: JrRole>
@@ -37,7 +37,7 @@ where
3737
fn from_rmcp<S>(
3838
name: impl ToString,
3939
new_fn: impl Fn() -> S + Send + Sync + 'static,
40-
) -> McpServer<'static, Role>
40+
) -> McpServer<Role, NullResponder>
4141
where
4242
S: rmcp::Service<rmcp::RoleServer>,
4343
{
@@ -67,12 +67,12 @@ where
6767
name: name.to_string(),
6868
new_fn,
6969
},
70-
Box::pin(futures::future::ready(Ok(()))),
70+
NullResponder,
7171
)
7272
}
7373
}
7474

75-
impl<Role: JrRole> McpServerExt<Role> for McpServer<'_, Role> where Role: HasEndpoint<Agent> {}
75+
impl<Role: JrRole> McpServerExt<Role> for McpServer<Role> where Role: HasEndpoint<Agent> {}
7676

7777
/// Component wrapper for rmcp services.
7878
struct RmcpServerComponent<S> {

0 commit comments

Comments
 (0)