Model Context Protocol (MCP)
Allows LLMS to more easily integrate with external tools
Notes from MCP (Model Context Protocol): Simply explained in 5 minutes
Packages
- {debrief} (Intro) - Code optimization diagnostic that provides LLM-friendly text output from a {profvis} analysis. (See Code, Optimization)
- {mcptools} - Allows MCP-enabled tools like Claude Desktop, Claude Code, and VS Code GitHub Copilot can run R code in the sessions you have running to answer your questions
- Works well with {btw}
- {mcpr} - Enables R applications to expose capabilities (tools, resources, and prompts) to AI models through a standard JSON-RPC 2.0 interface. It also provides client functionality to connect to and interact with MCP servers
- {fastapi_mcp} - Exposes FastAPI endpoints as Model Context Protocol (MCP) tools with Auth (i.e. takes an existing FastAPI application and essentially “turning it into” an MCP server)
- {plumber2mcp} - Takes a plumber API and exposes its endpoints as MCP utilities (Same as {fastapi.mcp})
- By adding MCP support to your Plumber API, you make your R functions available as:
Tools: AI assistants can call your API endpoints directly
Resources: AI assistants can read documentation, data, and analysis results
Prompts: AI assistants can use pre-defined templates to guide interactions
- By adding MCP support to your Plumber API, you make your R functions available as:
Resources
- Docs
- Model Context Protocol servers - Links to official mcp servers and community-based servers
Servers
- R Econometrics MCP Server
- mcp-repl - A MCP server that exposes a long-lived interactive REPL runtime over stdio.
- It is backend-agnostic in design. The default interpreter is R, with an opt-in Python interpreter (–interpreter python).
- Session state persists across calls, so agents can iterate in place, inspect intermediate values, debug, and read docs in-band.
Using MCP servers rather than the cloud service CLI tools (e.g. BigQuery CLI) provides better security control over what LLM products (e.g. Claude Code) can access, especially for handling sensitive data that requires logging or has potential privacy concerns.
-
- MCP Client: Various clients and apps you use, like Cursor, know how to talk using the “MCP Protocol.”
- MCP Servers: Providers like Sentry, Slack, JIRA, Gmail, etc. set up adapters around their APIs that follow the MCP Protocol.
- They convert a message like “Get me the recent messages in the #alerts channel” to a request that can be sent to the Slack API
Server File(s) Components
- Defines a set of tools for the MCP Server to implement
- Creates the server to listen for incoming requests
- Defines a `switch` case that receives the tool call and calls the underlying external API, like the Slack API.
- Wire up transport between Client and Server
- Allows the MCP client and server to communicate more simply than standard HTTP requests. Instead, they can read from standard IO when communicating.
Security
- Notes from The MCP Server Auth Playbook: What the Spec Leaves Out
- Requirements from the MCP specification and the OAuth RFCs
- API Key
- The key says a request is authorized, so strangers don’t get access.
- Doesn’t identify the user though since keys can get passed around.
- The key is also permanent. They don’t expire or get rotated.
- OAuth
- OAuth 2.1 with PKCE (Proof Key for Code Exchange, the step that makes a stolen authorization code useless to whoever stole it)
- Tokens are validated instead of secrets
- You gain per-user identity, expiry, revocation, and a standard every client library already speaks
- DCR and CIMD
- Instead of requiring manual registration (standard OAuth policy) of every agent that wants to connect to your MCP, these two things allow the agent to register itself.
- Dynamic Client Registration (DCR) lets a client register itself at runtime and receive credentials.
- Client ID Metadata Documents (CIMD) lets a client identify itself by a URL that hosts its own metadata.
- This now creates a registration endpoint that strangers can call 😖.
- API Key
Examples
Example: Use {btw} to start a local MCP server for your R packages
claude mcp add -s "user" r-btw -- Rscript -e "btw::btw_mcp_server()"- Now Claude Code can answer questions about ANY R package installed on your system.


