document
This tool covers document CRUD, tree navigation, metadata, and daily-note oriented document operations.
When to read this page: you need to create, move, query, or convert documents.
Related pages:
Common Actions
| Group | Actions |
|---|---|
| Create and read | create, lookup, ensure_link_targets, get_doc, get_outline |
| Tree navigation | get_child_blocks, get_child_docs, list_tree, search_docs |
| Metadata and mutations | rename, move, reorder, remove, set_attr, duplicate |
| Daily note / conversion | create_daily_note, heading_to_doc, doc_to_heading |
Parameters and Semantics
createtakes either a human-readablepath, orparentPath+title; omitmarkdownto create an empty document. Preferpathfor child documents. TheparentPath+titlemode accepts either a human-readable parent path or a storage path ending in.syreturned bylookup.lookupresolves byid, storagepath, or human-readablehpath/hPath; useincludeto requestid,ids,path,hpath, ordocInfo.ensure_link_targetsprovisions a reusable import link map inside one exact scope:notebook+ direct-parentparentId.resolveandreuseaccept only explicit direct-child document IDs.createaccepts explicit new titles, but never treats a matching existing title as identity: it reportssame_title_child_requires_explicit_idinunresolvedinstead. Every resolved or created output includes exactid, notebook, storagepath, andhPathreadback.ensure_link_targets(dryRun=true)is valid only formode="create"; it inspects and reportswouldCreatewithout mutation.resolveandreuseare read-only discovery operations. A realcreatefollows the normal two-call contract: preflight withvalidateOnly=true, then exactly one request with a fresh UUIDv7requestIdand returnedexpectedStructureHash. Do not retry after an unknown transport outcome: inspect or reuse the original request ID. The action never automatically removes documents it created.- The returned
idPathincludes availableid/ids. When several documents share the same hpath,include: ["ids"]returns all matching IDs; the tool includes a SQL fallback. rename,remove, andmoveoften need a storage path if you are not using document IDs.reordertakes a notebook or parent-documentparentIDplusorderedIDs. The array must contain every visible direct child document ID exactly once. It enables custom notebook sorting (sortMode: 6) and does not move, rename, or edit any document.get_child_docsrequires a documentid; it does not acceptnotebook + path.list_treeusesnotebook + path, andpathis a storage path such as/or/20240318112233-abc123.sy, not a human-readable path.- If bulk
removehits SiYuan's shortindexingwindow, retry by deleting one document at a time withnotebook + storage path. set_attrwrites document metadata attributes by document ID.get_outlinecalls SiYuan's native outline endpoint and returns the heading tree, block IDs, nesting, andheadingCountwithout reading the document body. Useget_docinstead when you also need editable Markdown.
Markdown and Title Rules
createmarkdown does not need a same-name leading# Title; if present, it is stripped to avoid duplicate visible titles.createaccepts((id 'title')), naked((id)), and#tag#directly. Naked refs are expanded to explicit anchors; if lookup fails, MCP falls back to((id 'id'))with a warning.createallows footnote-style refs such as[^1]and[text](siyuan://blocks/id), but the result includes a hint because they do not create SiYuan backlinks.get_docreturns the same editable Markdown shape asfs.read, preserving((id 'title'))and#tag#.get_doc mode="markdown"always returns complete display-block windows. Continue withnextWindowor useblockStart,blockLimit, andtokenBudget; the response also includes a full headingoutline.includeBlockIds=trueadds sidecar block references without changingcontent.- Character
page/pageSizepagination has been removed.mode="html"remains the unpaginated current-view HTML path and continues to usesize.
Safety Rules
removeandmoverequire explicit confirmation.- Always resolve document path type before mutating by path.
- Never use a title search result as a link target. Re-run
ensure_link_targetsinresolveorreusemode with the exact ID returned by an earlier successful result.
Examples
MCP:
json
{
"action": "create",
"notebook": "<notebook-id>",
"path": "/Inbox/Weekly Note",
"markdown": "Weekly report body"
}json
{
"action": "lookup",
"id": "<doc-id>",
"include": "path"
}json
{
"action": "ensure_link_targets",
"notebook": "<notebook-id>",
"parentId": "<parent-document-id>",
"mode": "reuse",
"targets": [{ "key": "source-index", "id": "<direct-child-document-id>" }]
}For a new target, call the same action first with mode: "create" and validateOnly: true, then commit exactly once using the returned expectedStructureHash, a fresh UUIDv7 requestId, and an explicit title target. A same-title child is an unresolved result, not an implicit reuse.
CLI:
bash
siyuan document create --notebook <notebook-id> --path "/Inbox/Weekly Note" --markdown "Weekly report body"
siyuan document lookup --id <doc-id> --include path
siyuan document reorder --parent-id <notebook-or-parent-doc-id> --ordered-ids-json '["<doc-id-1>","<doc-id-2>"]'
siyuan document ensure_link_targets --notebook <notebook-id> --parent-id <parent-document-id> --mode reuse --targets-json '[{"key":"source-index","id":"<direct-child-document-id>"}]'Action List
createlookupensure_link_targetsrenameremovemovereorderget_child_blocksget_child_docsset_attrlist_treesearch_docsget_docget_outlinecreate_daily_noteduplicateheading_to_docdoc_to_heading