document
In every mode, creation requires notebook + path or notebook + parentPath + title; use parentPath="/" for the notebook root. notebook + title alone is invalid and preflight rejects it without issuing a credential. After changing business arguments, preflight again for a new requestId; reuse an ID only to retry the same request.
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.- In strict mode,
create/create_daily_noteverify the returned document ID in the requested notebook. Matching paths in other notebooks are excluded from creation readback. ensure_link_targetspreserves its completelinkMap, dispositions, and counts even with slim responses, including read-only resolution/reuse withchanged=false. An emptycreatedarray does not mean no target was resolved.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 the server-issuedrequestIdand 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"tries full text by default, capped at 256 KiB UTF-8 and 2000 complete blocks. ExplicitblockStart,blockLimit, andtokenBudgetremain supported. Continue usingnextWindow;outlineScope="window"andtotalBlocks=nulluntil EOF. A single oversized block fails explicitly.includeBlockIds=trueadds sidecar references.- 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:
{
"action": "create",
"notebook": "<notebook-id>",
"path": "/Inbox/Weekly Note",
"markdown": "Weekly report body"
}{
"action": "lookup",
"id": "<doc-id>",
"include": "path"
}{
"action": "ensure_link_targets",
"notebook": "<notebook-id>",
"parentId": "<parent-document-id>",
"mode": "resolve",
"targets": [{ "key": "source-index", "id": "<direct-child-document-id>" }]
}{
"action": "ensure_link_targets",
"notebook": "<notebook-id>",
"parentId": "<parent-document-id>",
"mode": "reuse",
"targets": [{ "key": "source-index", "id": "<direct-child-document-id>" }]
}{
"action": "ensure_link_targets",
"notebook": "<notebook-id>",
"parentId": "<parent-document-id>",
"mode": "create",
"targets": [{ "key": "source-index", "title": "New Target" }],
"validateOnly": true
}Replace placeholder IDs with actual IDs returned by the tools. resolve/reuse targets use key + id; create targets use key + title. Never send both id and title, or key alone. The create example only preflights; commit exactly once with unchanged business arguments, validateOnly: false, the returned expectedStructureHash, and the server-issued requestId. A same-title child is an unresolved result, not an implicit reuse.
CLI:
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 resolve --targets-json '[{"key":"source-index","id":"<direct-child-document-id>"}]'
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>"}]'
siyuan document ensure_link_targets --notebook <notebook-id> --parent-id <parent-document-id> --mode create --targets-json '[{"key":"source-index","title":"New Target"}]' --validate-onlyAction List
createlookupensure_link_targetsrenameremovemovereorderget_child_blocksget_child_docsset_attrlist_treesearch_docsget_docget_outlinecreate_daily_noteduplicateheading_to_docdoc_to_heading