btw_mcp_server() starts an MCP server with tools from btw_tools(), which
can provide MCP clients like Claude Desktop or Claude Code with additional
context. The function will block the R process it's called in and isn't
intended for interactive use.
To give the MCP server access to a specific R session, run btw_mcp_session()
in that session. If there are no sessions configured, the server will run
the tools in its own session, meaning that e.g. the
btw_tools(tools = "env") tools will describe R objects in that R
environment.
Usage
btw_mcp_server(tools = btw_tools())
btw_mcp_session()Arguments
- tools
A list of
ellmer::tool()s to use in the MCP server, defaults to the tools provided bybtw_tools(). Usebtw_tools()to subset to specific list of btw tools that can be augmented with additional tools. Alternatively, you can pass a path to an R script that returns a list of tools as supported bymcptools::mcp_server().
Value
Returns the result of mcptools::mcp_server() or
mcptools::mcp_session().
Configuration
To configure this server with MCP clients, use the command Rscript and the
args -e "btw::btw_mcp_server()". For example, in Claude Desktop's configuration format:
For Claude Code:
For Continue, include the following in your config file:
See also
These functions use mcptools::mcp_server() and mcptools::mcp_session()
under the hood. To configure arbitrary tools with an MCP client, see the
documentation of those functions.
Examples
# Should only be run non-interactively, and
# will block the current R process once called.
if (FALSE) {
# To start a server with btw tools:
btw_mcp_server()
# To only do so with a subset of btw's tools, e.g. those
# that fetch package documentation:
btw_mcp_server(tools = btw_tools("docs"))
}
# To allow the server to access variables in specific
# sessions, call `btw_mcp_session()` in that session:
btw_mcp_session()
