内容
# MCP Server for Personal Mailer
一个基于 rust 的 MCP ([Model Context Protocol](https://modelcontextprotocol.io/introduction)) 服务器的示例项目,用于个人邮件。它使用户能够通过简单地向 LLM 聊天界面(如 Cursor 和 Copilot)发出提示来发送电子邮件。
这是通过使用 MCP 的官方 [rust sdk](https://github.com/modelcontextprotocol/rust-sdk)(正在积极开发中)实现的。它主要使用 crate [lettre](https://crates.io/crates/lettre) 作为底层的 SMTP 客户端。
## Usage
本节介绍了一些用例,以表明 MCP 服务器比传统的电子邮件程序更有趣。
传统的电子邮件程序要求用户知道如何将数据输入到程序中才能工作(例如,发送电子邮件)。在这里,我们可以只使用简单的词语,LLM 将帮助我们创建输入数据,以便将其放入“程序”中。
**Example 1:**
```text
send an formal email to Bob (bob@domain.com). invite him to my friend Chris's wedding. closing with my name "Alvin"
```
<details>
<summary>Sample Output</summary>
LLM:
```text
Email sent successfully!
```
SMTP:
```text
From: test@test.com
Subject: Invitation to Chris's Wedding
Content-Type: text/plain; charset=utf-8
To: bob@domain.com
Content-Transfer-Encoding: quoted-printable
Date: Sun, 18 May 2025 12:59:33 +0000
X-Peer: ('127.0.0.1', 58769)
Dear Bob,
I hope this message finds you well. I am writing to formally invite you to =
my friend Chris's wedding. It would be a pleasure to have you join us for t=
his special occasion.
Please let me know if you are able to attend.
Best regards,
Alvin
```
</details>
**Example 2:**
```text
add a email template named "greeting". It is a greeting to a new customer.
```
<details>
<summary>Sample Output</summary>
LLM:
```text
Email template created successfully!
```
Template:
```text
Hello {customer_name},
Welcome to our service! We are excited to have you as a new customer.
Best regards,
The Team
```
</details>
```text
send greeting email to customer "abc"
```
<details>
<summary>Sample Output</summary>
LLM:
```text
Email sent with template successfully!
```
SMTP:
```text
From: test@test.com
Subject: Welcome to our service!
Content-Type: text/plain; charset=utf-8
To: abc@abc.com
Content-Transfer-Encoding: 7bit
Date: Sun, 18 May 2025 12:28:52 +0000
X-Peer: ('127.0.0.1', 58333)
Hello abc,
Welcome to our service! We are excited to have you as a new customer.
Best regards,
The Team
```
</details>
## Local Run for Testing
本节介绍如何为测试目的在本地运行 MCP 服务器。
Prerequisites:
- python module `aiosmtpd` 作为 SMTP 服务器
- visual studio code with github copilot 作为 LLM 聊天界面和 MCP 客户端
Follow the steps:
1. 运行 SMTP 服务器。
```sh
python -m aiosmtpd -n -l 127.0.0.1:2525
```
1. 按照此[指南](https://docs.github.com/en/copilot/customizing-copilot/extending-copilot-chat-with-mcp)在您的 VSCode 中设置 MCP 代理。
1. 通过单击 VSCode 中 `mcp.json` 文件中的“start”按钮来启动 MCP 代理。
1. 运行 MCP 服务器:
```sh
cargo run
```
Finally, try typing the prompt in the chat interface, e.g. "send an email to you@domain.com with subject 'test' and body 'hello world'".