Skip to contents

mcp_server() gathers the tools, resources and prompts of a server written in an R script rather than in a package, which run_mcp_server() serves when it gets the path of the script. Each of them is a function declared with mcp_tool(), mcp_resource() or mcp_prompt(), with the roxygen tags a package would use, written as text: @mcpType, @mcpReturns, @mcpTask, @mcpConfirm... The same checks as the roclet apply, so a declaration that the roclet refuses stops with the same error.

Usage

mcp_server(
  name,
  version,
  instructions,
  tools = list(),
  resources = list(),
  prompts = list(),
  title = NULL,
  description = NULL,
  website_url = NULL,
  icons = character(),
  skills = NULL
)

mcp_tool(
  name,
  fun,
  title,
  description,
  params = character(),
  tags = character()
)

mcp_resource(
  name,
  uri,
  fun,
  title,
  description,
  params = character(),
  tags = character()
)

mcp_prompt(
  name,
  fun,
  title,
  description,
  params = character(),
  tags = character()
)

Arguments

name

The name of the server, of the tool, of the resource or of the prompt.

version

The version of the server.

instructions

What the server does, and when the model should use its tools.

tools, resources, prompts

Lists of tools, resources and prompts made by mcp_tool(), mcp_resource() and mcp_prompt().

title, description

The title and the description: of the server, which clients may show, as a package takes them from the Title and Description of its DESCRIPTION; of a tool, a resource or a prompt, as the first lines of its roxygen block.

website_url

The website of the server, which clients may show. A package takes the first URL of its DESCRIPTION.

icons

The icons of the server, each written as an @mcpIcon tag without the tag: the URI, then mimeType=, sizes= and theme=. A package takes them from the @mcpIcon tags of the roxygen block that documents "_PACKAGE".

skills

The folder of the skills of the server, relative to the script: one folder with a SKILL.md per skill. A package serves those of inst/mordew/skills/.

fun

The function that runs the tool, reads the resource or gets the prompt.

params

The descriptions of the arguments of fun, named, as @param tags.

tags

Other roxygen tags, each a string that starts with @.

uri

The URI of the resource, or its URI template.

Value

mcp_server(): a server, for the end of the script. The others: an entry of the registry.

Examples

mcp_server(
  "runlog",
  "0.1.0",
  "Answers questions about a running log.",
  tools = list(
    mcp_tool(
      "echo",
      function(text) {
        text
      },
      "Echo the text",
      "Sends the text back.",
      params = c(
        text = "Text to send back."
      ),
      tags = c(
        "@mcpType text type_string()",
        "@mcpReturns text"
      )
    )
  )
)$name
#> NULL