Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/mcp_logseq/logseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,28 @@ def update_page(self, page_name: str, content: str = None, properties: dict = No
except Exception as e:
logger.error(f"Error updating page '{page_name}': {str(e)}")
raise

def delete_block(self, block_uuid: str) -> Any:
"""Delete a LogSeq block by UUID."""
url = self.get_base_url()
logger.info(f"Deleting block '{block_uuid}'")

try:
response = requests.post(
url,
headers=self._get_headers(),
json={
"method": "logseq.Editor.removeBlock",
"args": [block_uuid]
},
verify=self.verify_ssl,
timeout=self.timeout
)
response.raise_for_status()
result = response.json()
logger.info(f"Successfully deleted block '{block_uuid}'")
return result

except Exception as e:
logger.error(f"Error deleting block '{block_uuid}': {str(e)}")
raise
1 change: 1 addition & 0 deletions src/mcp_logseq/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get_tool_handler(name: str) -> tools.ToolHandler | None:
add_tool_handler(tools.ListPagesToolHandler())
add_tool_handler(tools.GetPageContentToolHandler())
add_tool_handler(tools.DeletePageToolHandler())
add_tool_handler(tools.DeleteBlockToolHandler())
add_tool_handler(tools.UpdatePageToolHandler())
add_tool_handler(tools.SearchToolHandler())
logger.info("Tool handlers registration complete")
Expand Down
41 changes: 41 additions & 0 deletions src/mcp_logseq/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,47 @@ def run_tool(self, args: dict) -> list[TextContent]:
text=f"❌ Failed to update page '{page_name}': {str(e)}"
)]

class DeleteBlockToolHandler(ToolHandler):
def __init__(self):
super().__init__("delete_block")

def get_tool_description(self):
return Tool(
name=self.name,
description="Delete a block from LogSeq by its UUID.",
inputSchema={
"type": "object",
"properties": {
"block_uuid": {
"type": "string",
"description": "UUID of the block to delete"
}
},
"required": ["block_uuid"]
}
)

def run_tool(self, args: dict) -> list[TextContent]:
if "block_uuid" not in args:
raise RuntimeError("block_uuid argument required")

block_uuid = args["block_uuid"]

try:
api = logseq.LogSeq(api_key=api_key)
api.delete_block(block_uuid)

return [TextContent(
type="text",
text=f"Successfully deleted block '{block_uuid}'"
)]
except Exception as e:
logger.error(f"Failed to delete block: {str(e)}")
return [TextContent(
type="text",
text=f"Failed to delete block '{block_uuid}': {str(e)}"
)]

class SearchToolHandler(ToolHandler):
def __init__(self):
super().__init__("search")
Expand Down