DAVS Gmail MCP Server
📧 Gmail AI 助手与模型上下文协议(MCP)
本项目实现了一个能够直接与 Gmail 账户交互的智能助手,利用模型上下文协议(Model Context Protocol,MCP)。
它展示了本地 LLM(Ollama)与外部 API(Google Workspace)的安全集成,使模型能够读取、摘要和发送邮件,并通过动态模板消费静态资源(PDF),全部在标准化的客户端-服务器架构下运行。
🏗️ 系统架构
MCP 服务器(
gmail_mcp_server.py): 向客户端暴露工具(Tools)、静态和动态资源(Resources/Resource Templates)以及预定义提示词。处理与 Google Cloud 的 OAuth2 认证。MCP 客户端(
client.py): 连接到 MCP 服务器,发现可用能力,并动态格式化,使语言模型(Llama 3.1)能够将其用作函数调用(Function Calling)。图形界面(
app.py): 使用 Streamlit 构建的交互式应用程序,管理对话历史,根据服务器响应渲染动态 UI 组件,并支持快速提示词的使用。安全性: 严格的凭据管理。认证在本地完成,会话令牌保持在运行时环境中,不对外暴露。
Related MCP server: Gmail Streamable MCP Server
✨ 代理能力
工具(Tools):
list_emails(搜索和过滤)和send_email(撰写和发送)。资源(Resources): 访问用户的 Gmail 个人资料。
模板(Resource Templates): 从本地 PDF 手册中读取并注入上下文(例如
docs://setup-manual/{version})直接进入 LLM 上下文。提示词(Prompts): 预构建的流程,用于每日摘要和专业邮件撰写。
🚀 安装与配置
前置条件
Python 3.10+
已安装 Ollama 并带有
llama3.1模型。一个 Google Cloud Platform(GCP)账户。
1. Google 凭据配置(必填)
出于安全原因,本仓库不包含访问凭据。你必须生成自己的凭据:
创建新项目并启用 Gmail API。
配置 OAuth 同意屏幕(将你的邮箱添加为测试用户)。
创建 OAuth 客户端 ID 类型的凭据(桌面应用程序)。
下载 JSON 文件,将其重命名为
credentials.json,并放置在本项目的根目录中。
2. 环境运行
# Clonar repositorio
git clone [https://github.com/tu-usuario/gmail-mcp-server.git](https://github.com/tu-usuario/gmail-mcp-server.git)
cd gmail-mcp-server
# Crear entorno virtual e instalar dependencias
python -m venv venv
source venv/bin/activate # En Windows: venv\Scripts\activate
pip install -r requirements.txt
# Iniciar la interfaz gráfica
streamlit run app.pyThis server cannot be deployed
Maintenance
Related MCP Connectors
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Remote streamable-HTTP MCP server running on a single Cloudflare Worker. Your assistant gets live Airbnb, Amazon, Booking.com, Google Flights, Maps and Reddit data, social search on X, Instagram and TikTok, the Meta Ad Library, and image/video generation without any keys. Connect your own accounts to let it send WhatsApp or Telegram messages, work an IMAP inbox, manage Meta Ads campaigns and publish to X and LinkedIn. OAuth 2.1 with PKCE; stored credentials are AES-256-GCM encrypted.
MCP server connecting AI agents to 100+ apps (Gmail, Slack, Notion, GitHub) via one-click OAuth.
Let Claude or ChatGPT search, read and send your WhatsApp messages over MCP. OAuth sign-in.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Gmail access through MCP, allowing LLMs to read, compose, and send emails.10MIT
- AlicenseNot gradedqualityCmaintenanceStreamable HTTP MCP server for Gmail that enables AI agents to search threads, read messages, manage drafts, and organize the inbox via OAuth authentication.181 npm10MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that provides Gmail access for LLMs, enabling email composition, sending, searching, and label management via the Gmail API.MIT
- FlicenseNot gradedqualityDmaintenanceEnables users to access and manage their Gmail and Google Drive data via a Streamlit UI or Claude Desktop, supporting email counts, searches, file listings, and storage queries using OAuth authentication.-