Methods
McpClient$new()
Create a client. Use mcp_client().
Usage
McpClient$new(url, headers = NULL, name = NULL, timeout = 60, transport = NULL)
Arguments
url, headers, name, timeout
See mcp_client().
transport
For tests: a function taking a request (a list with
method, url, headers, body, and the JSON-RPC id), async,
and timeout, and returning a response (status, headers,
body) or a promise of one.
The server's tools, from tools/list, with their
_meta. The list is kept for as long as the server says it may be,
or a minute.
Usage
McpClient$tools(refresh = FALSE, wait = TRUE)
Arguments
refresh
Read the list again even if it is kept.
wait
FALSE to return the last list the client got, however
old, without asking the server: NULL if it has none.
Call a tool.
Usage
McpClient$call_tool(name, arguments = NULL)
Arguments
name
Tool name.
arguments
Named list of arguments, sent as JSON. A vector of
one value goes as one value; write an array of one as list(x).
Returns
The tools/call result: a list with content, and possibly
structuredContent, _meta, and isError.
McpClient$read_resource()
Read a resource, such as an app's ui:// page.
Usage
McpClient$read_resource(uri)
Returns
The resources/read result, a list with contents.
McpClient$request()
Send any request and return its result.
Usage
McpClient$request(method, params = NULL)
Arguments
method
JSON-RPC method.
params
Named list of parameters.
McpClient$send()
Send a JSON-RPC request and return the whole response,
errors included, with the request's own id. Hosts use this to pass
an app's requests on.
Arguments
message
A JSON-RPC request (a list).
tools(), returning a promise.
Usage
McpClient$tools_async(refresh = FALSE)
Arguments
refresh
Read the list again even if it is kept.
call_tool(), returning a promise.
Usage
McpClient$call_tool_async(name, arguments = NULL)
Arguments
name
Tool name.
arguments
Named list of arguments.
McpClient$read_resource_async()
read_resource(), returning a promise.
Usage
McpClient$read_resource_async(uri)
McpClient$request_async()
request(), returning a promise.
Usage
McpClient$request_async(method, params = NULL)
Arguments
method
JSON-RPC method.
params
Named list of parameters.
McpClient$send_async()
send(), returning a promise.
Usage
McpClient$send_async(message)
Arguments
message
A JSON-RPC request (a list).
McpClient$protocol_version()
The protocol version in use, or NULL before the
first request.
Usage
McpClient$protocol_version()
McpClient$server_info()
What the server said about itself (name, version),
or NULL before the first request.
McpClient$close()
End the session, for servers that keep one. The next
request starts a new one.
McpClient$print()
Print a summary.