mcp_host_context() reports what the chat client showing the app has
told it: the color theme, whether the app is inline or full screen, and
the user's locale and time zone. Reading it inside a reactive expression,
observer, or render function makes that code run again when it changes,
so a plot can switch to dark colors when the user switches the chat to
dark mode.
The values arrive with the app's first request from the page, so the first render, for the model's call that opened the app, sees an empty list.
Usage
mcp_host_context(session = shiny::getDefaultReactiveDomain())Value
A named list with any of theme ("light" or "dark"),
display_mode ("inline", "fullscreen", or "pip"), locale,
time_zone, and platform. An empty list before the page has reported
them, and NULL outside shinymcp's runtime.
Shiny's own MCP support
Shiny is gaining MCP support of its own
(https://github.com/rstudio/shiny/pull/4407). Once it is released, it
will be the way to put a live Shiny app in a chat, and shinymcp will stop
serving live apps. as_mcp_app(), mcp_endpoint(), and
mcp_tool_module() will take only apps built from tools, and bindMcp()
and the helpers for server functions (mcp_model_context(),
mcp_host_context(), and the rest) will be removed. For something the
model should be able to use on its own, rewrite that part of the app as
tools with mcp_app(); see vignette("rewriting-as-tools").
See also
Other server function helpers:
mcp_model_context()
