Skip to main content
Glama
alxspiker

MCP Server for FTP Access

list-directory

Retrieve and display the contents of an FTP directory by specifying the remote path using this tool, simplifying FTP server navigation and file management.

Instructions

List contents of an FTP directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesPath of the directory on the FTP server

Implementation Reference

  • Handler function implementing the list-directory tool: calls FTP client to list directory, formats output with sizes and types, returns formatted text response or error.
    async ({ remotePath }) => { try { const listing = await ftpClient.listDirectory(remotePath); // Format the output const formatted = listing.map((item) => `${item.type === "directory" ? "[DIR]" : "[FILE]"} ${item.name} ${item.type === "file" ? `(${formatSize(item.size)})` : ""} - ${item.modifiedDate}` ).join("\n"); const summary = `Total: ${listing.length} items (${listing.filter(i => i.type === "directory").length} directories, ${listing.filter(i => i.type === "file").length} files)`; return { content: [ { type: "text", text: `Directory listing for: ${remotePath}\n\n${formatted}\n\n${summary}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error listing directory: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • Input schema for list-directory tool defining 'remotePath' parameter using Zod.
    { remotePath: z.string().describe("Path of the directory on the FTP server"), },
  • src/index.ts:26-63 (registration)
    Registration of the 'list-directory' tool on the MCP server with name, description, input schema, and handler.
    server.tool( "list-directory", "List contents of an FTP directory", { remotePath: z.string().describe("Path of the directory on the FTP server"), }, async ({ remotePath }) => { try { const listing = await ftpClient.listDirectory(remotePath); // Format the output const formatted = listing.map((item) => `${item.type === "directory" ? "[DIR]" : "[FILE]"} ${item.name} ${item.type === "file" ? `(${formatSize(item.size)})` : ""} - ${item.modifiedDate}` ).join("\n"); const summary = `Total: ${listing.length} items (${listing.filter(i => i.type === "directory").length} directories, ${listing.filter(i => i.type === "file").length} files)`; return { content: [ { type: "text", text: `Directory listing for: ${remotePath}\n\n${formatted}\n\n${summary}` } ] }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error listing directory: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • FtpClient class method that connects to FTP server, lists directory using basic-ftp Client.list(), parses and returns structured file list.
    async listDirectory(remotePath: string): Promise<Array<{name: string, type: string, size: number, modifiedDate: string}>> { try { await this.connect(); const list = await this.client.list(remotePath); await this.disconnect(); return list.map(item => ({ name: item.name, type: item.type === 1 ? "file" : item.type === 2 ? "directory" : "other", size: item.size, modifiedDate: item.modifiedAt ? item.modifiedAt.toISOString() : "" })); } catch (error) { console.error("List directory error:", error); throw new Error(`Failed to list directory: ${error instanceof Error ? error.message : String(error)}`); } }

Other Tools

Related Tools

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/alxspiker/mcp-server-ftp'

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