MCP文件内容读取器
用于读取和分析各种文件格式的模型上下文协议(MCP)服务器,包括 PDF、Excel、Word和PowerPoint文档.
特性
- 多格式支持:阅读PDF、Excel(.xlsx、.xls)、Word(.docx、.doc)和PowerPoint(.pptx、.ppt)文件
- 内容分析:使用结构化信息提取提取和分析文件内容
- 文档搜索:在多个文档中搜索特定内容
- 文件上传:支持临时文件上传和处理
- MCP集成:完全符合模型上下文协议
安装
使用uvx(推荐)
uvx mcp-file-contents-reader使用pip
pip install mcp-file-contents-reader来源
git clone https://github.com/yourusername/mcp-file-contents-reader.git
cd mcp-file-contents-reader
pip install -e .用法
MCP配置
将以下内容添加到您的 mcp.json 配置文件:
{
"mcpServers": {
"file-reader": {
"command": "uvx",
"args": ["mcp-file-contents-reader"]
}
}
}或者,如果通过pip安装:
{
"mcpServers": {
"file-reader": {
"command": "mcp-file-contents-reader"
}
}
}可用工具
1. read_file
阅读Excel、PDF、PPT、Word文件,并以文本形式返回内容。
参数:
file_path(必填):要读取的文件的路径sheet_name(可选):Excel文件的工作表名称page_range(可选):PDF文件的页面范围(例如“1-5”或“1,3,5”)
2. search_documents
在Documents目录中搜索特定内容并分析文件。
参数:
keywords(必填):要在文件内容中搜索的关键字search_path(可选):要搜索的目录路径(默认:~/Documents)file_types(可选):要搜索的文件类型(默认值:\[“pdf”、“docx”、“xlsx”、”pptx“、”doc“、”xls“、”ppt“\])
3. analyze_file_content
详细分析具体文件内容,提取结构化信息。
参数:
file_path(必填):要分析的文件的路径extract_patterns(可选):要提取的特定模式或信息类型
4. upload_file
上传并临时存储Base64编码的文件数据。
参数:
file_data(必需):Base64编码文件数据filename(必填):带扩展名的文件名
5. read_uploaded_file
读取上传的文件并返回内容。
参数:
file_id(必填):上传文件的ID
6. list_uploaded_files
返回已上传文件的列表。
7. delete_uploaded_file
删除上传的文件。
参数:
file_id(必填):要删除的文件的ID
8. get_file_info
返回文件的基本信息。
参数:
file_path(必填):获取有关信息的文件路径
9. list_supported_formats
返回支持的文件格式列表。
支持的文件格式
- Excel:.xlsx、.xls
- 可移植文档格式:.pdf
- 幻灯片.pptx、.ppt
- 字.docx,.doc
示例用法
搜索捐款收据
{
"tool": "search_documents",
"arguments": {
"keywords": ["donation", "receipt", "charity", "fund"],
"search_path": "/Users/username/Documents",
"file_types": ["pdf", "docx", "xlsx"]
}
}分析特定文件
{
"tool": "analyze_file_content",
"arguments": {
"file_path": "/Users/username/Documents/receipt.pdf",
"extract_patterns": ["donor", "amount", "organization", "date"]
}
}发展
设置开发环境
git clone https://github.com/yourusername/mcp-file-contents-reader.git
cd mcp-file-contents-reader
pip install -e ".[dev]"运行测试
pytest代码格式化
black mcp_file_reader/类型检查
mypy mcp_file_reader/贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 为您的更改添加测试
- 运行测试套件
- 提交拉取请求
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
更新日志
1.0.0
- 初始版本
- 支持PDF、Excel、Word和PowerPoint文件
- MCP服务器实现
- 文档搜索和分析功能
