JS

jameshwade/shinymcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

33 stars 5 forks 质量 62 趋势 19NOASSERTION

将闪亮应用转换为MCP应用

概览

将实时闪亮的工作流程转化为MCP应用。 shinymcp 将 Shiny 接口和 R 计算转换为 MCP 应用:可运行于聊天客户端、Shiny 主机和 Shinychat 对话中的交互式卡片。 开始 查看使用场景 搭配 shinychat 的应用 ui:// 资源 声明 HTML 应用表面 用于 MCP 主机。 postMessage 桥梁 保持输入、工具调用和结果的同步。 Shiny 托管 Embed MCP 应用作为支持全屏的 Shiny 卡。 使用Shiny或bslib输入,添加MCP输出目标,并绑定到R工具。 将反应式组扁平化为工具功能,同时保持面向用户的工作流程。

概述(AI 翻译)

闪耀 YMCP 构建 MCP R中的应用。一个MCP App 是一个带有页面的工具:一个支持 MCP 应用的聊天客户端 扩展,如Claude、ChatGPT或VS Code,会在 对话,这个人可以继续使用它。在闪光 工具是R函数,页面是Shiny UI。模型可以调用 工具本身,在任何MCP客户端中,页面调用相同的工具 随着使用者使用。

安装

一个工具中的应用

名称连接了两半。工具的参数 bins 取其值 从带有该ID的输入开始,返回的列表填充输出 histogram 和 caption。当用户移动滑块时,页面 再次呼叫工具。

模型调用了同一个工具,并读取它返回的内容,无论是否 其客户端可以显示该页面:

图也以图像的形式达到它。每个结果分为三种: 模型的文本和紧凑的结构化数据,以及页面绘制的内容 (HTML、图片、控件数据),客户端传递给页面并保留这些内容 从模型中获取。结果可以包含文本、表格、图表、图片、HTML和 htmlwidgets。

preview_app(app) 在你的浏览器中打开应用的方式,就像聊天客户端一样

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

shinymcp

shinymcp builds MCP Apps in R. An MCP App is a tool with a page: a chat client that supports the MCP Apps extension, such as Claude, ChatGPT, or VS Code, shows the page in the conversation, and the person can keep working with it. In shinymcp the tools are R functions and the page is Shiny UI. The model can call the tools on their own, in any MCP client, and the page calls the same tools as the person uses it.

Installation

# install.packages("pak")
pak::pak("JamesHWade/shinymcp")

An app from a tool

library(shiny)
library(shinymcp)

faithful_histogram <- ellmer::tool(
  function(bins = 20) {
    list(
      histogram = mcp_result_plot(
        function() hist(faithful$waiting, breaks = bins, main = NULL, xlab = "Minutes"),
        text = "Histogram of waiting times between eruptions."
      ),
      caption = sprintf("%d eruptions; median wait %d minutes.", nrow(faithful), median(faithful$waiting))
    )
  },
  name = "faithful_histogram",
  description = "Show a histogram of waiting times between Old Faithful eruptions.",
  arguments = list(
    bins = ellmer::type_integer("Number of bins, 5 to 50.", required = FALSE)
  ),
  annotations = ellmer::tool_annotations(read_only_hint = TRUE)
)

app <- mcp_app(
  ui = fluidPage(
    sliderInput("bins", "Number of bins", min = 5, max = 50, value = 20),
    plotOutput("histogram"),
    textOutput("caption")
  ),
  tools = list(faithful_histogram),
  name = "faithful"
)

Names connect the two halves. The tool’s argument bins takes its value from the input with that id, and the list it returns fills the outputs histogram and caption. When the person moves the slider, the page calls the tool again.

The model calls the same tool, and reads what it returns, whether or not its client can show the page:

result <- app$run_tool("faithful_histogram", list(bins = 30))
cat(result$content[[1]]$text)
#> histogram: Histogram of waiting times between eruptions.
#> 
#> caption: 272 eruptions; median wait 76 minutes.
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "faithful": { "command": "Rscript", "args": ["/path/to/app.R"] } } }