flowchart LR A(Developers) --> B(Analysis,<br/>Algorithms,<br/>Business Logic,<br/>Cool stuff) B --> |R Package,<br/>CLI| D(Developers)
Model Context Protocol server and client for R.
From one dev to the another.
flowchart LR A(Developers) --> B(Analysis,<br/>Algorithms,<br/>Business Logic,<br/>Cool stuff) B --> |R Package,<br/>CLI| D(Developers)
flowchart LR A(Developers) --> B(Analysis,<br/>Algorithms,<br/>Business Logic,<br/>Cool stuff) B --> |R Package,<br/>CLI| D(Developers) B --> |RESTful API| E(Machines)
flowchart LR A(Developers) --> B(Analysis,<br/>Algorithms,<br/>Business Logic,<br/>Cool stuff) B --> |R Package,<br/>CLI| D(Developers) B --> |API| E(Machines) B --> |App,<br/>Document| F(Humans)
flowchart LR A(Developers) --> B(Analysis,<br/>Algorithms,<br/>Business Logic,<br/>Cool stuff) B --> |R Package,<br/>CLI| D(Developers) B --> |API| E(Machines) B --> |App,<br/>Document| F(Humans) B --> |MCP| G(LLMs)
A model that takes text as input and generates text as output.
Give LLMs access to tools (functions).

JSON-RPC message format transmitted over standard I/O (recommended) or HTTP.
Specs: modelcontextprotocol.io
{mcpr} implements the Model Context Protocol
Response
{
"jsonrpc":"2.0",
"result": {
"tools":[
{
"name":"get_weather",
"description":"Get weather for a location",
"inputSchema":{
"type":"object",
"properties":{
"location":{
"type":"string",
"title":"Location",
"location":"The location to get weather for"
}
},
"additionalProperties":false,
"required":["location"]
}
},
// more tools
]},
"id":1
}Let’s create a simple MCP server that provides help for R functions!
Will enable the LLM to fetch contextual help for R functions.
The server function is rather simple.
help <- new_tool(
name = "help",
description = "Retrieves internal documentation ..."
input_schema = schema(
properties = properties(
pkg = property_string(
"Package",
"Name of the package",
required = TRUE
),
fnc = property_string(
"Function",
"Name of the function",
required = TRUE
)
)
),
handler = function(params) {
response_text(
get_documentation(params$pkg, params$fnc)
)
}
)
mcp <- add_capability(mcp, help)Simply serve it.
Supports both HTTP and stdio (recommended).
Make descriptions lengthy and descriptive.
This increases the chances of the LLM triggering the MCP call.
@type to specify the argument type@mcp to define the name of the function and the descriptionExample
Add the roclet to your roxygen config.
Roxygen: list(
markdown = TRUE,
roclets = c("collate", "rd", "namespace", "mcpr::mcp_roclet")
)
Run devtools::document() to generate the MCP server at inst/mcp_server.R.
Initialise a new client.
client <- new_client_io(
command = "Rscript help.R",
name = "r-documentation-client",
version = "1.0.0"
)Supports both HTTP and stdio (recommended).
List the tools available.
Call a tool.
Use {ellmer} tools with {mcpr}.
Register {mcpr} tools with {ellmer}.
I write code, founder of Opifex.
Slides: rrr.is/mcpr

{mcpr}: Model Context Protocol server and client for R