项目简介

FTP MCP Server 是一个基于 Model Context Protocol (MCP) 构建的服务器,旨在为大型语言模型(LLM)客户端提供访问和管理 FTP 服务器上文件的能力。通过此服务器,LLM 可以执行诸如列出目录、下载和上传文件、创建和删除目录/文件等操作,从而扩展 LLM 在数据访问和处理方面的能力。

主要功能点

  • 目录列表: 获取 FTP 服务器指定目录下的文件和文件夹列表。
  • 文件下载: 从 FTP 服务器下载文件到本地,并以文本形式提供给 LLM 客户端。
  • 文件上传: 将文本内容上传到 FTP 服务器,创建或更新文件。
  • 创建目录: 在 FTP 服务器上创建新的文件夹。
  • 删除文件/目录: 从 FTP 服务器删除指定的文件或文件夹。

安装步骤

  1. 安装 Node.js: 确保你的系统已安装 Node.js 16 或更高版本。
  2. 克隆仓库: 使用 Git 克隆 'mcp-server-ftp' 仓库到本地:
    git clone https://github.com/alxspiker/mcp-server-ftp.git
    cd mcp-server-ftp
  3. 安装依赖: 在仓库目录下运行以下命令安装项目依赖:
    npm install
  4. 构建项目: 运行以下命令构建项目:
    npm run build
    对于 Windows 系统,可以使用 'build-windows.bat' 脚本:
    build-windows.bat

服务器配置

要将 FTP MCP Server 集成到 MCP 客户端(例如 Claude for Desktop),需要配置客户端的 MCP 服务器列表。以下是配置示例,以 'claude_desktop_config.json' 文件为例:

MacOS/Linux 平台: 编辑 '~/Library/Application Support/Claude/claude_desktop_config.json' 文件,在 'mcpServers' 字段下添加如下配置:

{
  "mcpServers": {
    "ftp-server": {  // 服务器名称,可以自定义
      "command": "node",  // 启动服务器的命令,这里使用 Node.js 解释器
      "args": ["/absolute/path/to/mcp-server-ftp/build/index.js"], // 启动命令的参数,指向构建后的 index.js 文件,请替换为实际路径
      "env": {  // 环境变量配置,用于FTP连接
        "FTP_HOST": "ftp.example.com",  // FTP 服务器地址,请替换为你的 FTP 服务器地址
        "FTP_PORT": "21",  // FTP 服务器端口,默认为 21
        "FTP_USER": "your-username",  // FTP 用户名,请替换为你的 FTP 用户名
        "FTP_PASSWORD": "your-password",  // FTP 密码,请替换为你的 FTP 密码
        "FTP_SECURE": "false"  // 是否使用 FTPS 安全连接,默认为 false,如果你的 FTP 服务器支持 FTPS,可以设置为 "true"
      }
    }
  }
}

Windows 平台: 编辑 '%APPDATA%\Claude\claude_desktop_config.json' 文件,配置方式与 MacOS/Linux 类似,注意路径格式:

{
  "mcpServers": {
    "ftp-server": {
      "command": "node",
      "args": ["C:\\path\\to\\mcp-server-ftp\\build\\index.js"], // 请替换为实际路径,注意 Windows 路径格式
      "env": {
        "FTP_HOST": "ftp.example.com",
        "FTP_PORT": "21",
        "FTP_USER": "your-username",
        "FTP_PASSWORD": "your-password",
        "FTP_SECURE": "false"
      }
    }
  }
}

注意:

  • 请将 '/absolute/path/to/mcp-server-ftp/build/index.js' 或 'C:\path\to\mcp-server-ftp\build\index.js' 替换为 'mcp-server-ftp' 项目构建后 'build/index.js' 文件的 绝对路径
  • 请根据你的 FTP 服务器信息,修改 'env' 字段下的 'FTP_HOST', 'FTP_PORT', 'FTP_USER', 'FTP_PASSWORD' 和 'FTP_SECURE' 环境变量。
  • 配置完成后,重启 MCP 客户端 (如 Claude for Desktop) 使配置生效。

基本使用方法

配置并启动 FTP MCP Server 后,在 MCP 客户端中,你可以使用自然语言指令来调用 FTP 工具。例如,在 Claude for Desktop 中,你可以尝试以下指令:

  • 列出 FTP 服务器 '/public' 目录下的文件: 'List the files in the /public directory on my FTP server'
  • 下载 FTP 服务器上的 '/data/report.txt' 文件: 'Download the file /data/report.txt from the FTP server'
  • 上传文本 "Hello FTP Server" 并保存为 '/notes.txt' 文件: 'Upload this text as a file called notes.txt to the FTP server'
  • 在 FTP 服务器上创建名为 'backups' 的新目录: 'Create a new directory called 'backups' on the FTP server'
  • 删除 FTP 服务器上的 'obsolete.txt' 文件: 'Delete the file obsolete.txt from the FTP server'
  • 删除 FTP 服务器上的空目录 '/old-project': 'Remove the empty directory /old-project from the FTP server'

客户端会将这些自然语言指令转换为对 FTP MCP Server 中工具的调用,从而实现 FTP 文件管理功能。

信息

分类

数据库与文件