Skip to main content
Glama
thekogit
by thekogit

File Writer MCP 服务器

这是一个 Node.js 实现的模型上下文协议 (MCP) 服务器,旨在 LM Studio 和其他兼容 MCP 的环境中实现无缝文件操作。该服务器为大语言模型提供了一个强大的接口,用于创建、追加和管理多种格式的文件,包括纯文本、Markdown、CSV 和 Microsoft Excel (XLSX)。

功能特性

  • 多格式支持:处理 .txt、.md、.csv 和 .xlsx 文件的格式转换。

  • 结构化数据处理:接受 JSON 对象形式的表格数据,并自动将其转换为所需格式。

  • 灵活的写入模式

    • 追加(默认):将新数据添加到现有文件的末尾。

    • 覆盖:用新内容替换现有文件。

    • 编号备份:通过创建递增版本(例如 file.1.csv)来保留现有数据。

  • 安全优先:将所有文件操作限制在用户指定的根目录下,以防止未经授权的路径遍历。

  • Excel 集成:利用 ExcelJS 实现二进制电子表格文件的高保真生成。

Related MCP server: Excel MCP Server

安装

前置要求

  • Node.js (v18 或更高版本)

  • npm

设置

  1. 克隆仓库或将源文件复制到本地机器。

  2. 安装所需的依赖项:

    npm install
  3. 构建项目:

    npm run build

LM Studio 配置

要在 LM Studio 中使用此服务器,请将其添加到 MCP 设置中,配置如下:

{
  "mcpServers": {
    "file-writer": {
      "command": "node",
      "args": [
        "C:/Users/szpon/file_writer_mcp/dist/index.js",
        "--root",
        "C:/your/default/directory"
      ]
    }
  }
}

参数

  • --root <path>:(必需)相对文件操作的默认目录的绝对路径。

  • --overwrite:(可选/旧版)为兼容旧配置而提供;现已弃用,改用工具选择。

  • --backup:(可选/旧版)为兼容旧配置而提供;现已弃用,改用工具选择。

工具使用

该服务器提供了三种不同的工具,让您可以直接从 LM Studio 侧边栏清晰地控制文件处理:

  1. write_file:用于标准操作。它将数据追加到现有文件,如果文件不存在则创建它。

  2. write_file_overwrite:用于完全用新数据替换现有文件。

  3. write_file_backup:用于在保存数据的同时保留原始文件。如果文件已存在,它会创建一个编号备份(例如 data.1.csv)。

工具参数

  • path (string):文件名或完整绝对路径。如果提供相对路径,它将相对于 --root 目录进行解析。如果提供绝对路径,服务器将直接写入该位置。

  • format (string):所需的文件扩展名(txtmdcsvxlsx)。

  • data (object):

    • headers (string[]):表格格式的列名。

    • rows (any[][]):要写入的数据集。

    • content (string, 可选):.txt 文件的纯文本内容。

开发

运行测试

该项目使用 Vitest 进行单元测试。要执行测试套件:

npm test

构建

将 TypeScript 源码编译到分发目录:

npm run build

许可证

本项目按“原样”提供,用于与 LM Studio 和其他 MCP 客户端集成。

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    D
    maintenance
    Enables secure filesystem operations with directory sandboxing and optional read-only mode. Supports file reading/writing, directory management, file searching, and text operations while restricting access to specified directories.
    12
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to read, write, and manipulate Excel files through comprehensive spreadsheet operations. Supports file management, data querying, worksheet operations, formula calculations, and includes security features like path validation and automatic backups.
    2
    MIT