Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# mcptools (development version)

* `mcp_server()` now formats tool results in the same way as ellmer (#78 by @gadenbuie).
* `mcp_tools()` now sends and receives a `"notifications/initialized"` (#77 by @galachad).
* `mcp_session()` now returns invisibly the nanonext socket used for communicating with the server.
* `mcp_server()` gains logical argument `session_tools`, allowing users to opt-out of presenting R sessions tools to clients.
Expand Down
8 changes: 5 additions & 3 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ handle_message_from_server <- function(data) {

as_tool_call_result <- function(data, result) {
is_error <- FALSE
format_result <- function(x) paste(x, collapse = "\n")

if (inherits(result, "ellmer::ContentToolResult")) {
is_error <- !is.null(result@error)
result <- result@value %||% result@error
format_result <- asNamespace("ellmer")[["tool_string"]] %||% format_result
}

jsonrpc_response(
data$id,
list(
content = list(
list(
type = "text",
text = paste(result, collapse = "\n")
text = format_result(result)
)
),
isError = is_error
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-session.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_that("as_tool_call_result handles ContentToolResult with error", {

output <- as_tool_call_result(data, tool_result)

expect_equal(output$result$content[[1]]$text, "error message")
expect_match(output$result$content[[1]]$text, "error message")
expect_true(output$result$isError)
})

Expand Down