这是一个使用Python开发的MCP(模型上下文协议)服务器项目,专注于发票和收据处理工具集。该项目利用OCR技术实现发票识别、数据提取和PDF处理功能,为AI助手提供发票处理能力。
pip install uv
git clone https://github.com/[username]/mcp-invoice.git
cd mcp-invoice
uv venv
source .venv/bin/activate
uv pip install -e .
Pdf2image需要在系统上安装Poppler:
brew install poppler
有两种方式部署MCP服务:
# 标准模式
mcp-invoice
# 或启用调试模式(包含文本位置信息)
MCP_INVOICE_DEBUG=true mcp-invoice
# 标准模式
python invoice_server.py
# 或启用调试模式
M
MCP_INVOICE_DEBUG=true python invoice_server.py
可以将MCP服务配置为系统服务,以便在系统启动时自动运行:
mkdir -p ~/Library/LaunchAgents
cat > ~/Library/LaunchAgents/com.user.mcp-invoice.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.mcp-invoice</string>
<key>ProgramArguments</key>
<array>
<string>$(which python)</string>
<string>$(pwd)/invoice_server.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$(pwd)/logs/mcp-invoice.log</string>
<key>StandardErrorPath</key>
<string>
$(pwd)/logs/mcp-invoice-error.log</string>
<key>WorkingDirectory</key>
<string>$(pwd)</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
</dict>
</plist>
EOF
# 创建日志目录
mkdir -p logs
# 加载服务
launchctl load ~/Library/LaunchAgents/com.user.mcp-invoice.plist
launchctl start com.user.mcp-invoice
launchctl stop com.user.mcp-invoice
在光标编辑器中,可以通过以下配置添加MCP发票服务:
打开光标编辑器的MCP配置文件:
$HOME/Library/Application Support/Cursor/tools/tools.json$HOME/.config/Cursor/tools/tools.json%APPDATA%\Cursor\tools\tools.json在tools.json文件中添加MCP发票服务配置:
{
"tools": {
"invoice": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp-invoice",
"run",
"invoice_server.py"
],
"env": {
"MCP_INVOICE_DEBUG": "false"
},
"alwaysAllow": [
"process_file",
"process_directory",
"merge_pdfs"
]
}
}
}
Cline与MCP的集成方法类似于光标:
在Roocode中集成MCP发票服务:
MCP_INVOICE_DEBUG=true mcp-invoice
ps aux | grep mcp-invoice
tail -f logs/mcp-invoice.log
MCP服务器提供了以下主要工具:
process_file处理单个文件并提取文本
file_path - 文件的绝对路径process_directory处理目录中的所有PDF和图像文件
directory_path - 目录的绝对路径merge_pdfs将多个PDF和/或图像文件合并成一个PDF
file_paths - 要合并的文件路径列表output_path - 输出PDF的路径此项目使用UV进行依赖管理和Hatch进行构建。
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
Vision框架错误
UTF-8编码问题
PDF转换错误