@@ -102,24 +102,20 @@ void toolcall::mcp_impl::initialize() {
102102 tools_populating_.notify_one ();
103103 };
104104
105- transport_->subscribe (" set_caps" , set_caps);
106-
107- mcp::initialize_request req (next_id_++);
108- transport_->send (req);
109-
105+ transport_->send (mcp::initialize_request (next_id_++), set_caps);
110106 tools_populating_.wait_for (lock, std::chrono::seconds (15 ), [&caps_received] { return caps_received; });
111- transport_->unsubscribe <mcp::initialize_response>(" set_caps" );
112107
113- on_list_changed update_dirty = [this ] (const mcp::tools_list_changed_notification &) {
108+ on_list_changed update_dirty = [&update_dirty, this ] (const mcp::tools_list_changed_notification &) {
114109 tool_list_dirty_ = true ;
110+ transport_->subscribe (" notifications/tools/list_changed" , update_dirty);
115111 };
116112
117113 bool has_tools = false ;
118114 for (const auto & cap : caps) {
119115 if (cap.name == " tools" ) {
120116 has_tools = true ;
121117 if (cap.listChanged ) {
122- transport_->subscribe (" update_dirty " , update_dirty);
118+ transport_->subscribe (" notifications/tools/list_changed " , update_dirty);
123119 }
124120 break ;
125121 }
@@ -167,28 +163,22 @@ std::string toolcall::mcp_impl::tool_list() {
167163 std::unique_lock<std::mutex> lock (tools_mutex_);
168164
169165 mcp::tools_list tools;
170- on_response set_tools = [this , &tools] (const mcp::tools_list_response & resp) {
166+ on_response set_tools = [this , &tools, &set_tools ] (const mcp::tools_list_response & resp) {
171167 std::unique_lock<std::mutex> lock (tools_mutex_);
172168
173169 tools.insert (tools.end (), resp.tools ().begin (), resp.tools ().end ());
174170 auto cursor = resp.next_cursor ();
175171 if (! cursor.empty ()) {
176- mcp::tools_list_request req (next_id_++, cursor);
177- transport_->send (req);
172+ transport_->send (mcp::tools_list_request (next_id_++, cursor), set_tools);
178173 return ;
179174 }
180175 tool_list_dirty_ = false ;
181176 lock.unlock ();
182177 tools_populating_.notify_one ();
183178 };
184179
185- transport_->subscribe (" set_tools" , set_tools);
186-
187- mcp::tools_list_request req (next_id_++);
188- transport_->send (req);
189-
180+ transport_->send (mcp::tools_list_request (next_id_++), set_tools);
190181 tools_populating_.wait_for (lock, std::chrono::seconds (15 ), [this ] { return ! tool_list_dirty_; });
191- transport_->unsubscribe <mcp::tools_list_response>(" set_tools" );
192182
193183 tools_ = tools_list_to_oai_json (tools);
194184 }
0 commit comments