MCP本地文件读取器
一种模型上下文协议(MCP)服务器,提供全面的文件系统操作,支持多种文档格式。与Claude Desktop和其他MCP兼容的AI工具配合使用。
特性
- 📁 文件系统操作:列出目录、读取文件、获取文件元数据
- 🔍 搜索功能:类似Grep的内容搜索和文件名模式匹配
- 📄 多格式支持:
- PDF文本提取 - Excel(.xlsx、.xls),带有表格列表和每张表格的读数 - Word文档(.docx) - PowerPoint演示文稿(.pptx) - CSV文件 - 具有自动编码检测功能的文本文件(Shift-JIS/UTF-8)
- 🌐 字符编码:自动检测和转换Shift JIS和UTF-8
- 🔒 安全:路径验证,以防止在指定根目录之外访问
安装
使用npx(推荐)
无需安装!只需将Claude Desktop配置为使用npx:
{
"mcpServers": {
"localfile-reader": {
"command": "npx",
"args": [
"-y",
"github:yryuu/mcp-localfile-all-read"
],
"env": {
"MCP_ROOT_PATH": "/path/to/your/directory"
}
}
}
}本地安装
npx github:yryuu/mcp-localfile-all-read配置
克劳德桌面版
编辑您的Claude Desktop配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
添加服务器配置:
{
"mcpServers": {
"localfile-reader": {
"command": "npx",
"args": ["-y", "github:yryuu/mcp-localfile-all-read"],
"env": {
"MCP_ROOT_PATH": "/Users/yourname/Documents"
}
}
}
}或者,如果全局安装:
{
"mcpServers": {
"localfile-reader": {
"command": "mcp-localfile-reader",
"env": {
"MCP_ROOT_PATH": "/Users/yourname/Documents"
}
}
}
}环境变量
MCP_ROOT_PATH:文件访问的根目录(默认为当前工作目录)
Windows示例:
{
"env": {
"MCP_ROOT_PATH": "C:\\Users\\YourName\\Documents"
}
}macOS/Linux示例:
{
"env": {
"MCP_ROOT_PATH": "/Users/yourname/Documents"
}
}备注:在Windows上,使用双反斜杠(\\)或正斜杠(/)在道路上。看 WINDOWS.md 有关Windows兼容性的详细信息。
可用工具
list_directory
列出目录的内容。
参数:
path(string):根目录的相对路径。用“.”表示根。
例子:
List the contents of the current directoryread_file
通过自动格式检测读取文件内容。
参数:
path(string):文件的相对路径。
支持的格式:
- 文本文件(.txt、.md、.json、.xml等)
- PDF(.PDF)
- Excel(.xlsx、.xls)
- Word(.docx)
- PowerPoint(.pptx)
- CSV(.CSV)
例子:
Read the contents of report.pdfget_file_info
获取文件或目录的元数据。
参数:
path(string):文件或目录的相对路径。
例子:
Get information about data.xlsxsearch_content
在文件中搜索文本模式。返回包含该模式的文件路径列表。
参数:
path(string):搜索的相对路径。pattern(string):要搜索的文本模式或正则表达式。max_results(数字):可选。要返回的最大文件数(默认值:1000)。file_pattern(字符串,可选):按名称模式过滤文件。case_sensitive(布尔值,可选):区分大小写的搜索。默认值:false。
例子:
Search for "TODO" in all JavaScript filesfind_files
按名称模式查找文件。
参数:
path(string):搜索的相对路径。name_pattern(string):文件名模式或正则表达式。case_sensitive(布尔值,可选):区分大小写的搜索。默认值:false。
例子:
Find all PDF files in the current directorylist_excel_sheets
列出Excel文件中的所有工作表名称。
参数:
path(string):Excel文件的相对路径。
例子:
List all sheets in budget.xlsxread_excel_sheet
从Excel文件中读取特定工作表。
参数:
path(string):Excel文件的相对路径。sheet_name(string):要读取的工作表的名称。
例子:
Read the "Sales" sheet from budget.xlsx发展
设置
git clone https://github.com/yryuu/mcp-localfile-all-read.git
cd mcp-localfile-all-read
npm install构建
npm run build本地测试
使用MCP检查器测试服务器:
npx @modelcontextprotocol/inspector node dist/index.js或者设置根路径:
MCP_ROOT_PATH=/path/to/test/directory npx @modelcontextprotocol/inspector node dist/index.js用法示例
使用克劳德桌面
配置后,您可以问Claude:
- “列出当前目录中的所有文件”
- “阅读report.pdf的内容”
- “在所有日志文件中搜索'error'”
- “查找所有Excel文件”
- “列出budget.xlsx中的表并阅读销售表”
- “阅读Word文档提案.docx”
编程式用法
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
// The server runs on stdio transport
// See src/index.ts for implementation details文件格式支持详细信息
可移植文档格式
- 从PDF文件中提取所有文本内容
- 处理多页文档
- 用途
pdf-parse图书馆
Excel
- 支持.xlsx和.xls格式
- 列出所有图纸名称
- 阅读特定表格或所有表格
- 以JSON数组形式返回数据
字
- 支持.docx格式
- 提取纯文本内容
- 用途
mammoth图书馆
幻灯片
- 支持.pptx格式
- 从所有幻灯片中提取文本
- 按幻灯片内容返回幻灯片
CSV文件
- 自动分隔符检测
- 字符编码检测(Shift-JIS/UTF-8)
- 返回结构化JSON数据
文本文件
- 自动字符编码检测
- 支持Shift JIS和UTF-8
- 处理各种基于文本的格式
安全
- 路径验证可防止在配置的根目录之外进行访问
- 在文件操作之前,所有路径都会被解析和验证
- 权限问题和无效路径的错误处理
许可证
麻省理工学院
贡献
欢迎投稿!请随时提交拉取请求。
作者
yryuu
仓库
https://github.com/yryuu/mcp-localfile-all-read
