Skip to main content
Glama

manage_folder

Create, rename, move, or delete folders in Obsidian vaults to organize your knowledge base structure.

Instructions

Create, rename, move, or delete a folder in the Obsidian vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesThe operation to perform: create, rename, move, or delete
pathYesPath to the folder within the vault
newPathNoNew path for the folder (required for rename and move operations)

Implementation Reference

  • src/index.ts:1196-1217 (registration)
    Registration of the 'manage_folder' tool in the listTools handler, including name, description, and input schema definition.
      name: 'manage_folder',
      description: 'Create, rename, move, or delete a folder in the Obsidian vault',
      inputSchema: {
        type: 'object',
        properties: {
          operation: {
            type: 'string',
            description: 'The operation to perform: create, rename, move, or delete',
            enum: ['create', 'rename', 'move', 'delete']
          },
          path: {
            type: 'string',
            description: 'Path to the folder within the vault'
          },
          newPath: {
            type: 'string',
            description: 'New path for the folder (required for rename and move operations)'
          }
        },
        required: ['operation', 'path'],
      },
    },
  • The main handler function that executes the manage_folder tool logic. It handles input validation and dispatches to specific folder operations: create, rename, move, or delete.
    private async handleManageFolder(args: any) {
      if (!args?.operation || !args?.path) {
        throw new Error('Operation and path are required');
      }
      
      const operation = args.operation;
      const folderPath = args.path;
      const newPath = args.newPath;
      
      switch (operation) {
        case 'create':
          await this.createFolder(folderPath);
          return {
            content: [
              {
                type: 'text',
                text: `Folder created successfully at ${folderPath}`,
              },
            ],
          };
        
        case 'rename':
          if (!newPath) {
            throw new Error('New path is required for rename operation');
          }
          await this.renameFolder(folderPath, newPath);
          return {
            content: [
              {
                type: 'text',
                text: `Folder renamed from ${folderPath} to ${newPath}`,
              },
            ],
          };
        
        case 'move':
          if (!newPath) {
            throw new Error('New path is required for move operation');
          }
          await this.moveFolder(folderPath, newPath);
          return {
            content: [
              {
                type: 'text',
                text: `Folder moved from ${folderPath} to ${newPath}`,
              },
            ],
          };
        
        case 'delete':
          await this.deleteFolder(folderPath);
          return {
            content: [
              {
                type: 'text',
                text: `Folder deleted successfully: ${folderPath}`,
              },
            ],
          };
        
        default:
          throw new Error(`Unknown folder operation: ${operation}`);
      }
    }
  • Tool call dispatcher registration where the manage_folder handler is invoked via switch case.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        switch (request.params.name) {
          case 'list_notes':
            return await this.handleListNotes(request.params.arguments);
          case 'read_note':
            return await this.handleReadNote(request.params.arguments);
          case 'create_note':
            return await this.handleCreateNote(request.params.arguments);
          case 'search_vault':
            return await this.handleSearchVault(request.params.arguments);
          case 'delete_note':
            return await this.handleDeleteNote(request.params.arguments);
          case 'move_note':
            return await this.handleMoveNote(request.params.arguments);
          case 'manage_folder':
            return await this.handleManageFolder(request.params.arguments);
          case 'update_note':
            return await this.handleUpdateNote(request.params.arguments);
          case 'read_multiple_notes':
            return await this.handleReadMultipleNotes(request.params.arguments);
          case 'auto_backlink_vault':
            return await this.handleAutoBacklinkVault(request.params.arguments);
          case 'notes_insight':
            return await this.handleNotesInsight(request.params.arguments);
          default:
            throw new McpError(
              ErrorCode.MethodNotFound,
              `Unknown tool: ${request.params.name}`
            );
        }
      } catch (error) {
        console.error(`Error executing tool ${request.params.name}:`, error);
        throw new McpError(
          ErrorCode.InternalError,
          `${error instanceof Error ? error.message : String(error)}`
        );
      }
    });
  • Helper function to create a folder using Obsidian API or filesystem fallback.
    private async createFolder(folderPath: string): Promise<void> {
      try {
        // First try using the Obsidian API
        await this.api.post(`/folders/${encodeURIComponent(folderPath)}`);
      } catch (error) {
        console.warn('API request failed, falling back to file system:', error);
        
        // Fallback to file system if API fails
        const fullPath = path.join(VAULT_PATH, folderPath);
        
        if (!fs.existsSync(fullPath)) {
          fs.mkdirSync(fullPath, { recursive: true });
        }
      }
    }
  • Helper function to delete a folder recursively using API or filesystem.
    private async deleteFolder(folderPath: string): Promise<void> {
      try {
        // First try using the Obsidian API
        await this.api.delete(`/folders/${encodeURIComponent(folderPath)}`);
      } catch (error) {
        console.warn('API request failed, falling back to file system:', error);
        
        // Fallback to file system if API fails
        const fullPath = path.join(VAULT_PATH, folderPath);
        
        if (!fs.existsSync(fullPath)) {
          throw new Error(`Folder not found: ${folderPath}`);
        }
        
        // Recursively delete the folder and its contents
        this.deleteFolderRecursive(fullPath);
      }
    }

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/newtype-01/obsidian-mcp'

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