mcp_client() starts an MCP server as a child process, as a client
application does, and opens an MCP 2025-11-25 session with it over
stdio. mcp_request() sends it a request and returns the result;
mcp_close() closes the session and stops the server. The server can be
written in any language. The client answers the questions of the server
with answer, sample and roots, as call_tool() does, declares
only the capabilities it got an answer for, and answers -32601 to a
request for another. mcp_close() closes the input of the server,
waits timeout seconds for it to stop, then asks it to terminate, and
kills it a second later.
Usage
mcp_client(
command,
args = character(),
timeout = 90,
answer = NULL,
sample = NULL,
roots = NULL
)
mcp_request(client, method, params = NULL)
mcp_close(client)Arguments
- command
The command that starts the server.
- args
Its arguments.
- timeout
Seconds to wait for each answer of the server. A request that gets none is cancelled with
notifications/cancelled.- 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 ofask().NULLcalls 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.NULLcalls 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.NULLcalls as a client without roots.- client
A client made by
mcp_client().- method
The method of the request, such as
"tools/call".- params
The parameters of the request, a named list.
Value
mcp_client(): the client. mcp_request(): the result of the
request, a list; an error of the server stops with its message.
mcp_close(): NULL, invisibly.
Examples
if (FALSE) { # \dontrun{
client <- mcp_client(
"Rscript",
c(
"-e",
"runlog::run_mcp_server()"
)
)
mcp_request(
client,
"tools/list"
)
mcp_close(
client
)
} # }