Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: Centralize content syntax in shared tool descriptions https://github.com/siyuan-note/siyuan/issues/20163

Daniel3b84da00dfaa
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.go
index b63caacb6f..d28978b718 100644
--- a/kernel/agent/agent.go
+++ b/kernel/agent/agent.go
@@ -50,20 +50,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their
## Domain Concepts
- Block: the fundamental unit. Everything is a block with a unique ID, including documents (a document block, type NodeDocument, is the root). Content blocks (headings, paragraphs, lists, code, tables) form a tree under a document block.
- Container blocks (can hold child blocks): document, blockquote, list, list-item, super-block, callout, tabs, tab-item, mindmap, mindmap-item. Leaf blocks (cannot hold children): heading, paragraph, code-block, math-block, table, HTML-block, thematic-break, video, audio, widget, iframe, attribute-view, block-query-embed.
-- Heading hierarchy: headings (h1-h6) are leaf blocks. Blocks that appear "under" a heading in the UI are its *following siblings* in the AST, not its children. To place a block below a heading, pass the heading's ID (or the ID of the last block currently below it) as previousID, not as parentID.
-- Nested lists: a list-item cannot directly contain another list-item. To nest lists, create a list (NodeList) as a child of the outer list-item, then add list-items to that inner list. The parent of a list-item must always be a list (NodeList).
-- Super-block layouts: despite the token names, "row" means a vertical layout with child blocks stacked top-to-bottom, while "col" means a horizontal layout with child blocks placed side-by-side. Never infer the visual direction from the English token alone.
-- To create a super-block, prefer block.insert/append/prepend with dataType "markdown" and Kramdown. For example, a horizontal super-block containing two paragraphs is:
-
-{{{col
-
-first paragraph
-
-second paragraph
-
-}}}
-
- Use {{{row for a vertical super-block. Never use data-layout in raw block DOM. If raw DOM is unavoidable, the outer block must use data-type="NodeSuperBlock" and data-sb-layout="row" or data-sb-layout="col", and every child must be complete block DOM with an explicit data-type; otherwise content may become an HTML block.
+- Heading hierarchy: headings (h1-h6) are leaf blocks. Blocks that appear "under" a heading in the UI are its *following siblings* in the AST, not its children.
- Native structured blocks: use native capabilities and preserve existing structure, block IDs, and metadata unless the user explicitly requests a conversion. Follow the relevant tool descriptions for block-specific syntax and operations.
- Notebook: a top-level container holding documents. Use notebook.list to enumerate; pass notebook ID when creating documents.
- hPath (human-readable path): the title-based path shown in the document tree, e.g. "/Diary/2024/June". The "path" parameter in document.create/move/list refers to hPath, not the internal ID-based filesystem path. A rename changes hPath but not the ID.
@@ -85,7 +72,7 @@ second paragraph
## Response Guidelines
- Reply in the language configured in SiYuan's appearance settings.
-- When mentioning documents/blocks the user can open, format them as markdown links: [title](siyuan://blocks/<blockID>). Only use block IDs actually returned by a tool call (block.get/get_children/breadcrumb/batch_get/search); never fabricate IDs. For general mentions without a specific block, plain text is fine.
+- When mentioning documents/blocks the user can open, format them as markdown links: [title](siyuan://blocks/<blockID>). Only use block IDs actually returned by a tool call; never fabricate IDs. For general mentions without a specific block, plain text is fine.
- When displaying a SiYuan tag name in chat, render its exact label as <span data-type="tag">label</span>. Keep every label character, including a leading $, inside the span and HTML-escape the label text. Never prefix the label with # or use #label# in chat.
- Be concise: summarize rather than repeat large content.
- For choices (which notebook/document/action), use the question tool — never a plain text list.
@@ -93,37 +80,6 @@ second paragraph
- Refer to the product as "SiYuan", never "SiYuan Note".
- Do not fabricate. If unknown or not found in the notes, say so honestly and search/verify before claiming facts.
-## Formatting
-- Inline formatting uses standard markdown: **bold**, *italic*, ~~strikethrough~~, ==mark==, and "code" (backticks).
-- In markdown written to SiYuan blocks, block references must include anchor text. Use ((<blockID> "<static anchor text>")) for fixed text, which is required whenever the anchor text differs from the referenced block's content. Use ((<blockID> '<dynamic anchor text>')) for text that follows the target block's content, so only when the anchor text is the target block's own content. Never use ((<blockID>)) or [[<blockID>]]. These forms are for note content; in chat responses use [title](siyuan://blocks/<blockID>).
-- For text styling that markdown cannot express (color, background, font size), use SiYuan text marks.
- The syntax requires a leading data-type="text" attribute — WITHOUT it the HTML is escaped and shown as literal text:
- - Text color: <span data-type="text" style="color: #ff0000;">red text</span>
- - Background: <span data-type="text" style="background-color: #ffff00;">highlighted</span>
- - Font size: <span data-type="text" style="font-size: 18px;">larger text</span>
- - Multiple CSS props: <span data-type="text" style="color: #ff0000; font-size: 18px;">red and large</span>
-- To also apply a markdown mark (bold/italic), list multiple types in data-type (note: this is about marking types, not CSS):
- <span data-type="text strong" style="color: #ff0000;">bold red</span> (text + bold)
- <span data-type="text em" style="background-color: #ffff00;">italic highlighted</span>
-- Prefer a semantic data-type mark over an equivalent style — data-type is SiYuan's native mark (recognized by the editor, convertible to/from markdown, and queryable), whereas style is just raw CSS. Markdown has no equivalent for these, so use the mark rather than faking it with style:
- - Underline: <span data-type="u">underlined</span> (NOT style="text-decoration: underline")
- - Superscript: x<span data-type="sup">2</span> (NOT style="vertical-align: super")
- - Subscript: H<span data-type="sub">2</span>O (NOT style="vertical-align: sub")
- - Keyboard key:<span data-type="kbd">Ctrl</span> (NOT a bare <kbd>, NOT style)
- - Tag: <span data-type="tag">todo</span> (NOT style="color: ...")
-- This rule also forbids faking ANY mark type with style — never write style="font-weight: bold", style="font-style: italic", style="text-decoration: line-through", etc. to mimic bold/italic/strikethrough/mark/code; use standard markdown (or the data-type mark) instead.
-- NEVER write a bare <span style="..."> without data-type — it will render as escaped literal text.
-- Prefer standard markdown (such as **bold**) when no color/size is needed.
-- HTML blocks (NodeHTMLBlock) render raw HTML in the document. Use one when the user wants HTML actually rendered (e.g. <ruby> annotations, styled containers), not displayed as code.
- Write the HTML as a bare block-level element whose opening tag starts with <div, on its own line(s); in SiYuan's editor the parser only recognizes a <div-opening line as an HTML block:
-
- <div>
- <ruby>你<rt>nǐ</rt></ruby>
- </div>
-
- - If the HTML root is not <div (e.g. <p>, <table>, <section>, <ruby>), wrap the whole snippet in <div>...</div> — otherwise it falls back to a plain paragraph and the HTML is escaped to literal text.
- - Do NOT use a fenced code block with an html info string for rendered HTML: that produces a code block (NodeCodeBlock) where the HTML is shown as syntax-highlighted text, not rendered. A fenced code block is for displaying source code, the opposite of rendering HTML.
-
## SiYuan User Guide
SiYuan has a built-in user guide notebook documenting all features. IDs by language: 简体中文 "20210808180117-czj9bvb", 繁體中文 "20211226090932-5lcq56f", 日本語 "20240530133126-axarxgx", others "20210808180117-6v0mkxr".
When asked whether/how SiYuan supports a feature: notebook.list to check it's open (notebook.open to open it if not), then search.fulltext the guide for docs and cite if found. Missing guide search results alone do not prove a feature is unsupported; also check the native tool descriptions and supported block types above. Do NOT invent features or UI workflows.
diff --git a/kernel/agent/capability_test.go b/kernel/agent/capability_test.go
index f14695e653..6a77af2c4b 100644
--- a/kernel/agent/capability_test.go
+++ b/kernel/agent/capability_test.go
@@ -31,41 +31,51 @@ func TestFrontendCapabilityModelNamesAreStableAndDistinct(t *testing.T) {
}
}
-func TestBlockCapabilityExposesSharedToolDescriptions(t *testing.T) {
+func TestContentCapabilitiesExposeSharedToolDescriptions(t *testing.T) {
originalConf := kernelModel.Conf
kernelModel.Conf = kernelModel.NewAppConf()
kernelModel.Conf.AI = conf.NewAI()
- id := tools.CapabilityIDForTool(tools.BlockTool)
- kernelModel.Conf.AI.Agent.CapabilityPolicy = &conf.CapabilityPolicy{
- Default: "deny", Overrides: map[string]string{id: "allow"},
- }
t.Cleanup(func() { kernelModel.Conf = originalConf })
- set, err := buildCapabilitySet(nil, capabilityAccessContext{})
- if err != nil {
- t.Fatal(err)
- }
- if len(set.definitions) != 1 || set.definitions[0].Function.Name != "block" {
- t.Fatal("block capability was not exposed independently")
- }
- definition := set.definitions[0].Function
- if definition.Description != tools.BlockTool.Description {
- t.Fatal("agent did not receive the shared block tool description")
- }
- data, err := json.Marshal(definition.Parameters)
- if err != nil {
- t.Fatal(err)
- }
- var schema tools.ToolSchema
- if err = json.Unmarshal(data, &schema); err != nil {
- t.Fatal(err)
- }
- if schema.Properties["data"].Description != tools.BlockTool.InputSchema.Properties["data"].Description {
- t.Fatal("agent did not receive the native block creation examples")
- }
- kernelModel.Conf.AI.Agent.CapabilityPolicy.Overrides[id] = "deny"
- set, err = buildCapabilitySet(nil, capabilityAccessContext{})
- if err != nil || len(set.definitions) != 0 {
- t.Fatalf("disabled block tool descriptions were still exposed: %v", err)
+ for _, tc := range []struct {
+ tool *tools.Tool
+ property string
+ }{
+ {tools.BlockTool, "data"}, {tools.DocumentTool, "markdown"},
+ {tools.DailynoteTool, "data"}, {tools.TemplateTool, "content"},
+ } {
+ t.Run(tc.tool.Name, func(t *testing.T) {
+ id := tools.CapabilityIDForTool(tc.tool)
+ kernelModel.Conf.AI.Agent.CapabilityPolicy = &conf.CapabilityPolicy{
+ Default: "deny", Overrides: map[string]string{id: "allow"},
+ }
+ set, err := buildCapabilitySet(nil, capabilityAccessContext{})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(set.definitions) != 1 || set.definitions[0].Function.Name != tc.tool.Name {
+ t.Fatal("content capability was not exposed independently")
+ }
+ definition := set.definitions[0].Function
+ if definition.Description != tc.tool.Description {
+ t.Fatal("agent did not receive the shared content tool description")
+ }
+ data, err := json.Marshal(definition.Parameters)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var schema tools.ToolSchema
+ if err = json.Unmarshal(data, &schema); err != nil {
+ t.Fatal(err)
+ }
+ if schema.Properties[tc.property].Description != tc.tool.InputSchema.Properties[tc.property].Description {
+ t.Fatal("agent did not receive the shared content syntax")
+ }
+ kernelModel.Conf.AI.Agent.CapabilityPolicy.Overrides[id] = "deny"
+ set, err = buildCapabilitySet(nil, capabilityAccessContext{})
+ if err != nil || len(set.definitions) != 0 {
+ t.Fatalf("disabled content tool descriptions were still exposed: %v", err)
+ }
+ })
}
}
diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.go
index 815fddb637..5f9788851b 100644
--- a/kernel/agent/prompt_test.go
+++ b/kernel/agent/prompt_test.go
@@ -47,26 +47,13 @@ func TestTurnContextStaysInUserMessage(t *testing.T) {
}
}
-func TestSystemPromptDocumentsBlockReferenceSyntax(t *testing.T) {
- if !strings.Contains(systemPrompt, `((<blockID> "<static anchor text>"))`) {
- t.Fatal("system prompt is missing the static SiYuan block-reference syntax")
- }
- if !strings.Contains(systemPrompt, `((<blockID> '<dynamic anchor text>'))`) {
- t.Fatal("system prompt is missing the dynamic SiYuan block-reference syntax")
- }
- if !strings.Contains(systemPrompt, `for fixed text`) ||
- !strings.Contains(systemPrompt, `for text that follows the target block's content`) {
- t.Fatal("system prompt does not explain static and dynamic block-reference behavior")
- }
- if !strings.Contains(systemPrompt, `required whenever the anchor text differs from the referenced block's content`) ||
- !strings.Contains(systemPrompt, `only when the anchor text is the target block's own content`) {
- t.Fatal("system prompt does not tie static anchor text to mismatched content and dynamic anchor text to the target's own content")
- }
- if !strings.Contains(systemPrompt, `Never use ((<blockID>)) or [[<blockID>]]`) {
- t.Fatal("system prompt does not reject block references without anchor text or bracketed block IDs")
- }
- if !strings.Contains(systemPrompt, `in chat responses use [title](siyuan://blocks/<blockID>)`) {
- t.Fatal("system prompt does not distinguish note-content block references from chat-response links")
+func TestSystemPromptDocumentsChatBlockLinks(t *testing.T) {
+ for _, capabilities := range []*capabilitySet{nil, {registrations: map[string]*capabilityRegistration{}}} {
+ prompt := filterSystemPromptByCapabilities(systemPrompt, capabilities)
+ if !strings.Contains(prompt, `[title](siyuan://blocks/<blockID>)`) ||
+ !strings.Contains(prompt, "never fabricate IDs") {
+ t.Fatal("chat block links and their ID constraints must remain available without content tools")
+ }
}
}
@@ -93,22 +80,6 @@ func TestSystemPromptUsesSanitizedKernelLogTool(t *testing.T) {
}
}
-func TestSystemPromptDocumentsSuperBlockLayout(t *testing.T) {
- for _, instruction := range []string{
- `"row" means a vertical layout`,
- `"col" means a horizontal layout`,
- `{{{col`,
- `Use {{{row for a vertical super-block`,
- `Never use data-layout in raw block DOM`,
- `data-sb-layout="row" or data-sb-layout="col"`,
- `every child must be complete block DOM with an explicit data-type`,
- } {
- if !strings.Contains(systemPrompt, instruction) {
- t.Fatalf("system prompt is missing the super-block instruction %q", instruction)
- }
- }
-}
-
func TestSystemPromptPreservesNativeStructure(t *testing.T) {
for _, instruction := range []string{
"use native capabilities and preserve existing structure, block IDs, and metadata",
@@ -128,7 +99,12 @@ func TestSystemPromptPreservesNativeStructure(t *testing.T) {
if !strings.Contains(prompt, "preserve existing structure, block IDs, and metadata") {
t.Fatal("native structure protection was removed by capability filtering")
}
- for _, detail := range []string{"NodeTabs", "NodeTabItem", "NodeMindmap", "NodeMindmapItem", "::: tabs", "@tab", "tabs-position", "tabs-active-id"} {
+ for _, detail := range []string{
+ "NodeTabs", "NodeTabItem", "NodeMindmap", "NodeMindmapItem", "::: tabs", "@tab", "tabs-position", "tabs-active-id",
+ "{{{col", "{{{row", "first paragraph", "second paragraph", "data-sb-layout", "NodeList", "previousID", "parentID",
+ "((<blockID>", "[[<blockID>]]", `data-type="text`, `data-type="u"`, `data-type="sup"`, `data-type="sub"`,
+ `data-type="kbd"`, "font-size", "font-weight", "<ruby>", "NodeHTMLBlock", "NodeCodeBlock",
+ } {
if strings.Contains(prompt, detail) {
t.Fatalf("block-specific detail %q belongs in the tool description, not the system prompt", detail)
}
diff --git a/kernel/mcp/server_test.go b/kernel/mcp/server_test.go
index 8354b4adab..c954dc4885 100644
--- a/kernel/mcp/server_test.go
+++ b/kernel/mcp/server_test.go
@@ -133,10 +133,19 @@ func TestModernProtocolClient(t *testing.T) {
}
}
-func TestBlockToolDescriptionsReachMCPClients(t *testing.T) {
+func TestContentToolDescriptionsReachMCPClients(t *testing.T) {
server, httpServer := newTestHTTPServer(t)
- syncTool(server, tools.BlockTool.Name, tools.BlockTool)
- client := mcpsdk.NewClient(&mcpsdk.Implementation{Name: "block-description-test", Version: "1.0.0"}, nil)
+ contentTools := map[string]struct {
+ tool *tools.Tool
+ property string
+ }{
+ "block": {tools.BlockTool, "data"}, "document": {tools.DocumentTool, "markdown"},
+ "dailynote": {tools.DailynoteTool, "data"}, "template": {tools.TemplateTool, "content"},
+ }
+ for name, tc := range contentTools {
+ syncTool(server, name, tc.tool)
+ }
+ client := mcpsdk.NewClient(&mcpsdk.Implementation{Name: "content-description-test", Version: "1.0.0"}, nil)
session, err := client.Connect(t.Context(), &mcpsdk.StreamableClientTransport{Endpoint: httpServer.URL}, nil)
if err != nil {
t.Fatal(err)
@@ -147,11 +156,12 @@ func TestBlockToolDescriptionsReachMCPClients(t *testing.T) {
t.Fatal(err)
}
for _, tool := range result.Tools {
- if tool.Name != tools.BlockTool.Name {
+ tc, ok := contentTools[tool.Name]
+ if !ok {
continue
}
- if tool.Description != tools.BlockTool.Description {
- t.Fatal("MCP client did not receive the shared native block rules")
+ if tool.Description != tc.tool.Description {
+ t.Fatalf("MCP client did not receive the shared %s rules", tool.Name)
}
data, err := json.Marshal(tool.InputSchema)
if err != nil {
@@ -161,12 +171,14 @@ func TestBlockToolDescriptionsReachMCPClients(t *testing.T) {
if err = json.Unmarshal(data, &schema); err != nil {
t.Fatal(err)
}
- if schema.Properties["data"].Description != tools.BlockTool.InputSchema.Properties["data"].Description {
- t.Fatal("MCP client did not receive the native block creation examples")
+ if schema.Properties[tc.property].Description != tc.tool.InputSchema.Properties[tc.property].Description {
+ t.Fatalf("MCP client did not receive the %s content syntax", tool.Name)
}
- return
+ delete(contentTools, tool.Name)
+ }
+ if len(contentTools) != 0 {
+ t.Fatalf("content tools were not listed: %v", contentTools)
}
- t.Fatal("native block tool was not listed")
}
func TestToolProjectionPolicyAndExecutionRecheck(t *testing.T) {
diff --git a/kernel/mcp/tools/block.go b/kernel/mcp/tools/block.go
index 8ea84bbd39..30781263f3 100644
--- a/kernel/mcp/tools/block.go
+++ b/kernel/mcp/tools/block.go
@@ -33,6 +33,10 @@ var BlockTool = &Tool{
Description: `Block operations, including native Tabs (NodeTabs/NodeTabItem) and Mindmap (NodeMindmap/NodeMindmapItem).
Actions: get(id), get_kramdown(id), get_children(id), tree_stat(id, by document), dom(id), insert(data, dataType, parentID?, nextID?, previousID?), append(data, dataType, parentID) / prepend(...) add a NEW child and return its ID — use after block.update when both modifying and adding, update(id, data, dataType, lockType?) replaces ONE block only (no append), delete(id), move(id, parentID, previousID?), breadcrumb(id), batch_get(ids) / batch_kramdown(ids) where ids is comma-separated.
+Block placement:
+- Headings (h1-h6) are leaf blocks; content shown below a heading is its following siblings, not its children. To place a block below a heading, use the heading ID (or the last block currently below it) as previousID, never as parentID.
+- A list-item must have a NodeList parent and cannot directly contain another list-item. To nest lists, create a NodeList inside the outer list-item, then add list-items to the inner list.
+
Native container structure and operations:
- These are native, editable blocks; do not substitute HTML widgets, Mermaid diagrams, or plugins unless requested.
- Tabs: NodeTabs contains only NodeTabItem; each item contains at least one body block and may contain nested tabs. Use an empty paragraph for an empty body. Use attr.set for tabs-position (top/left) and tabs-active-id (an existing direct item ID).
@@ -69,10 +73,12 @@ Native Mindmap DOM (dataType=dom):
<div data-type="NodeMindmap" data-subtype="u" class="mindmap"><div data-type="NodeMindmapItem" data-subtype="u" data-marker="-" class="mindmap-item"><div data-type="NodeParagraph" class="p"><div contenteditable="true">Root</div></div><div data-type="NodeMindmap" data-subtype="u" class="mindmap"><div data-type="NodeMindmapItem" data-subtype="u" data-marker="-" class="mindmap-item"><div data-type="NodeParagraph" class="p"><div contenteditable="true">Child</div></div></div></div></div></div>
Every block needs an explicit data-type. New native DOM blocks may omit data-node-id; the tool generates IDs.
-A horizontal super-block uses {{{col with blank-line-separated child blocks and }}} on its own line; col is horizontal and row is vertical. Raw super-block DOM uses data-type="NodeSuperBlock" and data-sb-layout, never data-layout, and every child needs an explicit data-type. Markdown block references use ((blockID "anchor text")); never [[blockID]].`},
+Raw super-block DOM uses data-type="NodeSuperBlock" and data-sb-layout="row" or data-sb-layout="col", never data-layout, and every child needs an explicit data-type; otherwise content may become an HTML block.
+
+` + markdownContentSyntax},
"dataType": {Type: "string", Description: "Content type: markdown or dom", Enum: []string{"markdown", "dom"}},
"lockType": {Type: "boolean", Description: "Reject update when the parsed block type differs from the existing block type; defaults to true for native Tabs/Mindmap containers and items, false otherwise. Set false only for an intentional type conversion"},
- "parentID": {Type: "string", Description: "Parent block ID"},
+ "parentID": {Type: "string", Description: "Parent container block ID; never a heading or another leaf block. A list-item requires a NodeList parent"},
"nextID": {Type: "string", Description: "Next sibling block ID (for insert)"},
"previousID": {Type: "string", Description: "Previous sibling block ID (for insert)"},
},
diff --git a/kernel/mcp/tools/block_test.go b/kernel/mcp/tools/block_test.go
index aed4afccf4..7e8a073420 100644
--- a/kernel/mcp/tools/block_test.go
+++ b/kernel/mcp/tools/block_test.go
@@ -34,7 +34,13 @@ func TestBlockToolDocumentsSuperBlockSyntax(t *testing.T) {
}
func TestMarkdownToBlockDOMCreatesHorizontalSuperBlock(t *testing.T) {
- dom, err := markdownToBlockDOM("{{{col\n\nfirst paragraph\n\nsecond paragraph\n\n}}}")
+ description := BlockTool.InputSchema.Properties["data"].Description
+ start := strings.Index(description, "{{{col\n")
+ end := strings.Index(description, "\nUse {{{row")
+ if start < 0 || end <= start {
+ t.Fatal("missing super-block Markdown example")
+ }
+ dom, err := markdownToBlockDOM(description[start:end])
if err != nil {
t.Fatal(err)
}
@@ -49,6 +55,18 @@ func TestMarkdownToBlockDOMCreatesHorizontalSuperBlock(t *testing.T) {
}
}
+func TestBlockToolDocumentsPlacement(t *testing.T) {
+ for _, instruction := range []string{
+ "following siblings, not its children", "as previousID, never as parentID",
+ "list-item must have a NodeList parent", "cannot directly contain another list-item",
+ "create a NodeList inside the outer list-item",
+ } {
+ if !strings.Contains(BlockTool.Description, instruction) {
+ t.Fatalf("missing block placement rule %q", instruction)
+ }
+ }
+}
+
func TestBlockWriteSuccess(t *testing.T) {
const id = "20260818000000-abcdefg"
result, err := blockWriteSuccess("append", id)
diff --git a/kernel/mcp/tools/content_syntax.go b/kernel/mcp/tools/content_syntax.go
new file mode 100644
index 0000000000..daa8805dbc
--- /dev/null
+++ b/kernel/mcp/tools/content_syntax.go
@@ -0,0 +1,33 @@
+// Copyright (c) 2020-present, b3log.org
+// Licensed under the GNU Affero General Public License v3.0.
+
+package tools
+
+// markdownContentSyntax 统一各内容写入工具的 Markdown 语法说明。
+const markdownContentSyntax = `SiYuan Markdown syntax:
+- Prefer standard Markdown for ordinary blocks and inline formatting: **bold**, *italic*, ~~strikethrough~~, ==mark==, and backticks for inline code.
+- Block references must include anchor text. Use ((<blockID> "<static anchor text>")) for fixed text, required whenever the anchor text differs from the referenced block's content. Use ((<blockID> '<dynamic anchor text>')) for text that follows the target block's content, only when the anchor text is the target block's own content. Never use ((<blockID>)) or [[<blockID>]]. These forms are for note content; use normal SiYuan links in chat responses.
+
+Super-block Markdown:
+Prefer Markdown for creating super-blocks. Despite the token names, col is horizontal and row is vertical; never infer the visual direction from the English token alone. A horizontal super-block with two paragraphs is:
+{{{col
+
+first paragraph
+
+second paragraph
+
+}}}
+Use {{{row for a vertical super-block. Separate child blocks with blank lines and put }}} on its own line.
+
+Text marks:
+- For color, background, or font size, use a span with a leading data-type="text" attribute. Examples: <span data-type="text" style="color: #ff0000;">red text</span>, <span data-type="text" style="background-color: #ffff00;">highlighted</span>, <span data-type="text" style="font-size: 18px;">larger text</span>, <span data-type="text" style="color: #ff0000; font-size: 18px;">red and large</span>.
+- Combine mark types in data-type, not in CSS: <span data-type="text strong" style="color: #ff0000;">bold red</span>, <span data-type="text em" style="background-color: #ffff00;">italic highlighted</span>.
+- Prefer semantic data-type marks over equivalent CSS: <span data-type="u">underlined</span>, x<span data-type="sup">2</span>, H<span data-type="sub">2</span>O, <span data-type="kbd">Ctrl</span>, <span data-type="tag">todo</span>. These are native editor marks, convertible to/from Markdown and queryable.
+- Never fake marks with CSS such as text-decoration, vertical-align, font-weight, or font-style, or use a bare <kbd>. Never write a bare <span style="..."> without data-type; it renders as escaped literal text. Prefer standard Markdown when no color or size is needed.
+
+Rendered HTML blocks:
+Use a NodeHTMLBlock for rendered HTML, such as ruby annotations or styled containers. In Markdown, start the block with a bare <div opening tag on its own line; wrap other roots (p, table, section, ruby, etc.) in <div>...</div> so the parser recognizes an HTML block instead of an escaped paragraph. Example:
+<div>
+<ruby>你<rt>nǐ</rt></ruby>
+</div>
+Do not use an html code fence for rendered HTML: it creates a NodeCodeBlock that displays source code instead.`
diff --git a/kernel/mcp/tools/content_syntax_test.go b/kernel/mcp/tools/content_syntax_test.go
new file mode 100644
index 0000000000..e0cd4fe296
--- /dev/null
+++ b/kernel/mcp/tools/content_syntax_test.go
@@ -0,0 +1,69 @@
+// Copyright (c) 2020-present, b3log.org
+// Licensed under the GNU Affero General Public License v3.0.
+
+package tools
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestContentToolsShareMarkdownSyntax(t *testing.T) {
+ for _, tc := range []struct {
+ tool *Tool
+ property string
+ }{
+ {BlockTool, "data"}, {DocumentTool, "markdown"}, {DailynoteTool, "data"}, {TemplateTool, "content"},
+ } {
+ description := tc.tool.InputSchema.Properties[tc.property].Description
+ for _, instruction := range []string{
+ `((<blockID> "<static anchor text>"))`, `((<blockID> '<dynamic anchor text>'))`,
+ "required whenever the anchor text differs", "only when the anchor text is the target block's own content",
+ "Never use ((<blockID>)) or [[<blockID>]]", "col is horizontal and row is vertical",
+ `data-type="text strong"`, `data-type="text em"`, `data-type="u"`, `data-type="sup"`,
+ `data-type="sub"`, `data-type="kbd"`, `data-type="tag"`, "Never fake marks with CSS",
+ `Never write a bare <span style="...">`, "wrap other roots", "Do not use an html code fence",
+ } {
+ if !strings.Contains(description, instruction) {
+ t.Fatalf("%s.%s is missing content syntax %q", tc.tool.Name, tc.property, instruction)
+ }
+ }
+ }
+}
+
+func TestDocumentedMarkdownExamplesCreateNativeContent(t *testing.T) {
+ description := BlockTool.InputSchema.Properties["data"].Description
+ for _, tc := range []struct {
+ name, prefix, suffix string
+ markers []string
+ }{
+ {"color", `<span data-type="text" style="color:`, "</span>", []string{`data-type="text"`, "color: #ff0000"}},
+ {"bold_color", `<span data-type="text strong"`, "</span>", []string{"strong", "color: #ff0000"}},
+ {"keyboard", `<span data-type="kbd"`, "</span>", []string{`data-type="kbd"`, "Ctrl"}},
+ {"html", "<div>\n<ruby>", "\n</div>", []string{`data-type="NodeHTMLBlock"`, "&lt;ruby&gt;"}},
+ {"static_reference", `((<blockID> "`, "))", []string{`data-type="block-ref"`, `data-subtype="s"`}},
+ {"dynamic_reference", "((<blockID> '", "))", []string{`data-type="block-ref"`, `data-subtype="d"`}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ start := strings.Index(description, tc.prefix)
+ if start < 0 {
+ t.Fatal("missing content example")
+ }
+ end := strings.Index(description[start:], tc.suffix)
+ if end < 0 {
+ t.Fatal("incomplete content example")
+ }
+ markdown := description[start : start+end+len(tc.suffix)]
+ markdown = strings.ReplaceAll(markdown, "<blockID>", "20261007000000-ref0001")
+ dom, err := markdownToBlockDOM(markdown)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, marker := range tc.markers {
+ if !strings.Contains(dom, marker) {
+ t.Fatalf("example lost native content %q: %s", marker, dom)
+ }
+ }
+ })
+ }
+}
diff --git a/kernel/mcp/tools/dailynote.go b/kernel/mcp/tools/dailynote.go
index 2d596ccbd9..a40e58406b 100644
--- a/kernel/mcp/tools/dailynote.go
+++ b/kernel/mcp/tools/dailynote.go
@@ -31,7 +31,7 @@ var DailynoteTool = &Tool{
Properties: map[string]Property{
"action": {Type: "string", Description: "Operation", Enum: []string{"create", "append", "prepend"}},
"notebook": {Type: "string", Description: "Notebook ID"},
- "data": {Type: "string", Description: "Content in markdown or dom (for append/prepend)"},
+ "data": {Type: "string", Description: "Content in markdown or dom (for append/prepend).\n\n" + markdownContentSyntax},
"dataType": {Type: "string", Description: "Content type: markdown or dom", Enum: []string{"markdown", "dom"}},
},
Required: []string{"action", "notebook"},
diff --git a/kernel/mcp/tools/document.go b/kernel/mcp/tools/document.go
index bbdd3d1c49..8706e7221b 100644
--- a/kernel/mcp/tools/document.go
+++ b/kernel/mcp/tools/document.go
@@ -37,7 +37,7 @@ var DocumentTool = &Tool{
"id": {Type: "string", Description: "Document block ID"},
"title": {Type: "string", Description: "Document title (for create, rename)"},
"path": {Type: "string", Description: "Document hPath, the human-readable path shown in the document tree (e.g. /folder/doc). Used for create, list, move."},
- "markdown": {Type: "string", Description: "Initial markdown content (for create)"},
+ "markdown": {Type: "string", Description: "Initial markdown content (for create).\n\n" + markdownContentSyntax},
"keyword": {Type: "string", Description: "Search keyword (for search_docs)"},
"notebook": {Type: "string", Description: "Notebook ID (required for create, list, move)"},
},
diff --git a/kernel/mcp/tools/template.go b/kernel/mcp/tools/template.go
index a3f8678319..768a4bb8eb 100644
--- a/kernel/mcp/tools/template.go
+++ b/kernel/mcp/tools/template.go
@@ -36,7 +36,7 @@ var TemplateTool = &Tool{
"path": {Type: "string", Description: "Template file path as returned by search (for get, remove, render)"},
"id": {Type: "string", Description: "Block ID (for render, save_as)"},
"name": {Type: "string", Description: "Template name without extension (for save_as, create)"},
- "content": {Type: "string", Description: "Markdown content (for create)"},
+ "content": {Type: "string", Description: "Markdown content (for create).\n\n" + markdownContentSyntax},
"overwrite": {Type: "boolean", Description: "Overwrite if exists (for save_as, create, default false)"},
},
Required: []string{"action"},