Skip to content

Commit d41f78e

Browse files
mandanyaclaude
andcommitted
write_note: replace now keeps page properties (no separate wipe mode)
mode="replace" previously wiped the whole page including its property block, so an agent updating a page's text silently lost page properties (find_tasks scoping and Logseq filtering depend on them). Now replace swaps the content but preserves page properties (captured from the first block, re-applied to the new content). To remove a property, use set_page_properties with a null value — no ambiguous "replace_without_properties" mode. Bump 0.2.1. Smoke-tested live + 46 unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4e96ab6 commit d41f78e

5 files changed

Lines changed: 22 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-server-logseq"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "An MCP server for LogSeq API"
55
readme = "README.md"
66
requires-python = ">=3.11"

src/mcp_server_logseq/guide.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
Passing an already-prefixed subpath is fine (no double prefix). You cannot edit
8181
pages outside `{prefix}/` — an unprefixed subpath is rewritten into it. Content
8282
starting with a task marker is rejected — use `create_task` for tasks.
83+
- `mode`: `append` adds a block; `replace` swaps the page content but **keeps page
84+
properties** (to remove a property use `set_page_properties` with a null value).
85+
write_note appends a block to a page — it never edits one block in place.
8386
"""
8487

8588

src/mcp_server_logseq/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ async def read_block(
381381
async def write_note(
382382
subpath: Annotated[str, Field(description="Page path within the agent namespace")],
383383
content: Annotated[Optional[str], Field(description="Block content to add (markdown)")] = None,
384-
mode: Annotated[str, Field(description="append | replace")] = "append",
384+
mode: Annotated[str, Field(description="append | replace (swaps page content, keeps page properties; remove a property via set_page_properties null)")] = "append",
385385
properties: Annotated[Optional[dict], Field(description="Page properties (set on creation)")] = None,
386386
) -> dict:
387387
"""Create or update a page in the agent's namespace."""

src/mcp_server_logseq/writes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ async def write_note(
7676
client, name, properties, create_first_block=bool(properties)
7777
)
7878

79+
preserved: dict = {}
7980
if mode == "replace" and existed:
8081
tree = await client.call("logseq.Editor.getPageBlocksTree", [name]) or []
82+
# Replace swaps content but keeps page properties (they live on the first
83+
# block); to remove a property, use set_page_properties(..., {prop: null}).
84+
if tree:
85+
preserved = tree[0].get("properties") or {}
8186
for blk in tree:
8287
uuid = blk.get("uuid")
8388
if uuid:
@@ -89,10 +94,21 @@ async def write_note(
8994
if isinstance(block, dict):
9095
appended_uuid = block.get("uuid")
9196

97+
# Re-attach preserved page properties to the new first block (mode="replace").
98+
if preserved:
99+
holder = appended_uuid
100+
if holder is None:
101+
block = await client.call("logseq.Editor.appendBlockInPage", [name, ""])
102+
holder = block.get("uuid") if isinstance(block, dict) else None
103+
if holder:
104+
for key, value in preserved.items():
105+
await client.call("logseq.Editor.upsertBlockProperty", [holder, key, value])
106+
92107
return {
93108
"page": name,
94109
"already_existed": existed,
95110
"appended_uuid": appended_uuid,
111+
"kept_properties": list(preserved.keys()),
96112
}
97113

98114

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)