An McpApp bundles a user interface with the tools it calls. It knows how
to render itself as the self-contained HTML page an MCP host shows (the
app's ui:// resource), how to describe its tools to a client, and how to
run them. Create one with mcp_app() or as_mcp_app() rather than
calling McpApp$new() directly; the arguments are the same.
Most code only needs $call_tool() (run a tool and get its R value
back, as in tests) and $html_resource() (the page a host renders).
See also
Other apps:
as_mcp_app(),
bindMcp(),
mcp_app(),
mcp_tool_module()
Public fields
nameApp name; the UI resource is
ui://<name>, with any characters a URI can't carry percent-encoded.versionApp version string.
titleHuman-readable title, or
NULL.descriptionWhat the app is for, or
NULL.
Methods
McpApp$new()
Create an app. See mcp_app() for the arguments.
Usage
McpApp$new(
ui,
tools = list(),
name = "shinymcp-app",
version = "0.1.0",
title = NULL,
description = NULL,
theme = NULL,
csp = NULL,
permissions = NULL,
prefers_border = NULL,
domain = NULL,
tool_visibility = NULL,
tool_outputs = NULL,
trigger = NULL,
debounce_ms = NULL,
resources = NULL,
host_styles = TRUE,
model_context = TRUE,
images = TRUE,
www = NULL,
runtime = NULL
)Arguments
ui, tools, name, version, title, description, theme, csp, permissions, prefers_border, domain, tool_visibility, tool_outputs, trigger, debounce_ms, resources, host_styles, model_context, images, wwwSee
mcp_app().runtimeInternal: the live Shiny runtime for apps created by
as_mcp_app()from a Shiny app.
McpApp$html_resource()
The HTML page an MCP host renders for this app. Dependencies (Bootstrap, bslib components, htmlwidgets) are inlined so the page works under a host's default Content Security Policy.
McpApp$resource_meta()
The _meta published with the app's ui:// resource
(CSP, permissions, border preference), or NULL.
McpApp$call_tool()
Run a tool and return its R value, as the tool function returned it. Useful in tests.
Arguments
nameTool name.
argumentsNamed list of arguments, as a client would send them. A vector of one value is one value; write an array of one as
list(x).contextRequest context; see
mcp_request().
McpApp$run_tool()
Run a tool and return an MCP tools/call result.
Arguments
nameTool name.
argumentsNamed list of arguments, as a client would send them. A vector of one value is one value; write an array of one as
list(x).contextRequest context.
caller = "app"marks calls from the app's own UI, andimages = FALSEasks for a result without image blocks for the model.rawIf
TRUE, return a list with theresultand therawvalue the tool function returned (NULLif it failed).
McpApp$interaction_defaults()
The app's declared interaction defaults (trigger,
debounce_ms), each possibly NULL.
McpApp$close()
Close the app's open views and stop the Shiny app
behind it, if any, running its onStop hook. serve() and
mcp_endpoint() call this when they stop.
