Skip to content

Commit 0b9aeee

Browse files
authored
Require ellmer >= 0.3.0 (#73)
1 parent 4e60a96 commit 0b9aeee

File tree

6 files changed

+41
-113
lines changed

6 files changed

+41
-113
lines changed

‎DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Depends:
2626
R (>= 4.1.0)
2727
Imports:
2828
cli,
29-
ellmer (>= 0.2.0),
29+
ellmer (>= 0.3.0),
3030
jsonlite,
3131
nanonext (>= 1.6.0),
3232
processx,

‎R/aaa.R‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,2 @@
11
the <- new_environment()
22
the$server_processes <- list()
3-
4-
# ellmer 0.3.0 --------------------------------------------------------------
5-
# the ellmer 0.3.0 release will make a number of breaking changes.
6-
# we'll include a few functions to future-proof the initial release of mcptools
7-
# for that package release (#52).
8-
is_new_ellmer <- function() {
9-
packageVersion("ellmer") >= "0.2.1.9000"
10-
}
11-
12-
tool_fun <- function(tool) {
13-
if (is_new_ellmer()) {
14-
return(tool)
15-
}
16-
17-
tool@fun
18-
}

‎R/client.R‎

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ error_no_mcp_config <- function(call) {
186186
cli::cli_abort(
187187
c(
188188
"The mcptools MCP client configuration file does not exist.",
189-
i = "Supply a non-NULL file {.arg config} or create a file at the default
189+
i = "Supply a non-NULL file {.arg config} or create a file at the default
190190
configuration location {.file {default_mcp_client_config()}}."
191191
),
192192
call = call
@@ -221,41 +221,21 @@ server_as_ellmer_tools <- function(server) {
221221
for (i in seq_along(tools)) {
222222
tool <- tools[[i]]
223223
tool_arguments <- as_ellmer_types(tool)
224-
if (is_new_ellmer()) {
225-
tools_out[[i]] <-
226-
do.call(
227-
ellmer::tool,
228-
c(
229-
list(
230-
fun = tool_ref(
231-
server = server$name,
232-
tool = tool$name,
233-
arguments = names(tool_arguments)
234-
),
235-
description = tool$description,
236-
arguments = tool_arguments,
237-
name = tool$name
238-
)
239-
)
240-
)
241-
} else {
242-
tools_out[[i]] <-
243-
do.call(
244-
ellmer::tool,
245-
c(
246-
list(
247-
.fun = tool_ref(
248-
server = server$name,
249-
tool = tool$name,
250-
arguments = names(tool_arguments)
251-
),
252-
.description = tool$description,
253-
.name = tool$name
254-
),
255-
tool_arguments
256-
)
224+
tools_out[[i]] <- do.call(
225+
ellmer::tool,
226+
c(
227+
list(
228+
fun = tool_ref(
229+
server = server$name,
230+
tool = tool$name,
231+
arguments = names(tool_arguments)
232+
),
233+
description = tool$description,
234+
arguments = tool_arguments,
235+
name = tool$name
257236
)
258-
}
237+
)
238+
)
259239
}
260240

261241
tools_out

‎R/server.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ append_tool_fn <- function(data) {
343343
))
344344
}
345345

346-
data$tool <- tool_fun(get_mcptools_tools()[[tool_name]])
346+
data$tool <- get_mcptools_tools()[[tool_name]]
347347
data
348348
}
349349

‎R/tools.R‎

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,10 @@ list_r_sessions_description <- paste(
125125
"and call select_r_session unless the user asks you to specifically."
126126
)
127127

128-
list_r_sessions_tool <-
129-
if (is_new_ellmer()) {
130-
ellmer::tool(
131-
fun = list_r_sessions,
132-
description = list_r_sessions_description
133-
)
134-
} else {
135-
ellmer::tool(
136-
.fun = list_r_sessions,
137-
.description = list_r_sessions_description
138-
)
139-
}
128+
list_r_sessions_tool <- ellmer::tool(
129+
fun = list_r_sessions,
130+
description = list_r_sessions_description
131+
)
140132

141133
select_r_session <- function(session) {
142134
nanonext::reap(the$server_socket[["dialer"]][[1L]])
@@ -161,22 +153,13 @@ select_r_session_description <- paste(
161153
"call this tool more than once if you need to switch between sessions."
162154
)
163155

164-
select_r_session_tool <-
165-
if (is_new_ellmer()) {
166-
ellmer::tool(
167-
fun = select_r_session,
168-
description = select_r_session_description,
169-
arguments = list(
170-
session = ellmer::type_integer("The R session number to select.")
171-
)
172-
)
173-
} else {
174-
ellmer::tool(
175-
.fun = select_r_session,
176-
.description = select_r_session_description,
177-
session = ellmer::type_integer("The R session number to select.")
178-
)
179-
}
156+
select_r_session_tool <- ellmer::tool(
157+
fun = select_r_session,
158+
description = select_r_session_description,
159+
arguments = list(
160+
session = ellmer::type_integer("The R session number to select.")
161+
)
162+
)
180163

181164
get_mcptools_tools <- function() {
182165
# must be called inside of the server session

‎inst/example-ellmer-tools.R‎

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
if (is_new_ellmer()) {
2-
res <-
3-
list(
4-
tool_rnorm = ellmer::tool(
5-
fun = rnorm,
6-
description = "Draw numbers from a random normal distribution",
7-
arguments = list(
8-
n = ellmer::type_integer(
9-
"The number of observations. Must be a positive integer."
10-
),
11-
mean = ellmer::type_number("The mean value of the distribution."),
12-
sd = ellmer::type_number(
13-
"The standard deviation of the distribution. Must be a non-negative number."
14-
)
15-
)
1+
res <- list(
2+
tool_rnorm = ellmer::tool(
3+
fun = rnorm,
4+
description = "Draw numbers from a random normal distribution",
5+
arguments = list(
6+
n = ellmer::type_integer(
7+
"The number of observations. Must be a positive integer."
8+
),
9+
mean = ellmer::type_number("The mean value of the distribution."),
10+
sd = ellmer::type_number(
11+
"The standard deviation of the distribution. Must be a non-negative number."
1612
)
1713
)
18-
} else {
19-
res <-
20-
list(
21-
tool_rnorm = ellmer::tool(
22-
rnorm,
23-
"Draw numbers from a random normal distribution",
24-
n = ellmer::type_integer(
25-
"The number of observations. Must be a positive integer."
26-
),
27-
mean = ellmer::type_number("The mean value of the distribution."),
28-
sd = ellmer::type_number(
29-
"The standard deviation of the distribution. Must be a non-negative number."
30-
),
31-
)
32-
)
33-
}
34-
14+
)
15+
)
3516

3617
res

0 commit comments

Comments
 (0)