Skip to main content
Glama
davsdevelop

DAVS Gmail MCP Server

by davsdevelop

📧 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 凭据配置(必填)

出于安全原因,本仓库不包含访问凭据。你必须生成自己的凭据:

  1. 前往 Google Cloud Console。

  2. 创建新项目并启用 Gmail API。

  3. 配置 OAuth 同意屏幕(将你的邮箱添加为测试用户)。

  4. 创建 OAuth 客户端 ID 类型的凭据(桌面应用程序)。

  5. 下载 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.py

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Gmail access through MCP, allowing LLMs to read, compose, and send emails.
    10
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Streamable HTTP MCP server for Gmail that enables AI agents to search threads, read messages, manage drafts, and organize the inbox via OAuth authentication.
    181 npm
    10
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that provides Gmail access for LLMs, enabling email composition, sending, searching, and label management via the Gmail API.
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables 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.
    -