Skip to main content
Glama
triliumnext-mcp

triliumnext-mcp

by perfectra1n

Write attachment

write_attachment
Destructive

Update a TriliumNext attachment by changing its metadata, replacing stored content from a URL, file, base64 or text, or editing text via search/replace blocks or a diff patch.

Instructions

Update an attachment: mode="metadata" changes role/mime/title/position; "replace" overwrites the body (path, URL, data URL, base64 or text; the stored mime is kept); "edit" applies "changes" or a "patch" to a text attachment (binary attachments must use "replace").

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "attachmentId": "<attachmentId>",
      "mode": "<mode>"
    },
    "name": "write_attachment"
  }
}

Input Schema

NameRequiredDescriptionDefault
mimeNoNew MIME type (metadata mode only).
modeYesWrite mode. "metadata" — update role/mime/title/position only. "replace" — overwrite attachment content (accepts a file path, http(s) URL, data URL, base64, or raw text). "edit" — apply search/replace blocks (changes) or a unified diff (patch) to text content.
roleNoNew role (metadata mode only): "image" for pictures embedded in the note, "file" for downloadable files (Trilium accepts other values, but these are the two in normal use).
patchNo"edit" mode: single-file unified diff (with @@ hunks) against the stored text.
titleNoNew title/filename (metadata mode only).
changesNo"edit" mode: {old_string, new_string} blocks applied in order; each old_string must match the stored text exactly once ("" inserts at the start).
contentNoNew content for "replace" mode, in any form create_attachment content accepts (URL, data URL, base64, raw text, or a server-side file path when permitted).
positionNoNew position for ordering (metadata mode only).
attachmentIdYesID of the attachment to write to

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed9 schema fields changedv0.4.0
    • addedInput schema / properties / attachmentId / maxLength
      Added value: +128
    • addedInput schema / properties / attachmentId / pattern
      Added value: +"^[A-Za-z0-9_]+$"
    • changedInput schema / properties / changes / description
      Previous value: -"\"edit\" mode: array of {old_string, new_string} blocks applied sequentially to existing content."New value: +"\"edit\" mode: {old_string, new_string} blocks applied in order; each old_string must match the stored text exactly once (\"\" inserts at the start)."
    • changedInput schema / properties / changes / items / properties / new_string / description
      Previous value: -"The replacement string"New value: +"Replacement text (\"\" deletes old_string)"
    • changedInput schema / properties / changes / items / properties / old_string / description
      Previous value: -"The exact string to find in the existing content"New value: +"Exact substring of the stored content; must occur exactly once (\"\" = insert at start)"
    • changedInput schema / properties / content / description
      Previous value: -"New content for \"replace\" mode. Pass any of: a local file path (\"/abs/path\" or \"~/path\"), an http(s) URL, a data URL (data:image/png;base64,...), or inline base64 (binary types) / raw text (text types) — the source is auto-detected. Use a file:// prefix to force path interpretation."New value: +"New content for \"replace\" mode, in any form create_attachment content accepts (URL, data URL, base64, raw text, or a server-side file path when permitted)."
    • changedInput schema / properties / mode / description
      Previous value: -"Write mode. \"metadata\" — update role/mime/title/position only. \"replace\" — overwrite attachment content (accepts a file path, http(s) URL, data URL, base64, or raw text). \"edit\" — apply search/replace blocks (changes) or a unified diff (patch) to existing text content."New value: +"Write mode. \"metadata\" — update role/mime/title/position only. \"replace\" — overwrite attachment content (accepts a file path, http(s) URL, data URL, base64, or raw text). \"edit\" — apply search/replace blocks (changes) or a unified diff (patch) to text content."
    • changedInput schema / properties / patch / description
      Previous value: -"\"edit\" mode: unified diff to apply to existing content."New value: +"\"edit\" mode: single-file unified diff (with @@ hunks) against the stored text."
    • changedInput schema / properties / role / description
      Previous value: -"New role (metadata mode only)."New value: +"New role (metadata mode only): \"image\" for pictures embedded in the note, \"file\" for downloadable files (Trilium accepts other values, but these are the two in normal use)."
  2. First observedv1.0.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already flag destructiveHint=true, idempotentHint=false and openWorldHint=true, so the mutating nature is known. The description adds real substance beyond them: "replace" overwrites the stored body while retaining the stored MIME, and "edit" supports either search/replace blocks or a unified diff, with binary content excluded from edit. It never states the return value or error behavior, keeping it below 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the verb and the mode taxonomy, and every clause carries a mode-specific constraint with no filler. It is compressed into a single dense semicolon-chained sentence, which is efficient but slightly harder to scan than a short bulleted breakdown.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter destructive mutation tool with no output schema, the description supplies the mode semantics and safety-relevant constraints an agent needs to pick the right path. Remaining gaps are minor: no statement of permissions required, return shape, or what happens to sibling fields not mentioned in metadata mode.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3, but the description adds cross-parameter meaning the schema cannot: which content forms "replace" accepts, that MIME is preserved on replace, and that binary attachments are ineligible for "edit". It does not cover position/role/title beyond mode gating, so 4 rather than 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ("Update an attachment") and immediately decomposes it into three named modes with distinct effects. An agent can distinguish this from create_attachment or get_attachment purely from the description's mode breakdown.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear per-mode selection rules, including the hard constraint that binary attachments must use "replace" and that "edit" applies only to text attachments. It stops short of explicitly contrasting with siblings like create_attachment (for new attachments) or stating when not to call it, so not a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.