Skip to contents

Register a custom serializer for a specific class

Usage

register_mcp_serializer(class_name, serializer_func)

Arguments

class_name

Character, name of the R class

serializer_func

Function that takes an object and returns JSON-compatible representation

Examples

# Register a custom serializer for spatial data
if (requireNamespace("sf", quietly = TRUE)) {
  register_mcp_serializer("sf", function(obj) {
    list(
      type = "geojson",
      data = sf::st_as_geojson(obj)
    )
  })
}