AI Knowledge & Logic

Targeted Code and Instruction Edits

Read selected lines and apply exact-text changes through existing Copilot and MCP tools, with revision protection.

Use targeted edits when changing a few lines of Python, macro content, or a section of workflow instructions. Existing read and update tools support them; you do not need a separate resource or patch tool.

Supported resources

ResourceRead toolUpdate toolText field
Python actionget_action_details (actionType: "python")update_python_actioncode
Condition providerget_condition_providerupdate_condition_providercode
Event handlerget_event_handlerupdate_event_handlercode
Recurring jobget_recurring_jobupdate_recurring_jobcode
Shared moduleget_python_moduleupdate_python_modulecode
HTTP endpointget_http_endpointupdate_http_endpointcode
Sidebar widgetget_sidebar_widget_detailsupdate_sidebar_widgetcode
Sidebar widget actionget_sidebar_widget_actionupdate_sidebar_widget_actioncode
Product-sync parserget_product_sync_parserupsert_product_sync_parsercode
Workflow variantget_workflowupdate_workflow_variantbotInstructions
Comment workflowget_comment_workflowupdate_comment_workflowbotInstructions, dmBotInstructions
Review workflowget_review_workflowupdate_review_workflowbotInstructions
Custom Python prompt sectionget_bot_configupdate_bot_configsystemPromptSectionCode

This interface edits text fields, not arbitrary JSON paths. Nested review email steps and legacy review-category configurations are not covered.

Macros (get_macro / update_macro) also support this interface for content: use contentSelection, contentRevision, contentEdits, fullContent, and expectedContentRevision. Portal HTML uses get_portal_page and patch_portal_page; see Portal Pages.

List tools for articles, macros, sidebar widgets, comment workflows and review workflows return metadata plus <field>Preview (up to 300 characters) and <field>Chars, instead of full text bodies. Use their detail readers for source. Existing list filters and pagination are unchanged.

Read bounded text, selected lines, or search matches

Omit selection arguments to read the first 12,000 characters of each text field. Small fields are returned completely. Reads never silently pretend an excerpt is a complete field. To read selected Python lines:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "actionType": "python",
  "codeSelection": { "startLine": 100, "endLine": 160 }
}

Line numbers are 1-based and inclusive. Omit startLine to begin at line 1 or endLine to read through the end. Out-of-range or reversed ranges fail.

To search literal text with context:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "actionType": "python",
  "codeSelection": { "find": "def execute_action", "contextLines": 10 }
}

Search and line ranges cannot be combined. Search is literal and case-sensitive; default context is five lines. Search results identify all match counts and return context for at most the first 50 matches. Nearby windows are merged, and omitted matches are explicitly marked as truncated. A missing search match returns zero matches, not an arbitrary excerpt.

A selected read returns its text in code, with line and absolute character boundaries in codeRead.excerpts, total sizes in codeRead.totalLines and codeRead.totalChars, and an opaque codeRevision for the complete code field. Copy that revision into the update call. Default reads also return the revision. Do not calculate revision tokens yourself.

For workflow instructions, use botInstructionsSelection and copy botInstructionsRevision. On get_workflow, also provide variantId when selecting or searching instructions. This returns only that variant; omitting both arguments retains the full workflow read. The variant must belong to the requested workflow.

Character limits and continuation

Every text read, including a line range or search result, is capped at 12,000 characters by default. Set maxChars (1-50,000) inside the selection to change the budget. This also bounds minified HTML or JSON on a single very long line. When codeRead.truncated is true, use codeSelection: { "offset": <codeRead.nextOffset>, "maxChars": 12000 } to read onward in the original field. Offsets are zero-based UTF-16 character positions, not byte offsets. Offset reads cannot be combined with line ranges or searches. Search continuation reads raw text from the indicated position; it does not repeat the search.

Use textFields to include only particular text fields; [] returns metadata only. For example, get_comment_workflow can request textFields: ["dmBotInstructions"] without also loading botInstructions. Include a field in textFields if you also supply its selection. On workflows, choose variantId to avoid reading every variant.

Never pass an excerpt to a full replacement argument. Prefer exact edits with the complete field's revision; if deliberately replacing a field, construct the entire replacement. Re-read if the revision changes between pages.

The same read selections are available on get_article (contentSelection), get_response_system_prompt (systemPromptSelection) and get_search_ui_config (for example searchResultsHtmlSelection, with textFields: ["searchResultsHtml"]). These read options do not add patch writes to those tools. read_octocom_docs accepts contentSelection and returns contentRead per page; request one slug when paging a particular document. These caps apply to the MCP/Copilot presentation, not dashboard or REST payloads.

Make exact-text edits

Call the resource's existing update tool. For example, update_python_action:

{
  "organizationId": "your-organization-id",
  "actionId": "your-action-id",
  "expectedCodeRevision": "revision-from-the-read-response",
  "codeEdits": [
    {
      "oldText": "return status == \"returned\"",
      "newText": "return status in {\"returned\", \"return_to_sender\"}"
    }
  ]
}

Each oldText must match exactly once, including whitespace, indentation and newline characters. If there are multiple matches, include more surrounding text to identify the intended occurrence. If there are no matches, read the current content and copy the text exactly. The tool never silently picks the first occurrence or replaces every occurrence.

Edits apply in array order, so a later edit sees the result of earlier edits. The whole call succeeds together or nothing is saved. Empty newText deletes the matched text. To insert text, replace an existing anchor with that anchor plus the addition. Empty oldText is invalid.

For workflow variants, use botInstructionsEdits and expectedBotInstructionsRevision. Comment DM instructions use dmBotInstructionsEdits and expectedDmBotInstructionsRevision. The custom Python prompt section uses systemPromptSectionCodeEdits and expectedSystemPromptSectionCodeRevision.

For update_http_endpoint, editing arguments belong inside its existing endpoint object. For update_review_workflow, they belong inside updates. Resource IDs and organizationId stay at their existing locations.

Full replacements remain available

Use fullCode to deliberately replace the entire script. It requires expectedCodeRevision from the read tool. For instructions use fullBotInstructions; for DM instructions use fullDmBotInstructions. Custom prompt code uses fullSystemPromptSectionCode. Each uses the corresponding expected revision.

For each text field, provide only one mode: full replacement or edits. Both are optional because settings-only updates, such as renaming or disabling a resource, do not change its text. An expected revision without a corresponding text change is invalid.

The existing code, botInstructions, dmBotInstructions, and systemPromptSectionCode arguments remain deprecated full-replacement aliases for existing clients. Old calls without revisions retain their existing behavior; prefer the explicit full fields or edits with revision protection. Do not combine an alias with the new replacement or edits argument for the same field.

Create tools still accept full content. To create the first product-sync parser, use the existing upsert_product_sync_parser call with code. Its new full/edit interface requires an existing parser; it cannot patch an absent resource.

Verify and recover

The server locks the resource in a database transaction before checking its revision and saving. If its text changed since the read, the entire update is rejected. Read it again, reassess the change, and retry with the new token. Repeated retries using the same stale token will not work.

Successful updates through the new interface return textChanges, keyed by the edited field. Each entry contains the saved revision, a before/after diff, and diffTruncated. The response omits the resource's large text fields. Diff output is bounded; when it is truncated or computation exceeds its limit, use a selected read to inspect the saved section.

Existing field constraints, resource permissions, approval behavior and version-history paths still apply. Updating code does not automatically execute it. Run the resource's existing test tool when you need to verify behavior, remembering that test execution can have real side effects.

On this page