# should only be run non-interactively, and will block the current R process
# once called.
if (identical(Sys.getenv("MCPTOOLS_CAN_BLOCK_PROCESS"), "true")) {
# to start a server with a tool to draw numbers from a random normal:
library(ellmer)
tool_rnorm <- tool(
rnorm,
"Draw numbers from a random normal distribution",
n = type_integer("The number of observations. Must be a positive integer."),
mean = type_number("The mean value of the distribution."),
sd = type_number("The standard deviation of the distribution. Must be a non-negative number.")
)
mcp_server(tools = list(tool_rnorm))
# can also supply a file path as `tools`
readLines(system.file("example-ellmer-tools.R", package = "mcptools"))
mcp_server(tools = system.file("example-ellmer-tools.R", package = "mcptools"))
}
if (interactive()) {
mcp_session()
}
Run the code above in your browser using DataLab