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 @@ -19,7 +19,7 @@ Description: Create, run, and connect to Model Context Protocol (MCP) servers, a
License: GPL (>= 2)
Depends: R (>= 4.1.0)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "mcpr::mcp_roclet"))
RoxygenNote: 7.3.2
Imports:
yyjsonr
Expand All @@ -29,6 +29,7 @@ Suggests:
knitr,
rmarkdown,
httr2,
ellmer
ellmer,
roxygen2
URL: https://mcpr.opifex.org/, https://github.com/devOpifex/mcpr
VignetteBuilder: knitr
15 changes: 15 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ S3method(resources_list,client)
S3method(resources_list,server)
S3method(resources_read,client)
S3method(resources_read,server)
S3method(roclet_output,roclet_mcp)
S3method(roclet_process,roclet_mcp)
S3method(roxy_tag_parse,roxy_tag_mcp)
S3method(roxy_tag_parse,roxy_tag_type)
S3method(roxy_tag_rd,roxy_tag_mcp)
S3method(roxy_tag_rd,roxy_tag_type)
S3method(send,jsonrpc_error)
S3method(send,jsonrpc_response)
S3method(tools_call,client)
Expand All @@ -29,6 +35,7 @@ export(add_capability)
export(ellmer_to_mcpr_tool)
export(get_name)
export(initialize)
export(mcp_roclet)
export(new_client_io)
export(new_mcp)
export(new_prompt)
Expand Down Expand Up @@ -63,3 +70,11 @@ export(serve_io)
export(tools_call)
export(tools_list)
export(write)
importFrom(roxygen2,block_get_tag_value)
importFrom(roxygen2,block_get_tags)
importFrom(roxygen2,roclet)
importFrom(roxygen2,roclet_output)
importFrom(roxygen2,roclet_process)
importFrom(roxygen2,roxy_tag_parse)
importFrom(roxygen2,roxy_tag_rd)
importFrom(roxygen2,roxy_tag_warning)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# mcpr 0.0.2

- Added support for `ellmer::tool`
- Added MCP roclet for automatic server generation:
- New `@mcp` tag for marking functions as MCP tools
- New `@type` tag for specifying parameter types (string, number, boolean, array, object, enum)
- `mcp_roclet()` function integrates with roxygen2 to generate complete MCP servers
- Automatically creates `inst/mcp_server.R` with tool definitions and handlers
- Supports all standard JSON Schema types and enum values

# mcpr 0.0.1

Expand Down
46 changes: 39 additions & 7 deletions R/input-schema.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#' Create a new input schema
#'
#' @param properties List of property definitions
#' @param type Type of the schema
#' @param additional_properties Logical indicating if additional properties are allowed
#' @param properties List of property definitions created with properties()
#' @type properties object
#' @param type Type of the schema (default: "object")
#' @type type string
#' @param additional_properties Whether additional properties are allowed
#' @type additional_properties boolean
#'
#' @return A list representing a JSON Schema object
#' @mcp create_json_schema Create a JSON Schema object for MCP tool inputs with property validation
#' @export
#'
#' @examples
Expand Down Expand Up @@ -93,15 +97,24 @@ new_property <- function(type, title, description, required = FALSE, ...) {
#' Create a string property definition
#'
#' @param title Short title for the property
#' @type title string
#' @param description Longer description of the property
#' @type description string
#' @param required Whether the property is required
#' @type required boolean
#' @param enum Optional character vector of allowed values
#' @type enum array
#' @param pattern Optional regex pattern the string must match
#' @type pattern string
#' @param min_length Optional minimum length
#' @type min_length number
#' @param max_length Optional maximum length
#' @param format Optional format (e.g., "date-time", "email", "uri")
#' @type max_length number
#' @param format Optional format constraint
#' @type format enum:date-time,email,uri,hostname,ipv4,ipv6
#'
#' @return A string property object
#' @mcp create_string_property Create a string property with validation constraints for MCP schemas
#' @export
#'
#' @examples
Expand Down Expand Up @@ -147,16 +160,26 @@ property_string <- function(
#' Create a number property definition
#'
#' @param title Short title for the property
#' @type title string
#' @param description Longer description of the property
#' @type description string
#' @param required Whether the property is required
#' @type required boolean
#' @param minimum Optional minimum value
#' @type minimum number
#' @param maximum Optional maximum value
#' @param exclusive_minimum Optional logical for exclusive minimum
#' @param exclusive_maximum Optional logical for exclusive maximum
#' @type maximum number
#' @param exclusive_minimum Whether minimum is exclusive
#' @type exclusive_minimum boolean
#' @param exclusive_maximum Whether maximum is exclusive
#' @type exclusive_maximum boolean
#' @param multiple_of Optional value the number must be a multiple of
#' @param integer Logical indicating if the number should be an integer
#' @type multiple_of number
#' @param integer Whether the number should be an integer
#' @type integer boolean
#'
#' @return A number property object
#' @mcp create_number_property Create a number property with range and type constraints for MCP schemas
#' @export
#'
#' @examples
Expand Down Expand Up @@ -205,10 +228,14 @@ property_number <- function(
#' Create a boolean property definition
#'
#' @param title Short title for the property
#' @type title string
#' @param description Longer description of the property
#' @type description string
#' @param required Whether the property is required
#' @type required boolean
#'
#' @return A boolean property object
#' @mcp create_boolean_property Create a boolean property for MCP schemas
#' @export
#'
#' @examples
Expand Down Expand Up @@ -316,11 +343,16 @@ property_object <- function(
#' Create an enum property with predefined values
#'
#' @param title Short title for the property
#' @type title string
#' @param description Longer description of the property
#' @type description string
#' @param values Character vector of allowed values
#' @type values array
#' @param required Whether the property is required
#' @type required boolean
#'
#' @return An enum property object
#' @mcp create_enum_property Create an enum property with predefined values for MCP schemas
#' @export
#'
#' @examples
Expand Down
4 changes: 3 additions & 1 deletion R/io.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' Serve an MCP server using stdin/stdout
#'
#' @param mcp An MCP server object
#' @param mcp An MCP server object created with new_server()
#' @type mcp object
#'
#' @return Nothing, runs indefinitely in normal mode, or the response in test mode
#' @mcp start_mcp_server_io Start an MCP server using stdin/stdout transport
#' @export
serve_io <- function(
mcp
Expand Down
54 changes: 40 additions & 14 deletions R/mcp.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#' Create a new MCP object
#'
#' @param name Name of the MCP
#' @param description Description of the MCP
#' @param version Version of the MCP
#' @param tools List of tools
#' @param resources List of resources
#' @param prompts List of prompts
#' @param name Name of the MCP server
#' @type name string
#' @param description Description of the MCP server
#' @type description string
#' @param version Version of the MCP server
#' @type version string
#' @param tools List of tools (optional)
#' @type tools array
#' @param resources List of resources (optional)
#' @type resources array
#' @param prompts List of prompts (optional)
#' @type prompts array
#' @param ... Forwarded to [new_server()]
#'
#' @return A new MCP object
#' @mcp create_mcp_server Create a new MCP server with specified name, description, and version
#' @export
#'
#' @examples
Expand Down Expand Up @@ -94,11 +101,16 @@ new_mcp <- function(...) {
#' Create a new tool
#'
#' @param name Name of the tool
#' @param description Description of the tool
#' @param input_schema Input schema for the tool
#' @param handler Function to handle the tool
#' @type name string
#' @param description Description of the tool
#' @type description string
#' @param input_schema Input schema for the tool (must be a schema object)
#' @type input_schema object
#' @param handler Function to handle the tool execution
#' @type handler object
#'
#' @return A new tool capability
#' @mcp create_mcp_tool Create a new MCP tool with input schema and handler function
#' @export
#'
#' @examples
Expand Down Expand Up @@ -152,12 +164,18 @@ new_tool <- function(
#' Create a new resource
#'
#' @param name Name of the resource
#' @type name string
#' @param description Description of the resource
#' @type description string
#' @param uri URI of the resource
#' @param mime_type Mime type of the resource
#' @param handler Function to handle the resource
#' @type uri string
#' @param mime_type MIME type of the resource (optional)
#' @type mime_type string
#' @param handler Function to handle the resource request
#' @type handler object
#'
#' @return A new resource capability
#' @mcp create_mcp_resource Create a new MCP resource with URI and MIME type
#' @export
#'
#' @examples
Expand Down Expand Up @@ -199,11 +217,16 @@ new_resource <- function(name, description, uri, mime_type = NULL, handler) {
#' Create a new prompt
#'
#' @param name Name of the prompt
#' @type name string
#' @param description Description of the prompt
#' @type description string
#' @param arguments List of arguments for the prompt
#' @param handler Function to handle the prompt
#' @type arguments array
#' @param handler Function to handle the prompt execution
#' @type handler object
#'
#' @return A new prompt capability
#' @mcp create_mcp_prompt Create a new MCP prompt with arguments and handler function
#' @export
#'
#' @examples
Expand Down Expand Up @@ -269,10 +292,13 @@ new_capability <- function(

#' Add a capability to an MCP object
#'
#' @param capability A capability object
#' @param mcp An MCP object
#' @param mcp An MCP server object
#' @type mcp object
#' @param capability A tool, resource, or prompt capability object
#' @type capability object
#'
#' @return The MCP object with the capability added
#' @mcp add_mcp_capability Add a tool, resource, or prompt capability to an existing MCP server
#' @export
add_capability <- function(mcp, capability) {
UseMethod("add_capability", capability)
Expand Down
4 changes: 3 additions & 1 deletion R/response.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Create a response object
#'
#' @param text Text content
#' @param text Text content for the response
#' @type text string
#' @param image Image content
#' @param audio Audio content
#' @param video Video content
Expand All @@ -25,6 +26,7 @@
#'
#' @name response
#' @return A response object
#' @mcp create_text_response Create a text response for MCP tool handlers
#' @export
response_text <- function(text) {
if (missing(text)) {
Expand Down
Loading
Loading