fix(examples): Prevent transport from closing due to premature client drop (#324)

This commit is contained in:
kah 2025-07-21 10:40:47 +09:00 • committed by GitHub
commit 8967daf87f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,8 +3,9 @@ use std::{collections::HashMap, sync::Arc};
use anyhow::Result;
use async_trait::async_trait;
use rmcp::{
RoleClient,
model::{CallToolRequestParam, CallToolResult, Tool as McpTool},
service::ServerSink,
service::{RunningService, ServerSink},
};
use serde_json::Value;
@ -70,9 +71,14 @@ impl Tool for McpToolAdapter {
#[derive(Default)]
pub struct ToolSet {
tools: HashMap<String, Arc<dyn Tool>>,
clients: HashMap<String, RunningService<RoleClient, ()>>,
}
impl ToolSet {
pub fn set_clients(&mut self, clients: HashMap<String, RunningService<RoleClient, ()>>) {
self.clients = clients;
}
pub fn add_tool<T: Tool + 'static>(&mut self, tool: T) {
self.tools.insert(tool.name(), Arc::new(tool));
}