@atengk/mcp-server-email 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +346 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1867 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ateng (atengk)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,347 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MCP Server Email
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>生产级 Email Model Context Protocol (MCP) 服务端(支持多账户并发、会话回复保持、IMAP 复合检索、附件沙箱与防灾软删除,提供 Stdio/SSE 双模通信)</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/atengk/mcp-server-email/actions/workflows/ci.yml">
|
|
9
|
+
<img src="https://img.shields.io/github/actions/workflow/status/atengk/mcp-server-email/ci.yml?branch=main&label=CI&style=flat-square" alt="CI Status" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/atengk/mcp-server-email/releases">
|
|
12
|
+
<img src="https://img.shields.io/github/v/release/atengk/mcp-server-email?style=flat-square" alt="Release" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@atengk/mcp-server-email">
|
|
15
|
+
<img src="https://img.shields.io/npm/v/@atengk/mcp-server-email?style=flat-square&color=cb3837" alt="npm version" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="./LICENSE">
|
|
18
|
+
<img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=flat-square" alt="License" />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="./CONTRIBUTING.md">
|
|
21
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome" />
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📖 项目简介
|
|
28
|
+
|
|
29
|
+
`mcp-server-email` 是专为大语言模型(LLM)与 AI 智能体(Agent)打造的生产级邮件能力底座。通过遵循标准化 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 协议,为支持 MCP 的各类客户端宿主环境提供完整的电子邮件外发、会话回复、草稿审查、多维检索、正文提纯、附件沙箱落盘与状态管理能力。
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## ✨ 核心特性
|
|
34
|
+
|
|
35
|
+
- 🎯 **13 大核心工具矩阵**:全功能覆盖外发、会话回复、草稿箱人机协同、多维分页检索、状态看板、正文提纯、附件沙箱、状态标记与防灾软删除;
|
|
36
|
+
- 👥 **原生多账户并发路由**:支持在单服务实例中通过 `MCP_ACCOUNTS`(JSON)或 `MCP_ACCOUNTS_FILE` 配置多个邮箱画像(如 `work`、`personal`),工具层自动按 `account` 参数动态分发并支持默认账户平滑回退;
|
|
37
|
+
- 🧵 **RFC 会话线程(Threading)保持**:专属 `reply_email` 工具自动读取原信 Message-ID,注入 `In-Reply-To` 与 `References` 邮件头,在各类邮件客户端中维持原生树状会话折叠;
|
|
38
|
+
- 🛡️ **三位一体安全与防灾隔离**:
|
|
39
|
+
- **凭据零泄露**:密码完全封存于环境层,Tool 入参及返回值绝不暴露敏感密钥;
|
|
40
|
+
- **附件沙箱隔离**:物理落盘强制限制在受管安全目录,严格防御 `../` 路径穿越攻击;
|
|
41
|
+
- **防灾软删除**:彻底禁用底层硬删除(EXPUNGE),删除意图统一路由至回收站(Trash);
|
|
42
|
+
- ⚡ **Token 经济性与上下文防御**:HTML 正文自动提纯为 Markdown 并执行 30KB 安全截断;检索列表自带 150 字符 Preview 纯文本摘要;邮件详情仅返回附件元数据清单,严禁大体积 Base64 塞爆上下文;
|
|
43
|
+
- 🔄 **Stdio / SSE 双模通信**:默认采用 `Stdio` 适配本地客户端进程直接拉起;支持 `--transport sse --port 3000` 切换为流式 HTTP 服务,便于 Docker 容器云或集中部署;
|
|
44
|
+
- 📦 **免安装秒开 (npx)**:一条命令直接通过 `npx -y @atengk/mcp-server-email` 极速加载。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🛠️ 主流 MCP 客户端集成指引
|
|
49
|
+
|
|
50
|
+
### 1. Claude Desktop
|
|
51
|
+
|
|
52
|
+
根据操作系统打开配置文件:
|
|
53
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
54
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
55
|
+
|
|
56
|
+
在 `mcpServers` 中添加配置:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"mcpServers": {
|
|
61
|
+
"email": {
|
|
62
|
+
"command": "npx",
|
|
63
|
+
"args": ["-y", "@atengk/mcp-server-email"],
|
|
64
|
+
"env": {
|
|
65
|
+
"MCP_SMTP_HOST": "smtp.qq.com",
|
|
66
|
+
"MCP_SMTP_PORT": "465",
|
|
67
|
+
"MCP_SMTP_SECURE": "true",
|
|
68
|
+
"MCP_SMTP_USER": "your_email@qq.com",
|
|
69
|
+
"MCP_SMTP_PASS": "YOUR_AUTHORIZATION_CODE",
|
|
70
|
+
"MCP_SMTP_FROM": "AI 助理 <your_email@qq.com>",
|
|
71
|
+
"MCP_IMAP_HOST": "imap.qq.com",
|
|
72
|
+
"MCP_IMAP_PORT": "993",
|
|
73
|
+
"MCP_IMAP_SECURE": "true",
|
|
74
|
+
"MCP_IMAP_USER": "your_email@qq.com",
|
|
75
|
+
"MCP_IMAP_PASS": "YOUR_AUTHORIZATION_CODE"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. Cursor
|
|
83
|
+
|
|
84
|
+
在 Cursor 中依次打开 **Settings -> Features -> MCP Servers -> Add New MCP Server**:
|
|
85
|
+
- **Name**: `email`
|
|
86
|
+
- **Type**: `command`
|
|
87
|
+
- **Command**: `npx -y @atengk/mcp-server-email`
|
|
88
|
+
- 在环境变量面板中添加 `MCP_SMTP_*` 与 `MCP_IMAP_*` 凭据配置。
|
|
89
|
+
|
|
90
|
+
### 3. Cline (VS Code 扩展)
|
|
91
|
+
|
|
92
|
+
在 Cline 的 MCP 设置页面(或编辑 `cline_mcp_settings.json`)添加:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"email": {
|
|
98
|
+
"command": "npx",
|
|
99
|
+
"args": ["-y", "@atengk/mcp-server-email"],
|
|
100
|
+
"env": {
|
|
101
|
+
"MCP_SMTP_HOST": "smtp.163.com",
|
|
102
|
+
"MCP_SMTP_PORT": "465",
|
|
103
|
+
"MCP_SMTP_SECURE": "true",
|
|
104
|
+
"MCP_SMTP_USER": "your_email@163.com",
|
|
105
|
+
"MCP_SMTP_PASS": "YOUR_AUTH_CODE",
|
|
106
|
+
"MCP_IMAP_HOST": "imap.163.com",
|
|
107
|
+
"MCP_IMAP_PORT": "993",
|
|
108
|
+
"MCP_IMAP_SECURE": "true",
|
|
109
|
+
"MCP_IMAP_USER": "your_email@163.com",
|
|
110
|
+
"MCP_IMAP_PASS": "YOUR_AUTH_CODE"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 4. Windsurf (Cascade)
|
|
118
|
+
|
|
119
|
+
在 `~/.codeium/windsurf/mcp_config.json` 中配置:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"mcpServers": {
|
|
124
|
+
"email": {
|
|
125
|
+
"command": "npx",
|
|
126
|
+
"args": ["-y", "@atengk/mcp-server-email"],
|
|
127
|
+
"env": {
|
|
128
|
+
"MCP_DEFAULT_ACCOUNT": "work",
|
|
129
|
+
"MCP_ACCOUNTS_FILE": "/Users/username/.config/mcp-email/accounts.json"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 👥 多账户配置模式 (Multi-Account)
|
|
139
|
+
|
|
140
|
+
当您拥有多个邮箱(如个人 QQ 邮箱与公司 Office 365 邮箱)时,可使用以下两种多账户配置方式:
|
|
141
|
+
|
|
142
|
+
### 方式 1:环境变量 JSON 字符串 (`MCP_ACCOUNTS`)
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"mcpServers": {
|
|
147
|
+
"email": {
|
|
148
|
+
"command": "npx",
|
|
149
|
+
"args": ["-y", "@atengk/mcp-server-email"],
|
|
150
|
+
"env": {
|
|
151
|
+
"MCP_DEFAULT_ACCOUNT": "work",
|
|
152
|
+
"MCP_ACCOUNTS": "{\"personal\":{\"smtp\":{\"host\":\"smtp.qq.com\",\"port\":465,\"secure\":true,\"user\":\"me@qq.com\",\"pass\":\"YOUR_QQ_AUTH_CODE\"},\"imap\":{\"host\":\"imap.qq.com\",\"port\":993,\"secure\":true,\"user\":\"me@qq.com\",\"pass\":\"YOUR_QQ_AUTH_CODE\"}},\"work\":{\"smtp\":{\"host\":\"smtp.office365.com\",\"port\":587,\"secure\":false,\"user\":\"me@company.com\",\"pass\":\"YOUR_WORK_PASS\"},\"imap\":{\"host\":\"outlook.office365.com\",\"port\":993,\"secure\":true,\"user\":\"me@company.com\",\"pass\":\"YOUR_WORK_PASS\"}}}"
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 方式 2:外部配置文件路径 (`MCP_ACCOUNTS_FILE`)
|
|
160
|
+
|
|
161
|
+
指向本地的一个标准 JSON 文件(参考 [`examples/accounts.example.json`](./examples/accounts.example.json)):
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"personal": {
|
|
166
|
+
"email": "me@qq.com",
|
|
167
|
+
"smtp": {
|
|
168
|
+
"host": "smtp.qq.com",
|
|
169
|
+
"port": 465,
|
|
170
|
+
"secure": true,
|
|
171
|
+
"user": "me@qq.com",
|
|
172
|
+
"pass": "YOUR_QQ_AUTH_CODE",
|
|
173
|
+
"from": "个人助手 <me@qq.com>"
|
|
174
|
+
},
|
|
175
|
+
"imap": {
|
|
176
|
+
"host": "imap.qq.com",
|
|
177
|
+
"port": 993,
|
|
178
|
+
"secure": true,
|
|
179
|
+
"user": "me@qq.com",
|
|
180
|
+
"pass": "YOUR_QQ_AUTH_CODE"
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"work": {
|
|
184
|
+
"email": "me@company.com",
|
|
185
|
+
"smtp": {
|
|
186
|
+
"host": "smtp.office365.com",
|
|
187
|
+
"port": 587,
|
|
188
|
+
"secure": false,
|
|
189
|
+
"user": "me@company.com",
|
|
190
|
+
"pass": "YOUR_WORK_PASS",
|
|
191
|
+
"from": "工作助理 <me@company.com>"
|
|
192
|
+
},
|
|
193
|
+
"imap": {
|
|
194
|
+
"host": "outlook.office365.com",
|
|
195
|
+
"port": 993,
|
|
196
|
+
"secure": true,
|
|
197
|
+
"user": "me@company.com",
|
|
198
|
+
"pass": "YOUR_WORK_PASS"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 🧰 13 大核心 MCP 工具详尽手册
|
|
207
|
+
|
|
208
|
+
所有工具均支持可选的 `account?: string` 参数,未传时自动回退至默认账户。
|
|
209
|
+
|
|
210
|
+
### 1. 账户发现与连通性自检
|
|
211
|
+
|
|
212
|
+
- **`list_accounts`**:列出当前服务端已注册的所有可用账户画像标识(包含邮箱地址、发信与收信服务器脱敏主机,严禁暴露密码)。
|
|
213
|
+
- *入参*:无
|
|
214
|
+
- **`verify_connection`**:一键对指定账户或默认账户发起真实的 SMTP 与 IMAP 握手体检,返回各协议连通性报告。
|
|
215
|
+
- *入参*:`account?: string`
|
|
216
|
+
|
|
217
|
+
### 2. 外发通信与人机协同
|
|
218
|
+
|
|
219
|
+
- **`send_email`**:外发全新邮件。支持纯文本、HTML 富文本、抄送、密送与本地文件附件。
|
|
220
|
+
- *入参*:
|
|
221
|
+
- `to`: 收件人地址(单字符串或字符串数组)
|
|
222
|
+
- `subject`: 邮件主题
|
|
223
|
+
- `text?`: 纯文本正文
|
|
224
|
+
- `html?`: HTML 格式正文
|
|
225
|
+
- `cc?`: 抄送地址列表
|
|
226
|
+
- `bcc?`: 密送地址列表
|
|
227
|
+
- `attachments?`: 附件列表(包含 `filename`, `path`, `content`, `contentType`)
|
|
228
|
+
- `account?`: 邮箱账户标识
|
|
229
|
+
- **`reply_email`**:会话回复专属工作流。根据被回复邮件原信自动注入 `In-Reply-To` 与 `References` 头,自动添加 `Re:` 前缀。
|
|
230
|
+
- *入参*:
|
|
231
|
+
- `originalUid`: 原邮件 UID
|
|
232
|
+
- `text?` / `html?`: 回复正文
|
|
233
|
+
- `replyAll?`: 是否全员回复(默认 false,为 true 时自动保留原抄送人并排除自身)
|
|
234
|
+
- `mailbox?`: 原邮件所在文件夹(默认 INBOX)
|
|
235
|
+
- `account?`: 邮箱账户标识
|
|
236
|
+
- **`create_draft`**:将邮件载荷构造成标准 RFC 822 MIME 数据并存入草稿箱,等待用户在客户端中复核与审批后手动发出。
|
|
237
|
+
- *入参*:`to?`, `subject?`, `text?`, `html?`, `cc?`, `bcc?`, `attachments?`, `account?`
|
|
238
|
+
|
|
239
|
+
### 3. 多维检索与正文提纯
|
|
240
|
+
|
|
241
|
+
- **`search_emails`**:在指定邮箱中进行多维组合检索。包含发件人、收件人、主题、未读、星标、附件与日期范围筛选,并自带 **150 字符 Preview 纯文本摘要**与分页元数据。
|
|
242
|
+
- *入参*:`query?`, `from?`, `to?`, `subject?`, `unseenOnly?`, `flaggedOnly?`, `hasAttachment?`, `since?`, `before?`, `page?` (默认 1), `limit?` (默认 10), `mailbox?` (默认 INBOX), `account?`
|
|
243
|
+
- **`get_email_detail`**:获取邮件完整详情。自动将 HTML 清洗转换为结构清晰的轻量 Markdown,执行 **30KB 阈值截断保护**并返回脱敏附件元数据列表(严禁 Base64 泄露)。
|
|
244
|
+
- *入参*:`uid`: 邮件 UID, `mailbox?` (默认 INBOX), `account?`
|
|
245
|
+
- **`download_attachment`**:将指定附件安全提取并落盘至受管本地沙箱,返回物理绝对路径与 `file:///` 直达 URI。
|
|
246
|
+
- *入参*:`uid`: 邮件 UID, `attachmentId`: 附件标识序号(如 '0')或附件原名, `mailbox?` (默认 INBOX), `account?`
|
|
247
|
+
|
|
248
|
+
### 4. 状态看板与归类流转
|
|
249
|
+
|
|
250
|
+
- **`get_mailbox_status`**:毫秒级极速获取指定或全部文件夹的状态看板(总邮件数、未读数、最近邮件数)。
|
|
251
|
+
- *入参*:`mailbox?` (指定单个文件夹或缺省统计全部), `account?`
|
|
252
|
+
- **`list_mailboxes`**:列出当前连接邮箱服务商所有可用的物理文件夹清单。
|
|
253
|
+
- *入参*:`account?`
|
|
254
|
+
- **`mark_email_read`**:修改邮件的已读/未读状态标记(`\Seen`),支持单封与批量原子变更。
|
|
255
|
+
- *入参*:`uids`: 单个 UID 或 UID 数组, `read?` (默认 true), `mailbox?` (默认 INBOX), `account?`
|
|
256
|
+
- **`flag_email`**:设置或取消重要星标标记(`\Flagged`),用于高优先级事项置顶关注。
|
|
257
|
+
- *入参*:`uids`: 单个 UID 或 UID 数组, `flagged?` (默认 true), `mailbox?` (默认 INBOX), `account?`
|
|
258
|
+
- **`move_email`**:将邮件跨文件夹移动或归档。**彻底杜绝物理硬删除(EXPUNGE)**,软删除请指定 `targetMailbox: "trash"`。
|
|
259
|
+
- *入参*:`uids`: 单个 UID 或 UID 数组, `targetMailbox`: 目标文件夹或别名, `sourceMailbox?` (默认 INBOX), `account?`
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## ⚙️ 环境变量全景表
|
|
264
|
+
|
|
265
|
+
| 环境变量名 | 类型 | 说明 | 示例 |
|
|
266
|
+
| :--- | :--- | :--- | :--- |
|
|
267
|
+
| `MCP_ACCOUNTS` | JSON 字符串 | 多账户配置对象(包含多个画像的 SMTP 与 IMAP 凭据) | 见多账户配置示例 |
|
|
268
|
+
| `MCP_ACCOUNTS_FILE` | 字符串 | 外部多账户 JSON 配置文件绝对路径 | `/etc/mcp-email/accounts.json` |
|
|
269
|
+
| `MCP_DEFAULT_ACCOUNT` | 字符串 | 多账户模式下的缺省路由账户名称 | `work` |
|
|
270
|
+
| `MCP_ATTACHMENT_DIR` | 字符串 | 附件下载的本地受管沙箱根目录 | `/data/mcp-attachments`(默认系统隔离临时目录) |
|
|
271
|
+
| `MCP_SMTP_HOST` | 字符串 | 单账户模式:SMTP 发信服务器主机 | `smtp.qq.com` |
|
|
272
|
+
| `MCP_SMTP_PORT` | 数字 | 单账户模式:SMTP 发信端口 | `465` 或 `587` |
|
|
273
|
+
| `MCP_SMTP_SECURE` | 布尔 | 单账户模式:是否启用 TLS/SSL 加密 | `true`(默认 true) |
|
|
274
|
+
| `MCP_SMTP_USER` | 字符串 | 单账户模式:SMTP 登录用户名 / 邮箱地址 | `user@example.com` |
|
|
275
|
+
| `MCP_SMTP_PASS` | 字符串 | 单账户模式:SMTP 授权码或密码 | `YOUR_AUTH_CODE` |
|
|
276
|
+
| `MCP_SMTP_FROM` | 字符串 | 单账户模式:发件人展示格式 | `AI 助理 <user@example.com>` |
|
|
277
|
+
| `MCP_IMAP_HOST` | 字符串 | 单账户模式:IMAP 收信服务器主机 | `imap.qq.com` |
|
|
278
|
+
| `MCP_IMAP_PORT` | 数字 | 单账户模式:IMAP 收信端口 | `993` |
|
|
279
|
+
| `MCP_IMAP_SECURE` | 布尔 | 单账户模式:是否启用 TLS/SSL 加密 | `true`(默认 true) |
|
|
280
|
+
| `MCP_IMAP_USER` | 字符串 | 单账户模式:IMAP 登录用户名 / 邮箱地址 | `user@example.com` |
|
|
281
|
+
| `MCP_IMAP_PASS` | 字符串 | 单账户模式:IMAP 授权码或密码 | `YOUR_AUTH_CODE` |
|
|
282
|
+
| `MCP_TRANSPORT` | 枚举 | 通信传输模式 (`stdio` 或 `sse`) | `stdio`(默认 stdio) |
|
|
283
|
+
| `MCP_PORT` | 数字 | SSE 模式下的 HTTP 监听端口 | `3000` |
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## 📮 常见邮箱服务商配置指引
|
|
288
|
+
|
|
289
|
+
> ⚠️ **避坑指南**:现代主流邮箱服务商出于安全考虑,均**不支持**直接使用邮箱日常登录密码,必须在邮箱网页端设置中开启 POP3/IMAP/SMTP 服务并生成专属的 **授权码 / 应用密码 (App Password)**。
|
|
290
|
+
|
|
291
|
+
| 邮箱服务商 | SMTP 服务器 & 端口 | IMAP 服务器 & 端口 | 密码填写要求与开启路径 |
|
|
292
|
+
| :--- | :--- | :--- | :--- |
|
|
293
|
+
| **QQ 邮箱** | `smtp.qq.com:465` (SSL) | `imap.qq.com:993` (SSL) | 在「网页设置 -> 账户 -> POP3/IMAP 服务」生成 16 位专属授权码 |
|
|
294
|
+
| **163 网易邮箱** | `smtp.163.com:465` (SSL) | `imap.163.com:993` (SSL) | 在「网页设置 -> POP3/SMTP/IMAP」开启并获取客户端授权密码 |
|
|
295
|
+
| **Gmail** | `smtp.gmail.com:465` (SSL) | `imap.gmail.com:993` (SSL) | 开启 Google 账号两步验证后,在「安全性 -> 应用专用密码」生成 |
|
|
296
|
+
| **Outlook / Office 365** | `smtp.office365.com:587` | `outlook.office365.com:993` | 需管理员开启相应 IMAP/SMTP 访问权限或配置应用密码 |
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## 🐳 Docker 容器运行 (SSE 模式)
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
docker run -d \
|
|
304
|
+
--name mcp-server-email \
|
|
305
|
+
-p 3000:3000 \
|
|
306
|
+
-e MCP_TRANSPORT=sse \
|
|
307
|
+
-e MCP_PORT=3000 \
|
|
308
|
+
-e MCP_SMTP_HOST=smtp.example.com \
|
|
309
|
+
-e MCP_SMTP_PORT=465 \
|
|
310
|
+
-e MCP_SMTP_USER=user@example.com \
|
|
311
|
+
-e MCP_SMTP_PASS=YOUR_SMTP_PASSWORD \
|
|
312
|
+
-e MCP_IMAP_HOST=imap.example.com \
|
|
313
|
+
-e MCP_IMAP_PORT=993 \
|
|
314
|
+
-e MCP_IMAP_USER=user@example.com \
|
|
315
|
+
-e MCP_IMAP_PASS=YOUR_IMAP_PASSWORD \
|
|
316
|
+
ghcr.io/atengk/mcp-server-email:latest
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## 💻 本地研发与质量保障
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# 安装依赖
|
|
325
|
+
pnpm install
|
|
326
|
+
|
|
327
|
+
# 运行全量测试套件
|
|
328
|
+
pnpm test
|
|
329
|
+
|
|
330
|
+
# 执行 TypeScript 类型检查
|
|
331
|
+
pnpm typecheck
|
|
332
|
+
|
|
333
|
+
# 编译打包单文件 ESM 产物
|
|
334
|
+
pnpm build
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## 🤝 参与贡献
|
|
340
|
+
|
|
341
|
+
欢迎任何形式的贡献与建议!请在提交代码前仔细阅读我们的 [贡献指南 (CONTRIBUTING.md)](./CONTRIBUTING.md)。
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## 📄 开源许可证
|
|
346
|
+
|
|
347
|
+
本项目基于 [Apache License 2.0](./LICENSE) 协议开源。
|
package/dist/index.d.ts
ADDED