Content
# r-package-mcp
A skill that turns an R package into a small, self-contained **MCP knowledge server** —
an MCP an AI assistant can query for the package's functions, arguments, datasets,
dependencies, and examples, so it can look the API up instead of guessing.
It reads documentation from the package's own `.Rd` files (via R's `tools::Rd_db`) into a
`knowledge.json`, then serves it through a generic [FastMCP](https://github.com/modelcontextprotocol)
server. The server needs no R at runtime; pair it with an R runtime if you also want to run code.
## Requirements
- **R** with `Rscript` on `PATH` (for extraction)
- **[uv](https://docs.astral.sh/uv/)** — runs the generated server and the tests; it provisions
Python and the `mcp` package itself, so nothing else to install
## Quickstart
```bash
# 1. extract the package's docs into knowledge.json
Rscript scripts/extract_rpkg.R <package> <package>_knowledge.json --install
# 2. assemble the server
python scripts/build_server.py <package>_knowledge.json <package>-mcp
# 3. test it — protocol (tools respond) and content (examples run)
uv run scripts/test_server.py <package>-mcp
Rscript scripts/check_examples.R <package>
```
The build step also writes a paste-ready registration snippet (`mcp.config.json`). See
[SKILL.md](SKILL.md) for the full workflow and options (e.g. `--update` to match the current
CRAN version instead of a stale local install).
## Tools the generated server exposes
`package_overview`, `search_functions`, `get_function`, `list_functions`, `get_examples`,
`get_related`, `get_recipes`, `list_datasets`, `get_dataset`, `get_dependencies`.
## Using it as a skill
This is an agent skill: point a coding agent at [SKILL.md](SKILL.md) (or drop this directory
into your agent's skills folder) and ask it to build an MCP for an R package. The scripts can
also be run directly, as shown above.
## Layout
- `SKILL.md` — the workflow an agent follows
- `scripts/` — extractor, builder, server template, and test/validate scripts
- `references/` — the `knowledge.json` schema, extraction notes, and server/registration notes
## License
[MIT](LICENSE).