Skip to main content
Glama
delete-dir.ts2.08 kB
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z } from 'zod'; import fs from 'fs-extra'; import * as path from 'path'; /** * Tool: Delete Directory * Registers the tool with the MCP server * @param server MCP server instance */ const registerTool = (server: McpServer) => { server.registerTool( 'delete-dir', { title: 'Delete Directory', description: 'Deletes a directory. Parameters: dirPath - The path of the directory to delete (required); recursive - Whether to delete the directory and its contents recursively (optional, default: true);', inputSchema: { dirPath: z.string(), recursive: z.boolean().optional(), } }, async ({ dirPath, recursive = true, }) => { try { // Check if the directory exists if (!(await fs.pathExists(dirPath))) { return { content: [ { type: 'text', text: `Error: Directory ${dirPath} does not exist.` } ], isError: true }; } if (!recursive) { const files = await fs.readdir(dirPath); if (files.length > 0) { return { content: [ { type: 'text', text: `Error: Directory ${dirPath} is not empty. Use recursive: true to delete it.` } ], isError: true }; } } await fs.remove(dirPath); return { content: [ { type: 'text', text: `Successfully deleted directory: ${dirPath}` } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error deleting directory: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } ); }; export default registerTool;

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/Yussefgafer/MyMCP'

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