{"id":35094172,"url":"https://github.com/devOpifex/mcpr","last_synced_at":"2026-01-07T10:02:49.650Z","repository":{"id":298089777,"uuid":"997825111","full_name":"devOpifex/mcpr","owner":"devOpifex","description":"Model Context Protocol server and client for R","archived":false,"fork":false,"pushed_at":"2025-06-19T16:46:02.000Z","size":2042,"stargazers_count":45,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-19T17:43:34.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mcpr.opifex.org/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devOpifex.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-07T09:08:20.000Z","updated_at":"2025-06-19T16:46:06.000Z","dependencies_parsed_at":"2025-06-19T17:38:45.997Z","dependency_job_id":null,"html_url":"https://github.com/devOpifex/mcpr","commit_stats":null,"previous_names":["devopifex/mcpr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devOpifex/mcpr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fmcpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fmcpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fmcpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fmcpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devOpifex","download_url":"https://codeload.github.com/devOpifex/mcpr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devOpifex%2Fmcpr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28234560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-07T02:00:05.975Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-27T15:04:24.313Z","updated_at":"2026-01-07T10:02:49.645Z","avatar_url":"https://github.com/devOpifex.png","language":"R","funding_links":[],"categories":["📚 Projects (1974 total)"],"sub_categories":["MCP Servers"],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"man/figures/logo.png\" /\u003e\n\u003c/div\u003e\n\nmcpr is an R implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io),\nenabling R applications to expose capabilities (tools, resources, and prompts)\nto AI models through a standard JSON-RPC 2.0 interface. It also provides client\nfunctionality to connect to and interact with MCP servers.\n\nSee the official [MCP documentation](https://modelcontextprotocol.io) for more information,\nparticularly on schemas and capabilities.\nVisit [package docs](https://mcpr.opifex.org/) for more information on the R implementation.\n\n## Installation\n\nYou can install mcpr from GitHub using the [pak](https://pak.r-lib.org/) package:\n\n```r\npak::pkg_install(\"devOpifex/mcpr\")\n```\n\n## Basic Usage\n\n### Server\n\nHere's a simple example that creates an MCP server with a calculator tool:\n\n```r\nlibrary(mcpr)\n\ncalculator \u003c- new_tool(\n  name = \"calculator\",\n  description = \"Performs basic arithmetic operations\",\n  input_schema = schema(\n    properties = properties(\n      operation = property_enum(\n        \"Operation\", \n        \"Math operation to perform\", \n        values = c(\"add\", \"subtract\", \"multiply\", \"divide\"),\n        required = TRUE\n      ),\n      a = property_number(\"First number\", \"First operand\", required = TRUE),\n      b = property_number(\"Second number\", \"Second operand\", required = TRUE)\n    )\n  ),\n  handler = function(params) {\n    result \u003c- switch(params$operation,\n      \"add\" = params$a + params$b,\n      \"subtract\" = params$a - params$b,\n      \"multiply\" = params$a * params$b,\n      \"divide\" = params$a / params$b\n    )\n\n    response_text(result)\n  }\n)\n\nmcp \u003c- new_server(\n  name = \"R Calculator Server\",\n  description = \"A simple calculator server implemented in R\",\n  version = \"1.0.0\"\n)\n\nmcp \u003c- add_capability(mcp, calculator)\n\nserve_io(mcp)\n```\n\nYou can return multiple responses by returning a list of `response` objects:\n\n```r\nresponse(\n  response_text(\"Hello, world!\"),\n  response_image(system.file(\"extdata/logo.png\", package = \"mcpr\")),\n  response_audio(system.file(\"extdata/sound.mp3\", package = \"mcpr\")),\n  response_video(system.file(\"extdata/video.mp4\", package = \"mcpr\")),\n  response_file(system.file(\"extdata/file.txt\", package = \"mcpr\")),\n  response_resource(system.file(\"extdata/resource.json\", package = \"mcpr\"))\n)\n```\n\nYou can also serve via HTTP transport with `serve_http`:\n\n```r\n# Serve via HTTP on port 3000\nserve_http(mcp, port = 3000)\n```\n\nSee the [Get Started](https://mcpr.opifex.org/articles/get-started) guide for more information.\n\n## MCP Roclet\n\nmcpr includes a roxygen2 roclet that can automatically generate MCP servers from your R \nfunctions using special documentation tags. \nThis provides a convenient way to expose existing R functions as MCP tools.\n\n### Usage\n\n1. Add `@mcp` and `@type` tags to your function documentation:\n\n```r\n#' Add two numbers\n#' @param x First number\n#' @param y Second number  \n#' @type x number\n#' @type y number\n#' @mcp add_numbers Add two numbers together\nadd_numbers \u003c- function(x, y) {\n  x + y\n}\n```\n\n2. Generate the MCP server using roxygen2:\n\n```r\n# Generate documentation and MCP server\nroxygen2::roxygenise(roclets = c(\"rd\", \"mcpr::mcp_roclet\"))\n```\n\nThis will create an MCP server file at `inst/mcp_server.R` that includes:\n- Tool definitions for all functions with `@mcp` tags\n- Proper input schemas based on `@type` tags\n- Handler functions that call your original R functions\n- A complete, runnable MCP server\n\n### Supported Types\n\nThe `@type` tag supports these parameter types:\n- `string` - Text values\n- `number` - Numeric values (integers and decimals)\n- `integer` - Integer values\n- `boolean` - True/false values\n- `array` - Lists/vectors\n- `object` - Complex R objects\n- `enum:value1,value2,value3` - Enumerated values\n\n### Example Generated Server\n\n```r\n# Generated MCP server code\nadd_numbers_tool \u003c- new_tool(\n  name = \"add_numbers\",\n  description = \"Add two numbers together\", \n  input_schema = schema(\n    properties = properties(\n      x = property_number(\"x\", \"First number\", required = TRUE),\n      y = property_number(\"y\", \"Second number\", required = TRUE)\n    )\n  ),\n  handler = function(params) {\n    result \u003c- add_numbers(params$x, params$y)\n    response_text(result)\n  }\n)\n\nmcp_server \u003c- new_server(\n  name = \"Auto-generated MCP Server\",\n  description = \"MCP server generated from R functions with @mcp tags\",\n  version = \"1.0.0\"\n)\n\nmcp_server \u003c- add_capability(mcp_server, add_numbers_tool)\nserve_io(mcp_server)\n```\n\n### Client\n\nHere's a simple example of using the client to interact with an MCP server:\n\n```r\nlibrary(mcpr)\n\n# Create a client that connects to an MCP server\n# For HTTP transport\nclient \u003c- new_client_http(\n  \"http://localhost:8080\",\n  name = \"calculator\",\n  version = \"1.0.0\"\n)\n\n# Or for standard IO transport\n# client \u003c- new_client_io(\n#   \"Rscript\",\n#   \"/path/to/server.R\",\n#   name = \"calculator\",\n#   version = \"1.0.0\"\n# )\n\n# List available tools\ntools \u003c- tools_list(client)\nprint(tools)\n\n# Call a tool\nresult \u003c- tools_call(\n  client,\n  params = list(\n    name = \"calculator\",\n    arguments = list(\n      operation = \"add\",\n      a = 5,\n      b = 3\n    )\n  ),\n  id = 1L\n)\nprint(result)\n\n# List available prompts\nprompts \u003c- prompts_list(client)\nprint(prompts)\n\n# List available resources\nresources \u003c- resources_list(client)\nprint(resources)\n\n# Read a resource\nresource_content \u003c- resources_read(\n  client,\n  params = list(\n    name = \"example-resource\"\n  )\n)\nprint(resource_content)\n```\n\n## ellmer integration\n\nNow supports ellmer tools, you can use ellmer's or mcpr's tools,\ninterchangeably.\n\nSee the example below, taken from the\n[ellmer documentation](https://ellmer.tidyverse.org/articles/tool-calling.html#defining-a-tool-function)\n\n```r\n# create an ellmer tool\ncurrent_time \u003c- ellmer::tool(\n  \\(tz = \"UTC\") {\n    format(Sys.time(), tz = tz, usetz = TRUE)\n  },\n  \"Gets the current time in the given time zone.\",\n  tz = ellmer::type_string(\n    \"The time zone to get the current time in. Defaults to `\\\"UTC\\\"`.\",\n    required = FALSE\n  )\n)\n\nmcp \u003c- new_server(\n  name = \"R Calculator Server\",\n  description = \"A simple calculator server implemented in R\",\n  version = \"1.0.0\"\n)\n\n# register ellmer tool with mcpr server\nmcp \u003c- add_capability(mcp, current_time)\n\nserve_io(mcp)\n```\n\n## Using mcpr\n\n### Claude Code Integration\n\nTo use your MCP server with Claude Code, see the [documentation](https://docs.anthropic.com/en/docs/claude-code/tutorials#set-up-model-context-protocol-mcp)\n\n```bash\nclaude mcp add r-calculator -- Rscript /path/to/calculator_server.R\n```\n\n### Cursor Integration\n\nTo integrate with Cursor see the [documentation](https://docs.cursor.com/context/model-context-protocol)\n\n```json\n{\n  \"customCommands\": {\n    \"r-calculator\": {\n      \"command\": \"Rscript 'path/to/calculator_server.R'\"\n    }\n  }\n}\n```\n### VS Code Agent Mode Integration\nTo integrate with VS Code Agent mode see the [documentation](https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server-to-your-user-settings)\n```json\n\"mcp\": {\n        \"servers\": {\n            \"my-mcp-server-calculator\": {\n                \"type\": \"stdio\",\n                \"command\": \"Rscript\",\n                \"args\": [\n                    \"path/to/calculator_server.R\"\n                ]\n            }\n      }\n}\n```\nMore integrations in the [docs](https://mcpr.opifex.org/articles/client-integration)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Fmcpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FdevOpifex%2Fmcpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevOpifex%2Fmcpr/lists"}