Skip to contents

Starts the package's MCP server in a separate R process and calls the tool over stdio, as an MCP client does. A package loaded from source, as under devtools::test(), is served in its development version through pkgload::load_all(); an installed package, as under R CMD check, in its installed version.

Usage

call_tool(
  tool,
  args = list(),
  transport = "stdio",
  package = testthat::testing_package(),
  timeout = 90,
  client = c("mordew", "inspector"),
  task = FALSE,
  answer = NULL,
  sample = NULL,
  roots = NULL
)

Arguments

tool

Name of the tool.

args

Named list of arguments.

transport

Transport to the server: "stdio".

package

Package that serves the tool, by default the one being tested.

timeout

Seconds to wait for each answer of the server, with the "mordew" client: longer by default than the 60 seconds a server lets a call run, so that a call too long gets the error of the server.

client

MCP client that calls the tool: "mordew", its own, or "inspector", the MCP Inspector run through npx, which needs Node.js. A client written by others checks that the server is understood beyond {mordew}'s own reading of the protocol. "inspector" is not supported on Windows yet.

task

TRUE runs the tool as a task, through tasks/result, with the "mordew" client. A tool tagged @mcpTask required always runs as one.

answer

What the user answers when the tool asks before it runs (@mcpConfirm, @mcpElicit), with the "mordew" client: a named list of the fields of the form, accepted, list() to accept a confirmation, or "decline" or "cancel", also the answer to every form of ask(). NULL calls as a client that cannot ask the user.

sample

The text the model of the client writes when the tool asks for one (@mcpSample, input_sample()), with the "mordew" client. NULL calls as a client that cannot sample.

roots

The URIs of the roots of the client, a character vector, when the tool asks for them (input_roots()), with the "mordew" client. NULL calls as a client without roots.

Value

The tool result: a list with content and isError.

Examples

if (FALSE) { # \dontrun{
# In the tests of a package made by create_mordew():
result <- call_tool(
  "longest_runs",
  list(
    n = 3
  )
)
result$content[[1]]$text
} # }