Skip to contents

Resources

A resource is data that the client reads by its URI and adds to the context: the user or the client application picks it, the model does not call it. A resource is a function without arguments, tagged with its URI. add_resource("surfaces") creates R/resource_surfaces.R and its test file, with the URI <package>://surfaces. Once written, a resource looks like this:

#' Surfaces
#'
#' The surfaces a run can be on, one per line.
#'
#' @mcpResource runlog://surfaces
surfaces <- function() {
  c(
    "road",
    "trail",
    "track"
  )
}

The roclet writes it in mordew_resources, keyed by its URI, next to the tool registry; @mcpIcon gives it icons, as it does a tool or a prompt. The roxygen title becomes the resource’s title, the description its description, and the function’s name its name. The roclet stops on a resource without title or description, on @mcpResource on an object that is not a function, and on two resources with the same URI.

Each read calls the function. As a tool does, a resource declares what it returns with @mcpReturns, text by default, and its value is converted as a tool’s is (see Return conventions), under a MIME type:

@mcpReturns Sent as
text (default) text/plain text, one element per line
table text/markdown text, the first 50 rows
json application/json text
image image/png blob, base64
html text/html;profile=mcp-app text, one element per line

html is the page of an MCP App, with a ui:// URI (see MCP Apps).

A function that fails, or that returns anything else than what it declares, gets a JSON-RPC error -32603 with the message; an unknown URI gets -32002, with the URI in data.uri. Over HTTP, the workers read the resources, as they run the tools.

A URI with variables, such as runlog://runs/{year}, makes a resource template, which clients list with resources/templates/list instead of resources/list. Its variables are name, the simple ones of RFC 6570, and they must be the arguments of the function, none for a URI without variables: the roclet stops otherwise. Reading runlog://runs/2024 calls runs(year = "2024"): each variable takes one segment of the URI, without /, as a string kept as it is in the URI, percent-encoding included. A resource with that exact URI is read first. The value comes from the client: check it in the function.

A client follows a resource with resources/subscribe and its URI, the URI of a resource or one that a template matches, until resources/unsubscribe. A function of the package that changes the data behind a resource calls mordew::notify_resource_updated(uri): the worker sends it to the front, which sends notifications/resources/updated to every session subscribed to that exact URI, whoever made the change, and the client reads the resource again. The subscriptions are kept for the stdio connection or the HTTP session: a request without a session gets -32603, an unknown URI -32002. Over HTTP, the notification goes on the stream that the client opens with a GET (see Listening), and a session without one does not get it. The server sees no change made outside its functions, such as a file edited by hand. Outside a server, notify_resource_updated() only checks its argument.

Prompts

A prompt is a message prepared by the server, which the user picks in the client, such as a slash command, and the client sends to the model: the model does not call it. A prompt is a function tagged @mcpPrompt that returns a character vector, sent as one user text message, one element per line, or a list of blocks made by the content_*() functions (see Return conventions), sent as one user message per block, such as an image then a question on it. add_prompt("review_run") creates R/prompt_review_run.R, a function that reads its text from inst/mordew/prompts/review_run.md, and its test file. With an argument, a prompt looks like this:

#' Review a run
#'
#' Asks the model for a review of one run.
#'
#' @param run_id ID of the run.
#' @mcpPrompt
review_run <- function(run_id) {
  paste(
    "Review the run",
    run_id,
    "of my log: pace, elevation gain and surface."
  )
}

The roclet writes it in mordew_prompts, keyed by its name, with its title, description and arguments: each argument needs an @param, its description, and is required when it has no default value. Arguments always come as strings, as MCP sends them: an unknown or missing argument, or one that is not a string, gets a JSON-RPC error -32602, as an unknown prompt does; a function that fails, or returns neither a character vector nor a list of blocks, gets -32603. Over HTTP, the workers get the prompts, as they run the tools.

@mcpComplete run_id complete_run_ids links an argument to complete_run_ids(value, context), a function of the package that suggests its values: clients call it through completion/complete while the user types. It gets value, the text typed so far, and context, a named list of the arguments already filled, empty when the client sends none, and returns the suggestions as a character vector. The first 100 are sent, with their total; an argument without @mcpComplete gets none, and a context that is not strings by name gets -32602. The server answers at most run_mcp_server(completions = ) completion requests per second, 10 by default, as the specification asks: the others get a “retry later” error -32603 without calling the function. The specification leaves to this function sorting by relevance, fuzzy matching, and keeping sensitive values out of the suggestions. The same tag completes a variable of a resource template, such as @mcpComplete year complete_years for runlog://runs/{year}. The roclet stops on an @mcpComplete that names no argument of the prompt or variable of the template. The prompt above with its completion, here from three IDs written in the function:

#' Review a run
#'
#' Asks the model for a review of one run.
#'
#' @param run_id ID of the run.
#' @mcpPrompt
#' @mcpComplete run_id complete_run_ids
review_run <- function(run_id) {
  paste(
    "Review the run",
    run_id,
    "of my log: pace, elevation gain and surface."
  )
}

complete_run_ids <- function(value, context) {
  ids <- c(
    "2025-03-01",
    "2025-03-08",
    "2025-04-12"
  )
  ids[startsWith(
    ids,
    value
  )]
}

Claude Code lists each prompt as a slash command and passes its arguments separated by spaces, so an argument cannot hold a space there. Its documentation mentions neither completion nor resource templates (checked on 2026-11-28).

Skills

A skill is a set of instructions for the model on how to use the tools of the server, such as which tools to call in which order: a folder with a SKILL.md file, and any other file that it uses. The server serves the skills of the folders of inst/mordew/skills/, following the io.modelcontextprotocol/skills extension. add_skill("year-review") creates inst/mordew/skills/year-review/SKILL.md; the other files of the skill go next to it:

inst/mordew/skills/
└── year-review/
    ├── SKILL.md
    └── examples/
        └── 2024.md

SKILL.md begins with YAML frontmatter between two --- lines, which gives at least the name of the skill and its description, then the instructions:

---
name: year-review
description: Review one year of the training log, compared with the year before. Use it when the user asks how a year went.
---

1. Call summarise_runs on the year, then on the year before.
2. Call summarise_runs_by_month on the year, to find its biggest and
   smallest months.

The name is the name of the folder, 1 to 64 lowercase letters, digits and single hyphens, and the description a text of 1 to 1024 characters. The other fields of the frontmatter are sent as they are. The server reads the skills when it starts, and stops on a skill without frontmatter, with a wrong name or description, or with more than 512 files or 16 MiB.

Each file of a skill is a resource whose URI follows its path in the folder: skill://year-review/SKILL.md and skill://year-review/examples/2024.md. The folders above a skill stay in its URI, so inst/mordew/skills/runlog/year-review/ gives skill://runlog/year-review/SKILL.md. A skill inside another one is a skill of its own, and its files are files of the other one too.

A client of the 2026-07-28 revision finds the skills with skills/list, which gives the entry of each skill: the URI of its SKILL.md, its frontmatter, and each of its files with its size and a SHA-256 digest of its bytes, so the client can check what it reads. skills/get gives the entry of one skill from the URI of its SKILL.md. The client then reads the files with resources/read: a text file comes as it is, text/markdown for a .md file, application/json, text/csv and text/html for these extensions and text/plain otherwise, and any other file as base64. The segments of a URI are percent-encoded, so my week.md is read at my%20week.md. Skills do not show in resources/list. The client can also list a folder of a skill, such as skill://year-review or skill://year-review/examples, with resources/directory/read: it gets the files and the folders right inside it, a folder with the type inode/directory. The folders above a skill are not listed.