Skip to main content
Glama

模型上下文协议(MCP)

所有版权归于: https://github.com/ShawhinT/YouTube-Blog/

这是 AI 代理系列的第四个示例。在这里,我构建了一个客户端 MCP 服务器,以便任何 AI 应用都可以访问人工智能虚拟助手 (AVA) 的工具集。

链接

如何运行此示例

  1. 克隆此 repo

  2. 如果还没有安装uv,请先安装

# Mac/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. 在开发模式下测试服务器

uv run mcp dev mcp-server-example.py
  1. 将服务器配置添加到 AI 应用程序(例如 Claude Desktop 或 Cursor)。

{
  "mcpServers": {
    "AVA": {
      "command": "/Users/shawhin/.local/bin/uv", # replace with global path to your uv installation
      "args": [
        "--directory",
        "/Users/shawhin/Documents/_code/_stv/sandbox/ava-mcp/", # replace with global path to repo
        "run",
        "mcp-server-example.py"
      ]
    }
  }
}

Related MCP server: Gmail AutoAuth MCP Server

自定义 AVA 的行为

更新个人信息和偏好

  1. 在项目目录中找到prompts/ava.md文件

  2. 使用以下方式自定义文件:

    • 沟通偏好

    • 处理任务的具体说明

    • AVA 的任何其他相关指南

环境设置(.env)

  1. 在项目根目录中创建一个.env文件,其中包含以下变量:

USER_EMAIL=your_email_address

# Google OAuth Credentials
GOOGLE_CREDENTIALS_PATH=.config/ava-agent/credentials.json
GOOGLE_TOKEN_PATH=.config/ava-agent/token.json

所需的环境变量:

  • USER_EMAIL :您要用于此应用程序的 Gmail 地址

  • GOOGLE_CREDENTIALS_PATH :您的 Google OAuth 凭据文件的路径

  • GOOGLE_TOKEN_PATH :存储 Google OAuth 令牌的路径

Google OAuth 设置

1.创建项目目录结构

首先,创建所需的目录结构:

mkdir -p .config/ava-agent

2. 设置 Google Cloud 项目

  1. 前往Google Cloud Console

  2. 创建新项目或选择现有项目

  3. 启用 Gmail API:

    • 在导航菜单中,转到“API 和服务”>“库”

    • 搜索“Gmail API”

    • 点击“启用”

3.创建OAuth凭证

  1. 在 Google Cloud Console 中:

    • 前往“API 和服务”>“凭证”

    • 点击“创建凭证”>“OAuth 客户端 ID”

    • 选择“桌面应用程序”作为应用程序类型

    • 给它起一个名字(例如,“AVA Gmail 客户端”)

    • 点击“创建”

  2. 下载凭证:

    • 创建完成后,点击“下载JSON”

    • 将下载的文件保存为.config/ava-agent/中的credentials.json

    • 该文件应包含您的客户端 ID 和客户端密钥

4. 配置 OAuth 同意屏幕

  1. 在 Google Cloud Console 中:

    • 前往“API 和服务”>“OAuth 同意屏幕”

    • 选择“外部”用户类型

    • 填写所需信息:

      • 应用程序名称

      • 用户支持电子邮件

      • 开发者联系信息

    • 添加 Gmail API 范围: https://www.googleapis.com/auth/gmail.modify

    • 将您的电子邮件添加为测试用户

    • 完成配置

登录 Google

在服务器访问你的 Gmail 账户之前,你需要先授权。你可以运行uv run oauth.py来执行此操作,它会执行以下操作。

  1. 检查token.json是否存在

  2. 如果未找到,它将启动 Google OAuth 身份验证流程

  3. 指导您完成浏览器中的身份验证过程:

    • 系统会要求您登录 Google 帐户

    • 授予请求的权限

    • 应用程序将自动保存令牌

  4. 自动生成并存储令牌

安全说明

文件保护

  • 切勿将.env文件或token.json提交到版本控制

  • 确保您的 Google 凭据安全

  • 将以下内容添加到您的.gitignore中:

    .env
    .config/ava-agent/token.json
    .config/ava-agent/credentials.json

Available Tools

1 tool
write_email_draftA

Create a draft email using the Gmail API.

Args:
    recipient_email (str): The email address of the recipient.
    subject (str): The subject line of the email.
    body (str): The main content/body of the email.

Returns:
    dict or None: A dictionary containing the draft information including 'id' and 'message' 
                 if successful, None if an error occurs.

Raises:
    HttpError: If there is an error communicating with the Gmail API.
    
Note:
    This function requires:
    - Gmail API credentials to be properly configured
    - USER_EMAIL environment variable to be set with the sender's email address
    - Appropriate Gmail API permissions for creating drafts

Inputs: recipient_email (required), subject (required), body (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 1 tool

    Disambiguation5/5

    With only one tool, there is no possibility of confusion or overlap between tools. The tool's purpose is singular and clearly defined as creating email drafts via Gmail API.

    Naming Consistency5/5

    The single tool name follows a clear verb_noun pattern (write_email_draft). With only one tool, consistency is inherently perfect as there are no other names to compare against.

    Tool Count2/5

    A single tool is insufficient for an email/Gmail server's scope. Basic email operations like sending, reading, listing, or deleting emails are missing, making this server feel incomplete and thin for its apparent domain.

    Completeness2/5

    The server is severely incomplete for email management. While write_email_draft covers draft creation, it lacks essential operations like send_email, list_emails, get_email, delete_email, or manage labels, creating significant gaps that will cause agent failures.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that provides AI applications with a toolset for an Artificial Virtual Assistant (AVA) integrated with the Gmail API. It enables users to automate email management and personal tasks through secure Google OAuth authentication.
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      An MCP server enabling AI assistants to manage Gmail through natural language, including sending, reading, searching, labeling, and handling attachments with auto authentication.
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that enables AI assistants to interact with Google Calendar and Gmail, allowing users to manage events, send emails, and organize their inbox through natural language.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An MCP-compliant server that exposes Gmail and Google Docs as tools, enabling AI agents to draft, send, and manage emails, as well as create, read, and append to documents through natural language.
      9
      MIT