update_block
Modify specific attributes or content of a Mnemosyne knowledge graph block by its ID. Perform surgical edits to update indent, checked status, list type, or replace block content without affecting other elements.
Instructions
Update a block by its ID. Can update attributes (indent, checked, listType) without changing content, or replace the entire block content. This is the most surgical edit - only modifies what you specify.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graph_id | Yes | ||
| document_id | Yes | ||
| block_id | Yes | ||
| attributes | No | ||
| xml_content | No |
Implementation Reference
- The `update_block_tool` async function is the main handler for the MCP 'update_block' tool. It connects to the document via HocuspocusClient, performs updates to block attributes or content using DocumentWriter in a transaction, and returns the updated block info.@server.tool( name="update_block", title="Update Block", description=( "Update a block by its ID. Can update attributes (indent, checked, listType) " "without changing content, or replace the entire block content. " "This is the most surgical edit - only modifies what you specify." ), ) async def update_block_tool( graph_id: str, document_id: str, block_id: str, attributes: Optional[Dict[str, Any]] = None, xml_content: Optional[str] = None, context: Context | None = None, ) -> dict: """Update a block's attributes or content. Args: graph_id: The graph containing the document document_id: The document containing the block block_id: The block to update attributes: Dict of attributes to update (indent, checked, listType, collapsed) xml_content: If provided, replaces the entire block content (preserves block_id) """ auth = MCPAuthContext.from_context(context) auth.require_auth() if not graph_id or not graph_id.strip(): raise ValueError("graph_id is required") if not document_id or not document_id.strip(): raise ValueError("document_id is required") if not block_id or not block_id.strip(): raise ValueError("block_id is required") if attributes is None and xml_content is None: raise ValueError("Either attributes or xml_content must be provided") try: await hp_client.connect_document(graph_id.strip(), document_id.strip()) def perform_update(doc: Any) -> None: writer = DocumentWriter(doc) if xml_content: # Full content replacement (preserves block_id) writer.replace_block_by_id(block_id.strip(), xml_content) if attributes: # Surgical attribute update writer.update_block_attributes(block_id.strip(), attributes) await hp_client.transact_document( graph_id.strip(), document_id.strip(), perform_update, ) # Read back the updated block channel = hp_client.get_document_channel(graph_id.strip(), document_id.strip()) if channel is None: raise RuntimeError(f"Document channel not found: {graph_id}/{document_id}") reader = DocumentReader(channel.doc) block_info = reader.get_block_info(block_id.strip()) result = { "success": True, "graph_id": graph_id.strip(), "document_id": document_id.strip(), "block": block_info, } return result except Exception as e:
- src/neem/mcp/tools/hocuspocus.py:977-1049 (registration)The @server.tool decorator with name="update_block" registers this handler as an MCP tool within the register_hocuspocus_tools function.@server.tool( name="update_block", title="Update Block", description=( "Update a block by its ID. Can update attributes (indent, checked, listType) " "without changing content, or replace the entire block content. " "This is the most surgical edit - only modifies what you specify." ), ) async def update_block_tool( graph_id: str, document_id: str, block_id: str, attributes: Optional[Dict[str, Any]] = None, xml_content: Optional[str] = None, context: Context | None = None, ) -> dict: """Update a block's attributes or content. Args: graph_id: The graph containing the document document_id: The document containing the block block_id: The block to update attributes: Dict of attributes to update (indent, checked, listType, collapsed) xml_content: If provided, replaces the entire block content (preserves block_id) """ auth = MCPAuthContext.from_context(context) auth.require_auth() if not graph_id or not graph_id.strip(): raise ValueError("graph_id is required") if not document_id or not document_id.strip(): raise ValueError("document_id is required") if not block_id or not block_id.strip(): raise ValueError("block_id is required") if attributes is None and xml_content is None: raise ValueError("Either attributes or xml_content must be provided") try: await hp_client.connect_document(graph_id.strip(), document_id.strip()) def perform_update(doc: Any) -> None: writer = DocumentWriter(doc) if xml_content: # Full content replacement (preserves block_id) writer.replace_block_by_id(block_id.strip(), xml_content) if attributes: # Surgical attribute update writer.update_block_attributes(block_id.strip(), attributes) await hp_client.transact_document( graph_id.strip(), document_id.strip(), perform_update, ) # Read back the updated block channel = hp_client.get_document_channel(graph_id.strip(), document_id.strip()) if channel is None: raise RuntimeError(f"Document channel not found: {graph_id}/{document_id}") reader = DocumentReader(channel.doc) block_info = reader.get_block_info(block_id.strip()) result = { "success": True, "graph_id": graph_id.strip(), "document_id": document_id.strip(), "block": block_info, } return result except Exception as e:
- src/neem/mcp/server/standalone_server.py:317-318 (registration)Invocation of register_hocuspocus_tools(mcp_server) during server setup, which triggers the registration of the update_block tool.register_hocuspocus_tools(mcp_server)
- Call to DocumentWriter.update_block_attributes(block_id, attributes), the underlying helper method for attribute updates.writer.update_block_attributes(block_id.strip(), attributes)