Skip to main content
Glama

rename_folder

Change the display label of a folder in Mnemosyne knowledge graphs to update organization and improve clarity.

Instructions

Rename a folder's display label.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
graph_idYes
folder_idYes
new_labelYes

Implementation Reference

  • The complete implementation of the 'rename_folder' tool, including registration decorator and handler function. It authenticates, validates inputs, verifies the folder exists, updates the folder name using a Y.js workspace transaction via HocuspocusClient, and returns the updated workspace snapshot.
    @server.tool(
        name="rename_folder",
        title="Rename Folder",
        description="Rename a folder's display label.",
    )
    async def rename_folder_tool(
        graph_id: str,
        folder_id: str,
        new_label: str,
        context: Context | None = None,
    ) -> dict:
        """Rename a folder via Y.js."""
        auth = MCPAuthContext.from_context(context)
        auth.require_auth()
    
        if not graph_id or not graph_id.strip():
            raise ValueError("graph_id is required and cannot be empty")
        if not folder_id or not folder_id.strip():
            raise ValueError("folder_id is required and cannot be empty")
        if not new_label or not new_label.strip():
            raise ValueError("new_label is required and cannot be empty")
    
        try:
            await hp_client.connect_workspace(graph_id.strip())
    
            # Verify folder exists
            channel = hp_client._workspace_channels.get(graph_id.strip())
            if channel is None:
                raise RuntimeError(f"Workspace not connected: {graph_id}")
    
            reader = WorkspaceReader(channel.doc)
            current = reader.get_folder(folder_id.strip())
    
            if not current:
                raise RuntimeError(f"Folder '{folder_id}' not found in graph '{graph_id}'")
    
            # Update folder name via Y.js
            await hp_client.transact_workspace(
                graph_id.strip(),
                lambda doc: WorkspaceWriter(doc).update_folder(
                    folder_id.strip(),
                    name=new_label.strip(),
                ),
            )
    
            snapshot = hp_client.get_workspace_snapshot(graph_id.strip())
    
            result = {
                "success": True,
                "folder_id": folder_id.strip(),
                "graph_id": graph_id.strip(),
                "new_label": new_label.strip(),
                "workspace": snapshot,
            }
            return result
    
        except Exception as e:
            logger.error(
                "Failed to rename folder",
                extra_context={
                    "graph_id": graph_id,
                    "folder_id": folder_id,
                    "error": str(e),
                },
            )
            raise RuntimeError(f"Failed to rename folder: {e}")
  • The call to register_hocuspocus_tools which registers the rename_folder tool (among others) on the MCP server instance.
    register_hocuspocus_tools(mcp_server)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sophia-labs/mnemosyne-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server