Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Maintainer: Bulent Arman Aksoy <arman@aksoy.org>
Authors@R:
person("Bulent Arman", "Aksoy", , "arman@aksoy.org", role = c("aut", "cre"))
Description: Extends plumber APIs with Model Context Protocol (MCP) support,
enabling AI assistants to discover and call your API endpoints as tools.
enabling AI assistants to discover and call your API endpoints as tools,
read resources for context, and use prompt templates for guided interactions.
Simply add pr_mcp() to your plumber pipeline to automatically expose all
endpoints via the MCP protocol.
endpoints via the MCP protocol with rich schema generation and documentation.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
93 changes: 93 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# plumber2mcp 0.3.0

## New Features

### Prompts Support
* Added full MCP Prompts support allowing you to define reusable prompt templates that AI assistants can discover and use
* New `pr_mcp_prompt()` function to register prompt templates with your MCP server
* Prompts support optional arguments with required/optional parameters
* Prompts can return simple strings, structured messages, or multi-turn conversations
* Both HTTP and stdio transports fully support prompts
* Added `prompts/list` and `prompts/get` JSON-RPC handlers
* Updated `initialize` response to advertise prompts capability

### Enhanced Testing
* Added comprehensive edge case testing (24 new tests)
* Added integration tests for combined features (10 new tests)
* Added security and validation tests (18 new tests)
* Total test count increased from ~69 to ~121 tests (75% increase)
* Tests now cover error handling, malformed inputs, injection attacks, and real-world scenarios

## Improvements

* Enhanced schema generation now includes output schemas
* Better error handling for malformed JSON-RPC requests
* Improved handling of NULL, NA, and empty values
* More robust handling of complex nested data structures
* Added support for functions with req/res parameters

## Documentation

* Comprehensive README updates with prompts examples and use cases
* Added example file demonstrating prompts usage (inst/examples/prompts_example.R)
* Detailed documentation of prompt message formats
* Added use cases for workflow guidance, code generation, and domain-specific assistance

## Bug Fixes

* Fixed parameter ordering in stdio transport handlers
* Fixed JSON-RPC error responses for unknown methods
* Improved type mapping for plumber parameters

# plumber2mcp 0.2.0

## New Features

### Resources Support
* Added MCP Resources support for exposing R content to AI assistants
* New `pr_mcp_resource()` function to add custom resources
* New `pr_mcp_help_resources()` convenience function for R help topics
* Resources can provide documentation, data summaries, session info, and more
* Added `resources/list` and `resources/read` handlers

### Stdio Transport
* Added native stdio transport support for standard MCP clients
* New `pr_mcp_stdio()` function for stdio-based servers
* Compatible with mcp-cli, Claude Desktop, and other MCP clients
* Handles JSON-RPC over stdin/stdout

## Improvements

* Enhanced schema generation with rich descriptions from roxygen comments
* Automatic detection of required vs optional parameters
* Improved type inference for function parameters and return values
* Better handling of empty properties (serialize as object, not array)

## Documentation

* Comprehensive README with examples for all transport types
* Added resources examples and documentation
* Added MCP Inspector testing instructions

# plumber2mcp 0.1.0

## Initial Release

### Core Features
* HTTP transport for MCP protocol
* Automatic endpoint discovery from Plumber APIs
* JSON-RPC 2.0 protocol implementation
* Tool schema generation from function signatures
* Support for include/exclude endpoint filters
* Customizable server name, version, and mount path

### MCP Protocol Support
* `initialize` - Server initialization and capabilities
* `tools/list` - List available API endpoints as tools
* `tools/call` - Execute API endpoints through MCP
* `ping` - Server health check

### Documentation
* Basic README with installation and usage
* Example Plumber API files
* GitHub Actions CI/CD setup
179 changes: 179 additions & 0 deletions R/plumber2mcp-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#' @keywords internal
"_PACKAGE"

#' plumber2mcp: Add Model Context Protocol Support to Plumber APIs
#'
#' @description
#' The plumber2mcp package extends Plumber APIs with Model Context Protocol (MCP)
#' support, enabling AI assistants (like Claude, ChatGPT, etc.) to discover and
#' interact with your R functions through three key MCP primitives:
#'
#' \itemize{
#' \item \strong{Tools}: AI assistants can call your API endpoints directly
#' \item \strong{Resources}: AI assistants can read documentation, data, and analysis results
#' \item \strong{Prompts}: AI assistants can use pre-defined templates to guide interactions
#' }
#'
#' @section Main Functions:
#'
#' \strong{Core MCP Setup:}
#' \itemize{
#' \item \code{\link{pr_mcp}}: Add MCP support to a Plumber router (main function)
#' \item \code{\link{pr_mcp_http}}: Add MCP support with HTTP transport
#' \item \code{\link{pr_mcp_stdio}}: Add MCP support with stdio transport
#' }
#'
#' \strong{Resources:}
#' \itemize{
#' \item \code{\link{pr_mcp_resource}}: Add a custom resource
#' \item \code{\link{pr_mcp_help_resources}}: Add built-in R help resources
#' }
#'
#' \strong{Prompts:}
#' \itemize{
#' \item \code{\link{pr_mcp_prompt}}: Add a prompt template
#' }
#'
#' @section Quick Start:
#'
#' \strong{HTTP Transport (for testing):}
#' \preformatted{
#' library(plumber)
#' library(plumber2mcp)
#'
#' pr("plumber.R") \%>\%
#' pr_mcp(transport = "http") \%>\%
#' pr_run(port = 8000)
#' }
#'
#' \strong{Stdio Transport (for MCP clients):}
#' \preformatted{
#' library(plumber)
#' library(plumber2mcp)
#'
#' pr("plumber.R") \%>\%
#' pr_mcp(transport = "stdio")
#' }
#'
#' @section Adding Features:
#'
#' \strong{Add a Resource:}
#' \preformatted{
#' pr \%>\%
#' pr_mcp(transport = "stdio") \%>\%
#' pr_mcp_resource(
#' uri = "/data/summary",
#' func = function() summary(mtcars),
#' name = "Dataset Summary"
#' )
#' }
#'
#' \strong{Add a Prompt:}
#' \preformatted{
#' pr \%>\%
#' pr_mcp(transport = "stdio") \%>\%
#' pr_mcp_prompt(
#' name = "analyze-data",
#' description = "Guide for data analysis",
#' arguments = list(
#' list(name = "dataset", description = "Dataset name", required = TRUE)
#' ),
#' func = function(dataset) {
#' paste("Please analyze the", dataset, "dataset")
#' }
#' )
#' }
#'
#' @section MCP Protocol:
#'
#' This package implements the Model Context Protocol (MCP) specification version
#' 2024-11-05. It provides:
#'
#' \itemize{
#' \item \strong{Automatic endpoint discovery}: Scans your Plumber API and converts endpoints to MCP tools
#' \item \strong{Rich schema generation}: Creates detailed JSON schemas from roxygen documentation
#' \item \strong{JSON-RPC 2.0}: Handles all MCP communication via JSON-RPC
#' \item \strong{Multiple transports}: HTTP (for testing) and stdio (for MCP clients)
#' \item \strong{Enhanced documentation}: Extracts parameter descriptions, types, and defaults
#' }
#'
#' @section Supported MCP Methods:
#'
#' \strong{Core Protocol:}
#' \itemize{
#' \item \code{initialize}: Server initialization and capability negotiation
#' \item \code{ping}: Health check
#' }
#'
#' \strong{Tools:}
#' \itemize{
#' \item \code{tools/list}: List available API endpoints
#' \item \code{tools/call}: Execute an API endpoint
#' }
#'
#' \strong{Resources:}
#' \itemize{
#' \item \code{resources/list}: List available resources
#' \item \code{resources/read}: Read a specific resource
#' \item \code{resources/templates/list}: List resource templates
#' }
#'
#' \strong{Prompts:}
#' \itemize{
#' \item \code{prompts/list}: List available prompt templates
#' \item \code{prompts/get}: Get a specific prompt with arguments
#' }
#'
#' @section Configuration:
#'
#' Customize your MCP server with:
#' \itemize{
#' \item \code{path}: Custom mount path (default: "/mcp")
#' \item \code{include_endpoints}: Whitelist specific endpoints
#' \item \code{exclude_endpoints}: Blacklist specific endpoints
#' \item \code{server_name}: Custom server name
#' \item \code{server_version}: Custom server version
#' \item \code{debug}: Enable debug logging (stdio only)
#' }
#'
#' @section Learn More:
#'
#' \itemize{
#' \item MCP Specification: \url{https://modelcontextprotocol.io}
#' \item GitHub Repository: \url{https://github.com/armish/plumber2mcp}
#' \item Plumber Documentation: \url{https://www.rplumber.io}
#' }
#'
#' @examples
#' \dontrun{
#' # Basic HTTP server
#' library(plumber)
#' library(plumber2mcp)
#'
#' pr <- plumber::pr()
#' pr$handle("GET", "/echo", function(msg = "hello") {
#' list(message = msg)
#' })
#'
#' pr %>%
#' pr_mcp(transport = "http") %>%
#' pr_run(port = 8000)
#'
#' # Full-featured stdio server
#' pr %>%
#' pr_mcp(transport = "stdio") %>%
#' pr_mcp_resource(
#' uri = "/docs/api",
#' func = function() "API Documentation",
#' name = "API Docs"
#' ) %>%
#' pr_mcp_prompt(
#' name = "help",
#' description = "Get help with the API",
#' func = function() "How can I help you use this API?"
#' )
#' }
#'
#' @docType package
#' @name plumber2mcp-package
NULL
Loading