Package {rairai}


Title: Model Context Protocol Server for Package Intelligence
Version: 0.2.7
Description: Helps artificial intelligence (AI) agents develop 'R' packages more efficiently and make better-informed code changes. Provides focused, package-aware context through the Model Context Protocol (MCP) so agents can understand existing behavior and assess changes with less manual exploration. Inspects packages without loading or executing their code.
License: MIT + file LICENSE
URL: https://github.com/tosidata/rairai, https://tosidata.github.io/rairai/
BugReports: https://github.com/tosidata/rairai/issues
Encoding: UTF-8
Depends: R (≥ 4.3.0)
Imports: mcplite, cachem, jsonlite, stringr, purrr, glue, rlang, fs, gert, R6, frontmatter, rvest, pkgsearch, treesitter, treesitter.r
Suggests: knitr, quarto, testthat (≥ 3.0.0), withr, pkgload
Config/testthat/edition: 3
VignetteBuilder: quarto
Config/roxygen2/version: 8.1.0
Config/roxygen2/markdown: TRUE
NeedsCompilation: no
Packaged: 2026-10-30 13:30:58 UTC; juha
Author: Juha Itkonen [aut, cre]
Maintainer: Juha Itkonen <juha@tosidata.com>
Repository: CRAN
Date/Publication: 2026-11-18 20:50:02 UTC

Create a JSON response

Description

Absent, empty, and NA values each have distinct JSON-shaping meanings; use them consistently.

Usage

json_response(..., auto_unbox = TRUE)

Arguments

...

Fields to include in the JSON object.

auto_unbox

Passed to jsonlite::toJSON().

Value

A JSON object string.


Serve the MCP tools

Description

Runs a Model Context Protocol (MCP) server over standard input and output.

Usage

serve(path = ".")

Arguments

path

Existing package directory to inspect by default. Accepts absolute, relative, and tilde paths. Defaults to the current working directory.

Details

Tools that inspect a local package can use package_root to select a different directory for one request. Supply an absolute path; this does not change the server's default directory.

Value

Called for its side effect of serving MCP requests over standard input and output. Blocks the current R process until standard input closes.

File access and security

The path argument is not a sandbox. It selects a default directory but does not restrict access to other directories. An MCP client can request any directory readable by the R process. Responses may disclose file names, file contents, and absolute paths to that client. The inspected package's code is not loaded or executed.

To limit access, run the server with restricted filesystem permissions or in a container that exposes only the files you intend to share.

See Also

vignette("tools", package = "rairai") for the tool guide.


Create an MCP tool error response

Description

Create an MCP tool error response

Usage

tool_error_response(..., auto_unbox = TRUE)

Arguments

...

Fields to include in the JSON object.

auto_unbox

Passed to jsonlite::toJSON().

Value

Throws a tool-level error whose message is JSON text.


Create a successful MCP tool response

Description

Create a successful MCP tool response

Usage

tool_value_response(..., auto_unbox = TRUE)

Arguments

...

Fields to include in the JSON object.

auto_unbox

Passed to jsonlite::toJSON().

Value

JSON text for successful MCP tool content.