Skip to main content
Glama
alxspiker

MCP Server for FTP Access

list-directory

List files and directories on an FTP server by specifying the remote path to browse server contents.

Instructions

List contents of an FTP directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesPath of the directory on the FTP server

Implementation Reference

  • The MCP tool handler function for 'list-directory'. It uses ftpClient.listDirectory to fetch the listing, formats it with file types, sizes, dates, adds a summary, and returns formatted text content 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 the list-directory tool using Zod, defining the 'remotePath' parameter.
    {
      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 McpServer instance, including name, description, 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.listDirectory method: connects to FTP, lists directory using basic-ftp client, maps to structured output with name, type, size, modifiedDate.
    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)}`);
      }
    }
  • Utility function to format file sizes in human-readable form (B, KB, MB, GB), used in the tool handler output.
    function formatSize(bytes: number): string {
      if (bytes < 1024) return bytes + " B";
      else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
      else if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + " MB";
      else return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB";
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a read-only operation by using 'List,' but doesn't disclose critical traits like error handling (e.g., what happens if the path doesn't exist), authentication requirements, rate limits, or output format (e.g., list of filenames vs. detailed metadata). This leaves significant gaps for safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('List contents of an FTP directory') with zero wasted words. It's appropriately sized for a simple tool with one parameter and no complex behaviors, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (1 parameter, no output schema, no annotations), the description is incomplete. It lacks details on output (what 'contents' includes), error cases, and usage context relative to siblings. While concise, it doesn't provide enough information for an agent to use the tool confidently without trial and error, especially with no annotations to fill gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'remotePath' fully documented in the schema as 'Path of the directory on the FTP server.' The description adds no additional meaning beyond this, such as path format examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but doesn't need to.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List contents') and target resource ('an FTP directory'), making the purpose immediately understandable. It distinguishes from siblings like 'download-file' or 'create-directory' by focusing on listing rather than file manipulation. However, it doesn't specify what information is listed (e.g., files, subdirectories, metadata), keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing directory), exclusions (e.g., not for listing files in a non-directory path), or relationships to siblings like 'download-file' for retrieving specific files. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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