AliMail Admin MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AliMail Admin MCP show me the full department tree for our company domain"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
alimail-admin-mcp
基于阿里邮箱开放平台 API 的 MCP(Model Context Protocol)服务。在 Claude、VS Code Copilot、Cursor 等 AI 客户端里,用自然语言管理企业邮箱的用户和部门。
⚠️ 本项目为非官方实现,与阿里云 / 阿里邮箱无隶属关系。它使用的应用凭证具有企业邮箱管理员级别的权限,请在充分理解风险后使用。
特性
27 个工具,分为
users、departments两个工具集:账号增删改查、别名、重置密码、邮箱设置、共享成员、安全手机、撤销登录态;部门增删改查、层级链,以及可递归获取整棵部门树的组合工具默认只读:
ALIMAIL_READ_ONLY=true时只注册 11 个查询工具破坏性操作需两步确认:先返回预览和一次性
confirmToken,确认后才执行域名范围限制:
ALIMAIL_ALLOWED_DOMAINS可限定只能操作指定域名下的账号审计日志:所有写操作都记录为 JSON 行,密码、token 等敏感字段自动脱敏
稳健的 API 客户端:token 缓存并提前刷新;令牌桶限流;
429/5xx自动退避重试,非幂等写操作不盲目重试;错误统一格式化并附带修复提示两种传输方式:stdio(默认)与 Streamable HTTP(
--http)Resources:
alimail://departments/tree、alimail://users/{email};Prompts:onboard_employee(入职)、offboard_employee(离职)
Related MCP server: proofpoint-essentials-mcp
准备工作:创建阿里邮箱应用
以管理员身份登录阿里邮箱域管后台,进入 高级应用 → API 开放平台(或“应用管理”),创建应用。
按最小权限原则授予用户、部门相关的 API 权限。只读场景只授读权限;需要写操作再授读写权限。权限名称以后台实际列出的为准。
记录应用的
client_id与client_secret。确认企业所在集群的 API 地址(默认
https://alimail-cn.aliyuncs.com)。
免费版阿里邮箱不支持 API 开放平台。单个域内所有应用的 API 调用合计不能超过 40 次/秒。
配置
所有配置都通过环境变量提供(可参考 .env.example):
变量 | 默认值 | 说明 |
| — | 必填,应用 ID |
| — | 必填,应用 Secret |
|
| API 地址,不同集群不能混用 |
|
| 设为 |
|
| 启用的工具集 |
| 空(不限制) | 限定可操作的邮箱域名,逗号分隔,子域名同样适用 |
|
| 本服务的请求速率上限(最大 40),需要给同域的其他应用留出余量 |
|
| 单次请求超时 |
| 空(输出到 stderr) | 审计日志文件路径 |
|
| HTTP 监听地址 |
|
| HTTP 端口 |
| 空 | HTTP 模式下可选:设置后请求必须带 |
|
| 允许的 Host 头,用于防御 DNS rebinding |
|
|
|
运行
方式一:从源码运行
npm ci
npm run build
ALIMAIL_CLIENT_ID=xxx ALIMAIL_CLIENT_SECRET=yyy node dist/index.js --check # 验证凭证(只换取 token,不调用业务接口)
ALIMAIL_CLIENT_ID=xxx ALIMAIL_CLIENT_SECRET=yyy node dist/index.js --list-tools命令行参数:--http、--host、--port、--check、--list-tools、--version、--help。
方式二:Docker(本地构建)
docker build -t alimail-admin-mcp:local .
# 验证凭证
docker run --rm -e ALIMAIL_CLIENT_ID=xxx -e ALIMAIL_CLIENT_SECRET=yyy alimail-admin-mcp:local --checkstdio 模式:由 MCP 客户端负责拉起容器,必须带 -i:
docker run -i --rm -e ALIMAIL_CLIENT_ID -e ALIMAIL_CLIENT_SECRET alimail-admin-mcp:localHTTP 模式:作为常驻服务运行:
cp .env.example .env # 填入凭证
docker compose up -d --build
curl http://localhost:3000/healthzdocker-compose.yml 默认只把端口发布在 127.0.0.1 上,MCP 地址为 http://localhost:3000/mcp。
客户端配置
VS Code(.vscode/mcp.json)
使用 inputs 在运行时输入密钥,避免把密钥写进配置文件:
{
"inputs": [
{ "id": "alimail-id", "type": "promptString", "description": "AliMail Client ID" },
{ "id": "alimail-secret", "type": "promptString", "description": "AliMail Client Secret", "password": true }
],
"servers": {
"alimail-admin": {
"type": "stdio",
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "ALIMAIL_CLIENT_ID", "-e", "ALIMAIL_CLIENT_SECRET", "-e", "ALIMAIL_READ_ONLY", "alimail-admin-mcp:local"],
"env": {
"ALIMAIL_CLIENT_ID": "${input:alimail-id}",
"ALIMAIL_CLIENT_SECRET": "${input:alimail-secret}",
"ALIMAIL_READ_ONLY": "true"
}
}
}
}如果不用 Docker,把 command/args 换成 "command": "node", "args": ["/绝对路径/alimail-admin-mcp/dist/index.js"]。
连接 HTTP 模式的服务:
{
"servers": {
"alimail-admin": { "type": "http", "url": "http://localhost:3000/mcp" }
}
}Claude Desktop / Cursor / Cline
{
"mcpServers": {
"alimail-admin": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "ALIMAIL_CLIENT_ID", "-e", "ALIMAIL_CLIENT_SECRET", "-e", "ALIMAIL_READ_ONLY", "alimail-admin-mcp:local"],
"env": {
"ALIMAIL_CLIENT_ID": "xxx",
"ALIMAIL_CLIENT_SECRET": "yyy",
"ALIMAIL_READ_ONLY": "true"
}
}
}
}工具一览
✏️ 表示写操作(仅在 ALIMAIL_READ_ONLY=false 时注册),🔥 表示破坏性操作(同样需要关闭只读模式,并且需要两步确认)。
users
工具 | 说明 |
| 按 filter 查询用户,游标分页。filter 示例: |
| 获取单个用户 / 批量获取(最多 100 个) |
| 获取邮箱设置(外发限制、转发、附件大小等) |
| 查询共享 / 委托成员 |
✏️ | 创建账号;不传密码时自动生成,并强制下次登录修改 |
✏️ | 更新资料、部门、状态( |
✏️ | 添加别名 |
✏️ | 修改邮箱设置 |
✏️ | 添加 / 更新共享成员权限(LOGIN、SEND_AS、SEND_ON_BEHALF) |
✏️ | 绑定安全手机 |
🔥 | 删除账号(不可逆) |
🔥 | 重置密码(可自动生成) |
🔥 | 删除别名 |
🔥 | 移除共享成员 |
🔥 | 解绑安全手机 |
🔥 | 撤销全部登录态 |
departments
工具 | 说明 |
| 获取部门信息, |
| 批量获取(最多 100 个) |
| 直属子部门 / 直属成员(offset 分页) |
| 层级链(支持单个或批量) |
| 递归获取整棵部门树,自动分页;可设置深度、节点上限,可附带成员 |
✏️ | 创建 / 更新(修改 |
🔥 | 删除部门;非空部门会删除失败,预览中会提示 |
安全机制
两步确认
调用破坏性工具时:
第一次调用(不带
confirm)不会执行操作。它返回status: "confirmation_required",同时附带目标对象的预览(例如被删除用户的姓名、邮箱、状态)和一个confirmToken。AI 必须把预览展示给用户,并取得明确同意。
第二次调用使用完全相同的参数,并带上
confirm: true和confirmToken,这时才真正执行。
confirmToken 只能使用一次,5 分钟后过期,并与工具名和参数绑定:换了目标或修改了参数,token 即失效。
其他
自动生成的密码只在执行结果中出现一次,不会写入日志或审计记录。
设置
ALIMAIL_ALLOWED_DOMAINS后,所有针对单个用户的操作都会检查目标所在域名。用 ID 定位用户时,服务会先查询出邮箱再做检查。创建用户、添加别名、共享成员中的地址也会检查。列表类查询(list_users等)不受此限制。HTTP 模式:
默认只监听
127.0.0.1,并校验 Host 头以防御 DNS rebinding。如果监听在非回环地址上又没有设置
MCP_AUTH_TOKEN,启动时会输出警告。不要把未加认证的端口暴露到局域网或公网:能访问这个端口的人,就能以邮箱管理员身份执行操作。
HTTP 模式是无状态的:每个请求都会新建 MCP 会话。token 缓存、限流、确认令牌和审计日志在进程内共享。
开发
npm ci
npm run typecheck
npm test # vitest;所有 HTTP 请求均为模拟,不访问真实环境
npm run build
npm run inspect # 使用 MCP Inspector 调试(需先设置凭证环境变量)目录结构:
src/
index.ts CLI 入口
config.ts 环境变量校验
server.ts 组装 McpServer
client/ token、限流、HTTP、分页、错误
guard/ 两步确认、域名范围、脱敏、审计
tools/ registry + users + departments
resources/ prompts/
transports/ stdio、Streamable HTTP
test/ 单元测试与端到端测试(InMemory 及 HTTP)新增工具集(例如邮件组、公共联系人、隔离区)的步骤:
在
src/config.ts的TOOLSETS中登记名称。新建
src/tools/<name>.ts,用defineTool定义工具。在
src/server.ts的ALL_TOOLS中注册。
接口的字段、分页方式和所需权限,请以官方文档为准。
许可
Available Tools
11 toolsget_department获取部门信息ARead-onlyIdempotent
根据部门 ID 获取部门信息;id 传 $root 返回组织根部门。
Inputs: id (required), select.
get_department_chain获取部门层级链ARead-onlyIdempotent
获取从根部门到目标部门的完整层级链。传 id 查询单个,传 ids 批量查询(最多 100 个)。
Inputs: id, ids.
get_departments_by_ids批量获取部门信息ARead-onlyIdempotent
根据部门 ID 列表批量获取部门信息(最多 100 个),不存在的 ID 不返回。
Inputs: ids (required), select.
get_department_tree获取部门树ARead-onlyIdempotent
从指定部门(默认根部门)递归获取完整部门树,自动处理分页。可选包含每个部门的直属成员。大型组织请设置 maxDepth / maxNodes 控制规模,结果中 truncated=true 表示被截断。
Inputs: rootId, maxDepth, maxNodes, includeUsers, +1 more.
get_mailbox_settings获取邮箱设置ARead-onlyIdempotent
获取用户邮箱设置(外部收发信限制、自动转发、附件大小、收件人数等)。字段多为可选字段,可用 select 指定,如 forbidSendMailToOutside,forwardingMode,attachmentSize。
Inputs: user (required), select.
get_user获取用户信息CRead-onlyIdempotent
根据用户 ID 或邮箱获取用户详情。
Inputs: user (required), select.
get_users_by_ids批量获取用户信息ARead-onlyIdempotent
根据用户 ID 列表批量获取用户信息(最多 100 个),不存在的 ID 不返回。
Inputs: ids (required), select.
list_department_users查询部门成员ARead-onlyIdempotent
查询指定部门的直属成员(offset/limit 分页,limit 最大 100)。如需含子部门成员,可用 list_users 的 filter (departmentId=xxx*)。
Inputs: id (required), limit, offset, select, +1 more.
list_sub_departments查询子部门ARead-onlyIdempotent
查询指定部门的直属子部门(offset/limit 分页,limit 最大 100)。需要整棵树请用 get_department_tree。
Inputs: id (required), limit, offset, select, +1 more.
list_users查询用户列表ARead-onlyIdempotent
按 filter 表达式查询组织内用户,游标分页(单页最多 100)。 filter 支持字段:email、name、nickname、employeeNo、status、domain、employeeType、delegateType、departmentId、jobTitle、workLocation、homeLocation、info、managerId、isSharedWithOthers。 示例:(departmentId=xxx) 直属成员;(departmentId=xxx*) 含子部门;(|(name=Jack)(email=jack));(&(employeeType=SERVICE)(email=abc));(&(departmentId=xxx)(!(status=FREEZE)))。 返回 hasMore=true 时用 nextCursor 继续翻页。
Inputs: size, order, cursor, filter, +3 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
The get/list department trio (get_department, get_departments_by_ids, get_department_chain) and the tree-vs-subdepartment pair (get_department_tree vs list_sub_departments) have some conceptual overlap, but descriptions explicitly cross-reference each other ("需要整棵树请用 get_department_tree") to route the agent correctly. Single-vs-batch (get_user vs get_users_by_ids) and user-vs-department listing are clearly distinguished.
All 11 tools follow a strict verb_noun snake_case convention: list_*, get_*, with suffixes clearly indicating batch (_by_ids, _ids). No mixing of styles or casing.
11 tools is well within the ideal 3-15 range for an org directory/mailbox admin server. Each tool earns its place by covering a distinct access pattern (single, batch, tree, filter, chain, settings).
The surface is entirely read-only: there is no create/update/delete for departments or users, and no update_mailbox_settings despite get_mailbox_settings existing, which is a notable gap for an 'Admin' server. Read coverage (single, batch, tree, filter, chain, shared accounts, mailbox settings) is otherwise solid.
Maintenance
Related MCP Connectors
Give AI agents secure access to your email via private aliases with dedicated mailbox storage.
Gmail, Outlook, Drive, OneDrive and calendars for AI agents. Many accounts, one endpoint, audit log.
AI agents read & send email, manage mailboxes, domains and webhooks via the QMailing API.
Connect any mailbox to Claude, ChatGPT & AI: read, send, reply, schedule & search emails.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to manage Migadu email hosting services through natural language, including creating mailboxes, setting up aliases, configuring autoresponders, and handling bulk operations efficiently.3533 PyPI17MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to manage MSP-multi-tenant email security: organizations, domains, users, licensing, features, subscription packages, and email flow reporting.Apache 2.0
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants and compatible clients to securely search, read, send, reply, forward, organize, and bulk-delete email across multiple mailboxes, with automatic SMTP configuration and AES-256-encrypted credential storage.1,044 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to safely interact with operations systems such as cloud inventory, runbooks, and ticketing while enforcing role-based access, JWT authentication, write confirmation, secret and PII redaction, rate limits, and audit logging.MIT