delete-file
Remove files directly from an FTP server by specifying the remote file path. Simplifies file management for users accessing FTP systems.
Instructions
Delete a file from the FTP server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| remotePath | Yes | Path of the file to delete |
Implementation Reference
- src/index.ts:172-194 (handler)Handler function that executes the delete-file tool logic: calls ftpClient.deleteFile(remotePath), handles errors, and returns formatted text response.async ({ remotePath }) => { try { await ftpClient.deleteFile(remotePath); return { content: [ { type: "text", text: `File successfully deleted from ${remotePath}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error deleting file: ${error instanceof Error ? error.message : String(error)}` } ] }; }
- src/index.ts:169-171 (schema)Input schema definition for the delete-file tool using Zod (z.string for remotePath).{ remotePath: z.string().describe("Path of the file to delete"), },
- src/index.ts:166-196 (registration)Registration of the 'delete-file' tool on the MCP server using server.tool(name, description, schema, handler).server.tool( "delete-file", "Delete a file from the FTP server", { remotePath: z.string().describe("Path of the file to delete"), }, async ({ remotePath }) => { try { await ftpClient.deleteFile(remotePath); return { content: [ { type: "text", text: `File successfully deleted from ${remotePath}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error deleting file: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
- src/ftp-client.ts:131-141 (helper)Supporting method in FtpClient class that connects to FTP, calls client.remove(remotePath) from basic-ftp, and handles deletion errors.async deleteFile(remotePath: string): Promise<boolean> { try { await this.connect(); await this.client.remove(remotePath); await this.disconnect(); return true; } catch (error) { console.error("Delete file error:", error); throw new Error(`Failed to delete file: ${error instanceof Error ? error.message : String(error)}`); } }