内容
# LMStudio MCPs & Autonomous Email Agent
LM Studio 的 MCP 服务器集合,以及一个由本地 LLM 驱动的**全自主电子邮件代理**。
## 🤖 特色:自主电子邮件代理
**给 AI 发送电子邮件,获得智能回复**。电子邮件代理在后台运行,监控您的收件箱,并使用本地 LLM 回复 — 包含实时信息搜索。
### 功能
| 功能 | 描述 |
|---------|-------------|
| 📥 **自动回复 / Auto-Reply** | 每 2 分钟检查收件箱,回复新邮件 / Checks inbox every 2 minutes, replies to new emails |
| 🔍 **网络搜索 / Web Search** | 在询问新闻、天气等时自动搜索网络 / Automatically searches the web when you ask about news, weather, etc. |
| 🥠 **有趣的 outgoing / Fun Outgoing** | 每小时发送幸运饼、笑话、名言和每日摘要 / Sends fortune cookies, jokes, quotes, and daily digests hourly |
| 🧠 **本地 LLM / Local LLM** | 所有智能都在您的机器上通过 LM Studio 运行 / All intelligence runs on YOUR machine via LM Studio |
| 🛡️ **仅限新邮件 / New-Only** | 仅回复代理启动后收到的邮件(忽略旧邮件)/ Only replies to emails received after agent starts (ignores old mail) |
### 演示对话
```
您发送电子邮件: "What's the weather in Austin?"
代理回复:
📋 搜索决定:SEARCH: weather Austin Texas
🔍 搜索天气:weather Austin Texas
✅ 找到 3 个搜索结果 / Found 3 search results
🤔 思考回复... / Thinking of reply...
📤 发送回复... / Sending reply...
您收到: "Hi! Based on current forecasts, Austin is expecting highs of 45°F with an Arctic blast moving through the region..."
```
### 快速开始
```bash
# 1. 安装依赖 / Install dependencies
pip install ddgs
# 2. 在脚本中配置您的 Gmail 凭证(参见下面的设置)
# Configure your Gmail credentials in the script (see setup below)
# 3. 启动 LM Studio,加载您的模型(例如 Llama、Mistral、Qwen 等)
# Start LM Studio with your model loaded (e.g., Llama, Mistral, Qwen, etc.)
# 4. 运行代理 / Run the agent
python agent/fun_agent_email.py
```
### 代理设置
#### Gmail 配置
代理使用 Gmail SMTP/IMAP。您需要一个**应用密码**(不是您的常规密码)。
1. 在您的 Google 账户上启用 2FA / Enable 2FA on your Google Account
2. 前往 [Google 应用密码](https://myaccount.google.com/apppasswords) / Go to [Google App Passwords](https://myaccount.google.com/apppasswords)
3. 为“邮件”生成密码 / Generate a password for "Mail"
4. 编辑脚本的 `EMAIL_CONFIG` / Edit the script's `EMAIL_CONFIG`:
```python
EMAIL_CONFIG = {
"smtp_server": "smtp.gmail.com",
"smtp_port": 587,
"imap_server": "imap.gmail.com",
"sender_email": "your-bot@gmail.com", # 机器人的电子邮件 / Bot's email
"sender_password": "xxxx xxxx xxxx xxxx", # 应用密码 / App password
"recipient_email": "your-personal@gmail.com" # 发送幸运饼的邮箱 / Where to send fortunes
}
```
#### LM Studio 配置
确保 LM Studio 运行并加载模型:
- 加载模型(任何模型都有效)
- 在端口 1234 上启用本地服务器(默认)
### 代理命令
```bash
# 运行代理(双重心跳循环)/ Run the agent (dual heartbeat loop)
python fun_agent_email.py
# 测试命令 / Test commands
python fun_agent_email.py test # 发送测试幸运饼 / Send a test fortune
python fun_agent_email.py digest # 发送每日摘要 / Send a daily digest
python fun_agent_email.py inbox # 检查收件箱并总结 / Check inbox and summarize
python fun_agent_email.py reply # 检查邮件并回复 / Check for emails and reply
python fun_agent_email.py search # 测试网络搜索 / Test web search
python fun_agent_email.py list # 列出最近的邮件 / List recent emails
```
### 双重心跳系统
代理运行两个循环:
| 循环 | 间隔 | 操作 |
|------|----------|--------|
| **收件箱检查 / Inbox Check** | 每 2 分钟 / Every 2 minutes | 检查新邮件,自动回复 / Check for new emails, auto-reply |
| **外出邮件 / Outgoing Mail** | 每 1 小时 / Every 1 hour | 发送幸运饼/笑话/摘要 / Send fortune/joke/digest |
在脚本中调整时间:
```python
INBOX_CHECK_INTERVAL = 120 # 秒 / seconds
OUTGOING_INTERVAL = 3600 # 秒 / seconds
```
### 网络搜索
代理自动决定何时搜索。它将搜索:
- 天气,预报 / Weather, forecasts
- 新闻,头条,当前事件 / News, headlines, current events
- 体育比分 / Sports scores
- 股票价格 / Stock prices
- 任何带有“今天” / “最新” / “当前”的内容 / Anything "today" / "latest" / "current"
跳过搜索:
- 问候语(“hi”,“how are you”)/ Greetings ("hi", "how are you")
- 它已经知道的常识 / General knowledge it already knows
- 个人问题 / Personal questions
### 示例邮件
| 您的邮件 | 代理回复 |
|------------|----------------|
| "What's the weather?" | 搜索网络,回复预报 / Searches web, replies with forecast |
| "Latest AI news?" | 搜索新闻,总结头条 / Searches news, summarizes headlines |
| "Tell me a joke" | 生成笑话(无需搜索)/ Generates a joke (no search needed) |
| "What's 2+2?" | 直接回答(无需搜索)/ Answers directly (no search needed) |
| "Who won the Super Bowl?" | 搜索,回复获胜者 / Searches, replies with winner |
## 📋 MCP 服务器
除了电子邮件代理外,该存储库还包括 MCP 服务器,扩展了 LM Studio 聊天界面中本地 LLM 的功能。
| 服务器 | 描述 |
|--------|-------------|
| **datetime** | 获取当前日期和时间 / Get current date and time |
| **email** | 通过 Gmail SMTP 发送电子邮件 / Send emails via Gmail SMTP |
| **groq** | 通过 Groq API 查询更大的模型(Llama 70B)/ Query larger models (Llama 70B) via Groq API |
| **octave** | 执行 GNU Octave/MATLAB 代码 / Execute GNU Octave/MATLAB code |
| **python** | 执行带有持久状态的 Python 代码 / Execute Python code with persistent state |
| **websearch** | 通过 DuckDuckGo 搜索网络 / Search the web via DuckDuckGo |
### 先决条件
- **LM Studio**(带有 MCP 支持的版本)
- **Python 3.10+**
- **Windows**(电子邮件和八度服务器使用 Windows 特定功能)
- 对于 Octave:安装 [GNU Octave](https://octave.org/download)
- 对于 Groq:[Groq API 密钥](https://console.groq.com/)
### 安装
```bash
# 克隆存储库 / Clone the repository
git clone https://github.com/yourusername/LMStudio_MCPs.git
cd LMStudio_MCPs
# 安装依赖 / Install dependencies
pip install pytz # datetime
pip install beautifulsoup4 ddgs requests uvicorn # websearch
pip install mcp groq # groq
pip install matplotlib numpy pandas # python server
```
## MCP 服务器详情
### DateTime - 当前日期/时间
以人类可读的格式返回当前日期和时间。
**工具 / Tools:** `get_datetime`
**配置 / Configuration (`datetime/server.py`):
```python
tz = pytz.timezone("US/Central") # 更改为您的时区 / Change to your timezone
```
### 电子邮件 - 通过 Gmail 发送电子邮件
⚠️ **需要设置 Gmail 应用密码** (参见上面的代理设置)
**工具 / Tools:** `send_email`
**平台 / Platform:** 仅限 Windows(使用 PowerShell)/ Windows only (uses PowerShell)
### Groq - 咨询更大的模型
通过 Groq API 查询 Llama 3.3 70B。
**工具 / Tools:** `ask_larger_model`
**设置 / Setup:**
1. 从 [console.groq.com](https://console.groq.com/) 获取 API 密钥 / Get API key from [console.groq.com](https://console.groq.com/)
2. 在 mcp.json 中设置(参见下面的示例)/ Set in mcp.json (see example below)
### Octave - 数值计算
执行带有持久工作区的 GNU Octave/MATLAB 代码。
**工具 / Tools:**
- `octave_execute` - 执行代码 / Execute code
- `octave_get_variable` / `octave_set_variable`
- `octave_list_workspace` / `octave_clear`
- `octave_save_figure` - 保存绘图为 PNG / Save plots to PNG
- `octave_help` / `octave_run_script` / `octave_create_script`
**设置 / Setup:** 在 `octave/octave_mcp_server.py` 中更新 Octave 路径 / Update Octave path in `octave/octave_mcp_server.py`
### Python - 代码执行
执行带有持久命名空间的 Python 代码。
**工具 / Tools:**
- `python_execute` - 执行代码 / Execute code
- `python_get_variable` / `python_set_variable` / `python_list_variables`
- `python_clear` / `python_save_figure`
- `python_create_script` / `python_run_script` / `python_list_scripts`
- `python_pip_install` / `python_help`
### 网络搜索 - DuckDuckGo
无需 API 密钥即可搜索网络。
**工具 / Tools:**
- `web_search` - 搜索,返回标题/片段/网址 / Search, returns titles/snippets/URLs
- `get_page_content` - 获取并提取页面文本 / Fetch and extract page text
## LM Studio 配置
### mcp.json 位置
- **Windows:** `%USERPROFILE%\.lmstudio\mcp.json`
- **macOS/Linux:** `~/.lmstudio/mcp.json`
### 完整的 mcp.json 示例
```json
{
"mcpServers": {
"datetime": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/datetime/server.py"]
},
"email": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/email/server.py"]
},
"groq": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/groq/server.py"],
"env": {
"GROQ_API_KEY": "gsk_your_api_key_here"
}
},
"octave": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/octave/octave_mcp_server.py"]
},
"python": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/python/python_mcp_server.py"]
},
"websearch": {
"command": "python",
"args": ["C:/Users/YourName/LMStudio_MCPs/websearch/main.py"]
}
}
}
```
**提示 / Tips:** 在路径中使用正斜杠,或转义反斜杠(`\\`)。 / Use forward slashes in paths, or escape backslashes (`\\`).
## 故障排除
### 电子邮件代理问题
| 问题 | 解决方案 |
|---------|----------|
| 无法连接到 LM Studio | 确保 LM Studio 在端口 1234 上运行本地服务器 / Ensure LM Studio is running with local server on port 1234 |
| 搜索功能不工作 | 运行 `pip install ddgs` 并使用 `python fun_agent_email.py search` 进行测试 / Run `pip install ddgs` and test with `python fun_agent_email.py search` |
| 不回复邮件 | 检查 Gmail 应用密码是否正确;检查是否启用 IMAP / Check Gmail App Password is correct; check IMAP is enabled |
| 回复旧邮件 | 代理应忽略旧邮件;检查控制台输出 / Agent should ignore old mail on startup; check console output |
### MCP 服务器问题
| 问题 | 解决方案 |
|---------|----------|
| 服务器无法连接 | 检查 Python 路径;如有必要,使用完整路径 / Check Python path; use full path if needed |
| 电子邮件身份验证失败 | 使用应用密码,而不是 Gmail 密码 / Use App Password, not Gmail password |
| Groq API 错误 | 检查 API 密钥;注意免费层级的速率限制 / Check API key; watch for rate limits on free tier |
| Octave 未找到 | 在 `octave_mcp_server.py` 中更新路径 / Update path in `octave_mcp_server.py` |
### 一般调试
手动测试任何服务器:
```bash
python path/to/server.py
```
然后粘贴:
```json
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}
```
您应该看到一个 JSON 响应。
## 项目结构
```
LMStudio_MCPs/
├── agent/
│ └── fun_agent_email.py # 🤖 自主电子邮件代理 / Autonomous email agent
├── datetime/
│ └── server.py
├── email/
│ └── server.py
├── groq/
│ └── server.py
├── octave/
│ └── octave_mcp_server.py
├── python/
│ └── python_mcp_server.py
├── websearch/
│ └── main.py
└── README.md
```
## 接下来是什么?
扩展电子邮件代理的想法:
- **提醒 / Reminders** - "2 小时后提醒我" → 稍后发送电子邮件 / "Remind me in 2 hours" → emails you later
- **URL 总结 / URL Summarizer** - 发送链接,获取总结 / Send a link, get a summary
- **每日新闻摘要 / Daily News Digest** - 主动提供早晨的头条新闻 / Proactive morning headlines
- **股票警报 / Stock Alerts** - "如果 AAPL 跌破 200 美元,则提醒我" / "Alert me if AAPL drops below $200"
- **待办事项列表 / Todo List** - 通过电子邮件管理任务 / Manage tasks via email
- **图像生成 / Image Generation** - 生成图像并通过电子邮件发送 / Generate images and email them back
## 许可证
MIT 许可证
## 贡献
欢迎贡献!打开问题或拉取请求。
**使用本地 AI 构建。** 核心功能无云依赖 — 您的数据保留在您的机器上。
**Built with local AI in mind.** No cloud dependencies for core functionality — your data stays on your machine.
MCP 配置
以下是此 MCP Server 的配置信息,可直接复制到 Cursor 或其他 MCP 客户端中使用。
mcp.json
连接信息
猜你喜欢
everything-claude-code
完整的 Claude Code 配置集合 - agents、skills、hooks、commands、rules、MCPs。来自 Anthropic...
Firecrawl
Firecrawl MCP Server 实现了网页抓取、爬虫和内容提取功能。
MarkItDown MCP
MarkItDown-MCP是一个轻量级服务器,用于将URI转换为Markdown。
cc-switch
跨平台的Claude Code、Codex和Gemini CLI一体化助手。
Agent-Reach
赋予你的AI Agent观察整个互联网的眼睛。读取并搜索...
servers
# 模型上下文协议服务器