selmaR includes a Model Context Protocol (MCP) server that lets Claude query your SELMA instance in natural language. The server runs as a local JSON-RPC 2.0 stdio process and exposes 7 tools for exploring student management data.
Setup
Add the server to your Claude Code settings
(~/.claude/settings.json or project .claude/settings.json):
{
"mcpServers": {
"selmaR": {
"command": "Rscript",
"args": ["<path-to-selmaR>/inst/mcp/server.R"],
"cwd": "<directory-containing-config.yml>"
}
}
}The server reads credentials from config.yml in the working directory
(same format as selma_connect()).
Tools
The MCP server exposes the following tools to Claude:
auth_statusCheck connection and field policy status.
list_entitiesList all available SELMA entity types with descriptions.
search_entitiesSearch entity types by keyword (case-insensitive, matches name and description).
describe_entityGet per-column summary statistics for an entity. Returns aggregates only — never individual rows.
get_entity_summaryGet filtered/grouped aggregate statistics. Supports
filter_byandgroup_byparameters.get_efts_reportGenerate an EFTS funding report by source and category for a given year.
execute_rExecute R code in a sandboxed workspace with dplyr, tidyr, ggplot2, lubridate, and scales. Variables persist between calls. Code is inspected before execution — namespace access and I/O functions are blocked.
PII Protection (7 Defence Layers)
Student data is sensitive. The server enforces:
ID pseudonymisation — session-scoped deterministic hashing of all ID columns.
AST code inspection — blocked packages and functions in
execute_r.Input allowlisting — only the 7 tools above are exposed; no raw API access.
PII field policy — configurable YAML allowlist controls which columns are visible per entity (see
inst/mcp/field_policy.yml).Hybrid data access — structured tools return aggregates only, never individual rows.
Output scanning — regex and PII dictionary checks on all responses before they leave the server.
Audit logging — JSONL log of every tool call plus a session summary report.
Files
The MCP server consists of:
inst/mcp/server.RMain MCP server (~1500 lines).
inst/mcp/field_policy.ymlDefault PII field policy — controls which columns Claude can see for each entity.
inst/mcp/test_server.RTest suite for the security layers.
See also
vignette("mcp-examples") for usage walkthroughs,
vignette("mcp-server-design") for the full security architecture.
