Back to MCP directory
publicPublicdnsLocal runtime

Local File Reader

一个基于MCP协议的本地文件读取服务器,为AI模型提供安全的本地文件系统访问能力

article

README

🚀 MCP 本地文件阅读器

MCP 本地文件阅读器是一个基于 Model Context Protocol (MCP) 的本地文件读取服务器,它能让 AI 模型安全地访问本地文件系统,为 AI 与本地文件交互提供了便利。

✨ 主要特性

资源(Resources)

  • 可列出并访问本地文件系统中的文件。
  • 支持多种文件类型,涵盖文本文件和二进制文件。
  • 能自动检测文件 MIME 类型,并提供合适的内容处理。

工具(Tools)

  • read_file - 读取指定文件的内容:
    • 对于文本文件,返回完整内容。
    • 对于二进制文件,返回文件信息摘要。
  • list_files - 列出指定目录中的所有文件:
    • 返回文件名列表。
  • get_file_info - 获取指定文件的详细信息:
    • 返回文件大小、类型、创建时间等元数据。

📦 安装指南

npm install mcp-local-file-reader

💻 使用示例

作为命令行工具

安装后,可直接在命令行中运行:

npx mcp-local-file-reader

此时会启动一个 MCP 节点服务器,监听 LLM 对话。

与 AI 工具集成

在 Windsurf 中使用

在 Windsurf 中,无需手动启动 mcp-local-file-reader,只需进行配置,Windsurf 会自动启动它(在 Windsurf 的 mcp_config.json 中配置,点击 refresh 刷新服务器)。

  1. 在 Windsurf 的 mcp_config.json 配置文件中添加以下配置(暂时不需要 FILE_TOOLS_API_KEY):
    • 本地部署
{
  "servers": {
    "file-tools": {
      "command": "cmd",
      "args": [
        "/c",
        "node",
        "path/to/mcp-local-file-reader/build/index.js"
      ],
      "env": {
        "FILE_TOOLS_API_KEY": ""
      }
    }
  }
}
- **使用 npm 部署**
{
  "servers": {
    "file-tools": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "mcp-local-file-reader"
      ],
      "env": {
        "FILE_TOOLS_API_KEY": ""
      }
    }
  }
}

点击 Windsurf 对话框中的锤子图标,然后点击 refresh 刷新服务器。 官方配置说明:https://docs.codeium.com/windsurf/mcp 2. 重启 Windsurf 以加载新的 MCP 配置。

在其他 MCP 兼容的 AI 应用中使用

按照特定应用的 MCP 集成指南,添加此服务器作为工具提供者。在 cursor 的配置与 Windsurf 中的配置类似,在 VSCode 中可能会稍微复杂一些。但本质上都是配置 mcp.json,可以参考类似的配置。

🔧 技术细节

开发

  • 安装依赖:
npm install
  • 构建服务器:
npm run build
  • 开发模式(自动重新构建):
npm run watch
  • 使用 MCP Inspector 测试:
npm run inspector

📄 许可证

本项目采用 MIT 许可证。

⚠️ 重要提示

此服务器允许 AI 模型访问本地文件系统,请谨慎使用并确保:

  1. 只允许访问必要的目录。
  2. 不要暴露敏感文件或目录。
  3. 在生产环境中使用前,考虑添加额外的安全限制。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client