MCP is now the standard plug
The Model Context Protocol (MCP) is the standard way to give an AI assistant access to tools and data. Claude, ChatGPT and Copilot all speak it.
Validated functions instead of generated code
For data teams, the question is no longer “do we need a chat?” but “what can the model do with our data?”. Letting a model write and run arbitrary code is powerful, but it is hard to control, to reproduce and to audit.
The alternative is to expose a closed set of validated R functions. The model chooses which function to call and with which arguments; R does the computation. Results are reproducible, tested and traceable, which is what regulated organisations (pharma, public research) need.
Why a framework, given that the pieces exist
Every building block already exists in R (see Prior art). What is missing is the assembly: a convention to structure, test, secure and deploy an MCP server as a production artefact. That is the gap golem filled for Shiny: Shiny, testthat, roxygen and Docker all existed before golem, and golem’s contribution was “an app is a package”, plus the conventions and the path to production.
What {mordew} is, and what it is not
mordew is:
- an opinionated framework where one MCP server is one R package
- scaffolding:
create_mordew(),add_tool(),add_resource(),add_prompt(),add_skill(),use_evals(),dev/scripts - the MCP specification, revisions 2025-11-25 and 2026-07-28 (see MCP specification coverage)
- a roxygen roclet that turns documentation into a registry of tools, resources and prompts
- a testing toolkit covering three levels: unit, contract, behaviour, plus security
- runtime helpers: its own thin MCP protocol layer, over stdio and HTTP, with a worker pool and limits
- deployment helpers: Docker and Posit Connect
mordew is not:
- an LLM client: mordew never calls a model itself,
except in behavioural evals, which run the model through the
claudeCLI - a chat: a chat is a separate product, an MCP client like any other (see Scope: the chat is a separate product)
- a sandbox: OS-level isolation is documented and scaffolded, not reinvented
Scope: the chat is a separate product
A chat that talks MCP does not depend on the server it connects to: it works with any MCP server, written in R or not. Its concerns are those of another product (user authentication, conversation history, choice of model, safe rendering, scaling Shiny sessions), and its dependencies (shiny, shinychat, ellmer) would weigh on every package built with mordew. So mordew stops at the MCP server.
-
To try tools during development:
mordew::run_dev()opens an ellmer chat in the R console, or gives the command of a Claude Code session, connected to the package’s MCP server (see Development loop). The other ways to try them, with or without a model, are in Trying the tools. - To give users a chat: build it as its own application, for example a golem app using shinychat and ellmer, that connects to the mordew server through MCP. Everything the server enforces (validation, limits, the worker pool) then applies to the chat too. The section Clients we build ourselves lists what such a chat must get right.
Prior art
| Project | What it does | Gap mordew addresses |
|---|---|---|
| mcptools (Posit) | MCP server from arbitrary R functions (ellmer tools), stdio or HTTP. MCP client for ellmer chats. Turnkey deployment documented for Posit Connect. | No project structure, no testing conventions, no deployment path outside Connect. |
| mcpr (devOpifex) | Roxygen roclet: @mcp and @type tags
generate inst/mcp_server.R. Tools, resources and
prompts. |
Generates a file, not a project framework. |
| mcpr (chi2labs) | Decorator-based MCP server, following plumber’s patterns. | No package structure. |
| plumber2mcp | Turns a plumber API into an MCP server. | Starts from an API, not from a domain package. |
| mcplite | Lightweight stdio MCP server, with OpenTelemetry spans. | stdio only, no production framework. |
| shinychat + ellmer (Posit) | Shiny chat UI wired to a model, with tool-call display. | A building block for a separate chat product, outside mordew’s scope. |
| btw (Posit) | Ready-made tools that give models context about R sessions and packages. | Aimed at coding assistants, not at domain tools. |
| FastMCP (Python) | The reference framework in Python: schema, validation, authentication, deployment. | No R equivalent. |
The Python side carries two lessons:
- The framework layer has value even when the SDK exists. According to its README, some version of FastMCP powers 70% of MCP servers, all languages combined.
- The framework and the SDK can be one package. FastMCP 1.0 was merged into the official MCP Python SDK in 2024.
What makes {mordew} different
mordew does not try to be an MCP client: Claude, ChatGPT and Copilot already do that well. It focuses on industrialisation: the model only ever reaches R functions that are documented, typed and tested like any package code, and the same package carries everything needed to deploy them.
| mordew brings | Why it matters | Covered elsewhere in R? |
|---|---|---|
Package convention: create_mordew(),
add_tool(), dev/ scripts |
An MCP server is developed, versioned, reviewed and installed like any package. | No |
| Three-level testing: the function, the MCP contract, the model’s behaviour | Proves that the tool computes correctly, is exposed correctly, and is called correctly. | Level 1 only |
| Production without Posit Connect: Dockerfile, a shared token, multi-user, asynchronous execution | Production R often runs in containers, outside Posit Connect, and must serve several users at once. | No, it has to be done by hand |
| Return conventions: data frame → table, plot → image, errors the model can act on | Keeps the model’s context small and answers usable. | No |
Restricted client configurations
(mcp_client_config()) |
Generates the most restricted setup each client allows, and says when it is only partial. | No |
Who calls whom
The MCP server never calls the model, and the model never calls the
server either. A model only produces text: when it wants a tool, its
answer contains a request (“call summarise_runs with
year = 2025”). The client (Claude Code,
ellmer, a chat app…) reads that request, calls the MCP server, and sends
the result back to the model.
sequenceDiagram participant U as User participant C as MCP client participant M as Model (API) participant S as mordew server (R) C->>S: tools/list S-->>C: tool definitions U->>C: question C->>M: question + tool definitions M-->>C: "call summarise_runs(2025)" C->>S: tools/call summarise_runs S-->>C: result of the R function C->>M: tool result M-->>C: final answer, or another tool call C-->>U: answer
This has three consequences for mordew:
- The server never sees the model. It has no API key, no prompt and no conversation: only tool calls and their arguments. The model and the system prompt belong to the client.
- The model has no network access to the server. Everything goes through the client, which is what lets a client restrict the tools.
- Arguments are untrusted input. The server cannot know where a request comes from, or whether the model was manipulated.
From package to server
flowchart LR
subgraph pkg["Your R package"]
F["R/: one function per tool"]
X["roxygen: descriptions + types"]
T["tests/: unit, contract, evals"]
end
pkg -- "roclet" --> REG["Tool registry
declarative R lists"]
REG --> SRV["MCP server
mordew, stdio or HTTP"]
SRV --> EXT["MCP clients
Claude Code, Claude Desktop, Codex, Copilot"]
SRV --> CHAT["A separate chat app
an MCP client, outside mordew"]
The tool registry is the centre of the design. It is generated once from roxygen and served through a single MCP server to every client. A chat application is one of those clients, built and deployed separately. The registry is declarative data, committed and reviewed; everything that executes — the server loop, validation, serialisation — is imported from mordew at runtime, so a fix reaches deployed servers through an update, not a regeneration.
Why not build on mcptools
mcptools is the obvious base: maintained by Posit, stdio and HTTP, deployable on Posit Connect. mordew still ships its own protocol layer, for three reasons, read in the mcptools source (development version 1.0.3.9000, commit 714803b).
-
What mordew would reuse is the cheap
part: the stdio loop and the
tools/listandtools/calldispatch, about 130 lines of base R and jsonlite. -
What mordew needs, mcptools does differently
or not at all.
mcp_server()only takestools,type,host,portandsession_tools; everything else is internal code, so each point means wrapping or replacing it:- the server identity is fixed (“R mcptools server”, version 0.0.1), where mordew takes it from the package;
- arguments are not validated, R errors become JSON-RPC errors
(-32603) instead of
isErrorresults, and data frames go throughpaste(), where mordew has its own validation and return conventions; - the schema comes from an ellmer internal and cannot carry
min,maxorpattern; - HTTP is synchronous: the request handler runs the tool itself, so a slow call blocks every client, where mordew hands calls to a worker pool.
-
The dependency would reach every deployed server. A
generated package depends on mordew at runtime, so
mcptools’ eleven direct imports (httpuv, httr2, nanonext, processx…)
would come with it, against minimal runtime
Imports(see Design decisions).
The client side follows. Contract tests need the raw JSON-RPC
response, which mcp_tools() turns into ellmer objects; over
stdio it also waits 4 seconds at most and does not check response ids. A
minimal stdio client of our own serves both call_tool() and
run_dev(): it starts the server, opens a 2025-11-25
session, returns the raw response that carries each request’s id, waits
up to a configurable timeout, and reports the end of the server’s stderr
when the server stops. On Windows, writing a request larger than the
pipe buffer to a server that does not read its stdin blocks until the
server reads or exits: the timeout only applies to the answer.
The cost: following the specification becomes mordew‘s
work (see Risks), and Posit Connect needs
mordew’s own engine rather than mcptools’
engine: mcptools (see Posit Connect).
Relationship with golem
- Same philosophy: a package,
dev/scripts, conventions over configuration. - Same tooling where possible: dockerfiler.
Design decisions
The registry is generated, not introspected at runtime. An installed package keeps no roxygen comments (R drops them at install time), so there is nothing to introspect at runtime; and a committed registry makes the security boundary — the tool list — reviewable in every diff.
Types are explicit tags whose content is an R expression (see Writing a tool).
mordew ships no chat. A chat is a separate product and talks to a mordew server through MCP, like any client.
mordew ships its own protocol layer, server and stdio client (see Why not build on mcptools).
Evals have their own runner, without vitals. An eval checks tool calls, not a text answer: the tool, and each argument on its own terms, through a Claude Code session restricted to the server (see Testing strategy). That fits in a few functions of mordew; vitals stays out until its log viewer is worth the extra dependency.
One package. Runtime
Importsstay minimal — whatrun_mcp_server()executes for a package: jsonlite for the protocol, mirai, nanonext, promises and later for the front and its workers, digest for the signed state and the digests of the skills, and yaml for their frontmatter. A server written as a script also needs roxygen2 where it runs. The development and testing tooling (testthat, pkgload, processx, dockerfiler…) lives inSuggests, installed on a development machine withmordew::install_dev_deps(), the golem pattern.Default architecture for HTTP: the worker pool (B).
run_mcp_server(transport = "http")runs one, and replicas of it behind a load balancer (A + B) stay possible.-
A generated package depends on mordew at runtime, as golem apps depend on golem. The deciding argument is security: validation, limits and serialisation are load-bearing, and a fix to them must reach every deployed server through an update of mordew, never through regenerating and re-releasing each package. The generated registry stays declarative data; everything that executes is imported. The costs are accepted: mordew must be on CRAN before any package built with it is, and every user installs mordew’s dependencies. Until then, a package installs it from GitHub with the
Remotes: ThinkR-open/mordewthatcreate_mordew()writes.A mordew package should pass
R CMD check --as-cran: evals anddev/in.Rbuildignore, round-trip tests through a subprocess skipped on CRAN, examples that never start a blocking server, small example data. mordew speaks MCP 2025-11-25. It is what clients send today: Claude Code 2.1.251 and 2.1.330 both open with
initializeandprotocolVersion: 2025-11-25(checked on 2026-11-22). 2026-07-28 requests are served side by side, request by request, and both revisions pass the official conformance suite (dev/conformance.R).
Risks
| Risk | Why it is serious | Mitigation |
|---|---|---|
| Overlap with Posit’s tooling | Posit maintains the whole stack (ellmer, mcptools, shinychat, Connect), and FastMCP 1.0 was absorbed into the official Python SDK. | Focus on what mcptools does not cover (project structure, testing, production outside Connect). |
| The MCP specification changes fast | Posit describes MCP as a recent and rapidly evolving framework, and following it is mordew’s own work, since it ships its own protocol layer. | Keep the protocol layer thin, and test it through a client written by others, the MCP Inspector. |
| Maintenance cost | Open source means issues, support and upgrades. | Keep the scope small and the protocol layer thin, welcome contributors early. |
| Unclear adoption | Real use cases still have to be collected. | Build the prototype on real use cases before the first release. |
| Flaky, costly evals | Models are not deterministic, and every eval run costs tokens. | Thresholds, several runs per case, a separate CI job. |
| A blocking server in production | A process that runs tools itself runs one call at a time; one slow call blocks every user. | Asynchronous execution over HTTP: a mirai worker pool (B), with a timeout per call and a bounded queue; replicas behind a load balancer (A) on top. |
About the name
mordew is the city in Alex Pheby’s novel of the same name, where God is dead and his corpse lies in the catacombs beneath the streets, while the Living Mud spawns half-formed, short-lived creatures. A golem is clay brought to life by words; mordew is mud that spawns life. In French, the name sounds like mordieu, an old oath meaning “by God’s death”.
References
-
mcptools and
mcp_server()reference - R and the Model Context Protocol, tidyverse blog
- mcpr (devOpifex)
- mcpr (chi2labs)
- plumber2mcp
- mcplite
- shinychat: tool calling UI
- FastMCP documentation and README
- RAppArmor
- Model Context Protocol
- Specification, 2026-07-28 and its changelog
- Announcement of the 2026-07-28 specification