R6 class for registering custom MCP resources that the server exposes
via the resources/list and resources/read MCP protocol methods. Mirrors the
ergonomics of ToolRegistry but registration is imperative rather than file-scanned.
Details
Each registered resource carries a zero-argument resource_reader callback
that the server invokes when the client issues a resources/read request. Readers
may return either a simple list(text = ..., mimeType = ...) /
list(blob = ..., mimeType = ...) shape (which the registry wraps into a full
MCP contents envelope) or a complete list(contents = list(...)) shape.
Methods
Method register()
Register a resource entry.
Usage
MCPResourceRegistry$register(
uri,
name,
resource_reader,
description = NULL,
mimeType = NULL,
title = NULL,
annotations = NULL,
size = NULL,
meta = NULL,
mcp_app_only = FALSE,
overwrite = FALSE
)Arguments
uriNon-empty character scalar identifying the resource.
nameNon-empty character scalar with a human-readable name.
resource_readerZero-argument function returning the resource contents.
descriptionOptional description string.
mimeTypeOptional default MIME type for the resource.
titleOptional title string.
annotationsOptional annotations list passed through to the descriptor.
sizeOptional size hint.
metaOptional
_metalist passed through to the descriptor.mcp_app_onlyLogical; if
TRUE, the resource is only listed/read for clients that announce MCP Apps support.overwriteLogical; if
TRUE, replace an existing entry with the same URI.
Method list()
List resource descriptors visible to the calling client.
Method read()
Read a resource by URI.
Method has()
Check whether a URI is registered.
Examples
if (FALSE) { # \dontrun{
reg <- MCPResourceRegistry$new()
reg$register(
uri = "data://hello",
name = "Hello",
resource_reader = function() list(text = "hi", mimeType = "text/plain")
)
server <- mcprServer$new(resource_registry = reg)
} # }
