Skip to contents

gptr_mcp_add() writes a server into gptr's own mcp.json: the user file under tools::R_user_dir("gptr", "config"), or .gptr/mcp.json of the project (used only when you trust the project). It never edits another harness's files. Give exactly one of command (a server started as a local process speaking stdio) and url (a Streamable HTTP server). Secret values in env and headers must be ${VAR} placeholders: they are expanded from the environment when gptr connects and never stored. Nothing connects until a tool is used.

Usage

gptr_mcp_add(
  name,
  command = NULL,
  args = character(),
  url = NULL,
  env = NULL,
  headers = NULL,
  exposure = "r",
  timeout = 60,
  scope = c("user", "project")
)

gptr_mcp_remove(name, scope = c("user", "project"))

Arguments

name

Server name: 1-64 letters, digits, _ or -. Its tools are reached as peter$mcp$<name>$<tool>() inside the r tool.

command, args

The program and its arguments for a stdio server.

url

The endpoint of a Streamable HTTP server.

env, headers

Named character vectors: environment variables of a stdio server, HTTP headers of an HTTP server. Write secrets as ${VAR} placeholders.

exposure

How the model reaches the tools: "r" (R functions listed in the prompt), "direct" (declared as tools), "deferred" (found through peter$search()) or "hidden".

timeout

Seconds per request; progress notifications from the server extend it.

scope

"user" (default) or "project".

Value

gptr_mcp_add() returns the server spec invisibly; gptr_mcp_remove() returns TRUE invisibly when a server was removed, else FALSE.

Examples

proj = tempfile("proj")
dir.create(proj)
old = options(gptr.project_root = proj)
gptr_init(proj)
gptr_mcp_add("fs", command = "npx",
             args = c("-y", "@modelcontextprotocol/server-filesystem", "."),
             scope = "project")
gptr_mcp_remove("fs", scope = "project")
options(old)
unlink(proj, recursive = TRUE)