@@ -163,10 +163,9 @@ capabilities <- function() {
163163 )
164164}
165165
166- # Hacky way of getting tools from btw
166+ # TODO: btw now surfaces a btw_tools() function that can be passed
167+ # directly to `tool_as_json()` along with .acquaint_tools (#12)
167168get_all_btw_tools <- function () {
168- dummy_provider <- ellmer :: Provider(" dummy" , " dummy" , " dummy" )
169-
170169 .btw_tools <- getNamespace(" btw" )[[" .btw_tools" ]]
171170 tools <- lapply(unname(.btw_tools ), function (tool_obj ) {
172171 tool <- tool_obj $ tool()
@@ -175,21 +174,29 @@ get_all_btw_tools <- function() {
175174 return (NULL )
176175 }
177176
178- as_json <- getNamespace(" ellmer" )[[" as_json" ]]
179- inputSchema <- compact(as_json(dummy_provider , tool @ arguments ))
180- # This field is present but shouldn't be
181- inputSchema $ description <- NULL
182-
183- list (
184- name = tool @ name ,
185- description = tool @ description ,
186- inputSchema = inputSchema
187- )
177+ tool_as_json(tool )
188178 })
189179
180+ tools <- c(tools , lapply(.acquaint_tools , tool_as_json ))
181+
190182 compact(tools )
191183}
192184
185+ tool_as_json <- function (tool ) {
186+ dummy_provider <- ellmer :: Provider(" dummy" , " dummy" , " dummy" )
187+
188+ as_json <- getNamespace(" ellmer" )[[" as_json" ]]
189+ inputSchema <- compact(as_json(dummy_provider , tool @ arguments ))
190+ # This field is present but shouldn't be
191+ inputSchema $ description <- NULL
192+
193+ list (
194+ name = tool @ name ,
195+ description = tool @ description ,
196+ inputSchema = inputSchema
197+ )
198+ }
199+
193200compact <- function (.x ) {
194201 Filter(length , .x )
195202}
@@ -206,36 +213,3 @@ check_not_interactive <- function(call = caller_env()) {
206213 )
207214 }
208215}
209-
210- mcp_discover <- function () {
211- sock <- nanonext :: socket(" poly" )
212- on.exit(nanonext ::: reap(sock ))
213- cv <- nanonext :: cv()
214- monitor <- nanonext :: monitor(sock , cv )
215- suppressWarnings(
216- for (i in seq_len(1024L )) {
217- nanonext :: dial(
218- sock ,
219- url = sprintf(" %s%d" , acquaint_socket , i ),
220- autostart = NA
221- ) &&
222- break
223- }
224- )
225- pipes <- nanonext :: read_monitor(monitor )
226- res <- lapply(seq_along(pipes ), function (x ) nanonext :: recv_aio(sock ))
227- lapply(
228- pipes ,
229- function (x ) nanonext :: send_aio(sock , " " , mode = " raw" , pipe = x )
230- )
231- nanonext :: collect_aio_(res )
232- }
233-
234- select_host <- function (i ) {
235- lapply(the $ server_socket [[" dialer" ]], nanonext :: reap )
236- attr(the $ server_socket , " dialer" ) <- NULL
237- nanonext :: dial(
238- the $ server_socket ,
239- url = sprintf(" %s%d" , acquaint_socket , as.integer(i ))
240- )
241- }
0 commit comments