Zimbra MCP服务器
MCP(模型上下文协议)服务器,用于Zimbra管理电子邮件、标签、日历和联系人。
安装
cd ~/Projets/MCP/zimbra-mcp
# With uv
uv sync
# Or with pip
pip install -e .配置
创建一个 .env 示例中的文件:
cp .env.example .env配置您的Zimbra凭据:
ZIMBRA_URL=https://zimbra.example.com/service/soap
ZIMBRA_USER=me@example.com
ZIMBRA_PASSWORD=your_password
ZIMBRA_TIMEOUT=30
ZIMBRA_ENABLE_SEND=false| 变量 | 描述 | 默认值 |
|---|---|---|
ZIMBRA_URL | Zimbra SOAP端点URL | (必填) |
ZIMBRA_USER | Zimbra帐户电子邮件 | (必填) |
ZIMBRA_PASSWORD | Zimbra帐户密码 | (必填) |
ZIMBRA_TIMEOUT | 请求超时(秒) | 30 |
ZIMBRA_ENABLE_SEND | 启用 send_email 工具(true/1/yes) | false |
用法
启动服务器
uv run zimbra-mcp使用MCP检查员进行测试
mcp dev src/zimbra_mcp/server.py可用工具
电子邮件
| 工具 | 说明 |
|---|---|
search_emails | 使用Zimbra语法搜索(收件箱、发件人、标签等) |
get_email | 按ID全文检索电子邮件 |
download_attachment | 下载本地文件的附件 |
list_folders | 列出所有邮件文件夹 |
search_folder | 按名称或路径搜索文件夹(不区分大小写的部分匹配) |
move_emails | 将电子邮件移动到文件夹 |
mark_as_read | 将电子邮件标记为已读或未读 |
delete_emails | 删除电子邮件(软删除到垃圾箱,或硬删除) |
create_draft | 创建带有可选回复/转发支持的草稿 |
send_email | 直接发送电子邮件(选择加入,需要 ZIMBRA_ENABLE_SEND=true) |
回复和转发草稿
create_draft 和 send_email 支持链接到原始邮件进行回复和转发:
| 参数 | 说明 |
|---|---|
orig_msg_id | 原始消息的ID |
reply_type | "r" 为了回答, "w" for forward |
include_original | "inline" 引用正文, "attachment" 附上as.eml |
示例:
- 简单草稿:
create_draft(to=[...], subject="...", body="...") - 引用回复:
create_draft(to=[...], subject="Re: ...", body="...", orig_msg_id="123", reply_type="r", include_original="inline") - 作为附件转发:
create_draft(to=[...], subject="Fwd: ...", body="...", orig_msg_id="123", reply_type="w", include_original="attachment")
Zimbra搜索语法
基本操作员:
in:inbox-收件箱中的电子邮件from:john@example.com-来自John的电子邮件to:me-发送给我的电子邮件tag:important-带有“重要”标签的电子邮件subject:meeting-主题包含“会议”has:attachment-带附件的电子邮件after:2024-01-01 before:2024-12-31-日期范围(ISO或MM/DD/YYYY)is:unread-未读电子邮件is:flagged-标记的电子邮件
布尔运算符
from:john OR from:mary-来自John或Mary的电子邮件NOT is:read或-is:read-未读电子邮件(排除)(from:john OR from:mary) subject:urgent-分组括号
组合: in:inbox from:boss tag:urgent is:unread
联系人
| 工具 | 说明 |
|---|---|
search_contacts | 搜索联系人(所有字段)。使用 "*" 或全部为空 |
get_contact | 按ID检索联系人 |
create_contact | 创建联系人(姓名、电子邮件、电话、公司等) |
update_contact | 更新现有联系人的特定字段 |
delete_contact | 删除一个或多个联系人 |
标签
| 工具 | 说明 |
|---|---|
list_tags | 列出所有带颜色的标签 |
create_tag | 创建标签(名称、颜色) |
delete_tag | 删除标签 |
add_tag_to_emails | 在电子邮件中添加标签 |
remove_tag_from_emails | 删除标签 |
可选颜色:蓝色、青色、绿色、紫色、红色、黄色、粉色、灰色、橙色
日历
| 工具 | 说明 |
|---|---|
get_calendar_events | 一段时间内的事件 |
get_event_details | 事件的全部细节 |
create_event | 创建事件 |
get_free_busy | 用户可用性 |
发展
运行测试
# Install test dependencies
uv sync --extra test
# Run tests
uv run pytest
# Verbose output
uv run pytest -v测试结构
测试使用 unittest.mock 模拟Zimbra SOAP客户端,因此不需要Zimbra服务器。这 capture_tools 夹具 conftest.py 拦截 @mcp.tool() 装饰器直接访问工具功能。
Claude代码集成
添加到MCP配置(~/.claude/settings.json):
{
"mcpServers": {
"zimbra": {
"command": "uv",
"args": ["run", "--directory", "/home/me/Projets/MCP/zimbra-mcp", "zimbra-mcp"],
"env": {
"ZIMBRA_URL": "https://zimbra.example.com/service/soap",
"ZIMBRA_USER": "me@example.com",
"ZIMBRA_PASSWORD": "your_password"
}
}
}
}项目结构
zimbra-mcp/
├── pyproject.toml
├── README.md
├── CLAUDE.md
├── .env.example
├── src/
│ └── zimbra_mcp/
│ ├── __init__.py
│ ├── server.py # FastMCP entry point
│ ├── config.py # Configuration
│ ├── client.py # Zimbra SOAP client
│ ├── errors.py # Exceptions
│ └── tools/
│ ├── __init__.py
│ ├── emails.py # Email tools
│ ├── tags.py # Tag tools
│ ├── contacts.py # Contact tools
│ └── calendar.py # Calendar tools
└── tests/
├── conftest.py # Shared fixtures
├── test_config.py
├── test_errors.py
├── test_client.py
└── tools/
├── test_emails.py
├── test_tags.py
├── test_contacts.py
└── test_calendar.py