Skip to main content
Glama

patch

Apply JSON Patch operations to modify specific database records by adding, removing, or replacing field values using RFC 6902 standard patch format.

Instructions

Apply JSON Patch operations to a specific record (RFC 6902).

This tool applies a sequence of patch operations to modify a record. However, since SurrealDB doesn't natively support JSON Patch, this implementation converts patches to a merge operation. Supported operations:

  • add: Add a new field or array element

  • remove: Remove a field (limited support)

  • replace: Replace a field value

Args: thing: The full record ID to patch in format "table:id" (e.g., "user:john") patches: Array of patch operations. Each operation should have: - op: The operation type ("add", "remove", "replace", "move", "copy", "test") - path: The field path (e.g., "/email", "/profile/bio") - value: The value for add/replace operations

Returns: A dictionary containing: - success: Boolean indicating if patch was successful - data: The complete record after applying patches - applied_patches: Number of patch operations applied - error: Error message if patch failed (only present on failure)

Examples: >>> await patch("user:john", [ ... {"op": "replace", "path": "/email", "value": "john@newdomain.com"}, ... {"op": "add", "path": "/verified", "value": true} ... ]) { "success": true, "data": {"id": "user:john", "email": "john@newdomain.com", "verified": true, ...}, "applied_patches": 2 }

Note: This provides compatibility with JSON Patch but internally uses SurrealDB's merge. Complex operations like "move" or "test" are not fully supported.

Input Schema

NameRequiredDescriptionDefault
patchesYes
thingYes

Input Schema (JSON Schema)

{ "properties": { "patches": { "items": { "additionalProperties": true, "type": "object" }, "title": "Patches", "type": "array" }, "thing": { "title": "Thing", "type": "string" } }, "required": [ "thing", "patches" ], "type": "object" }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lfnovo/surreal-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server