Skip to main content
Glama
delete-file.ts1.82 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 File * Registers the tool with the MCP server * @param server MCP server instance */ const registerTool = (server: McpServer) => { server.registerTool( 'delete-file', { title: 'Delete File', description: 'Deletes a file. Parameters: filePath - The path of the file to delete (required);', inputSchema: { filePath: z.string(), } }, async ({ filePath, }) => { try { // Check if the file exists if (!(await fs.pathExists(filePath))) { return { content: [ { type: 'text', text: `Error: File ${filePath} does not exist.` } ], isError: true }; } // Check if it's a file const stats = await fs.stat(filePath); if (!stats.isFile()) { return { content: [ { type: 'text', text: `Error: ${filePath} is a directory, not a file.` } ], isError: true }; } await fs.remove(filePath); return { content: [ { type: 'text', text: `Successfully deleted file: ${filePath}` } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error deleting file: ${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