コンテンツにスキップ

ADK 用 AgentMail MCP ツール

ADKでサポートPythonTypeScriptGo

AgentMail MCP Server は AI エージェント用に構築されたメールインボックス API である AgentMail を ADK エージェントに接続します。 この統合により、エージェントは自然言語で送受信、返信、転送を行える独自のメール インボックスを持てます。

使用ケース

  • エージェント専用インボックスを提供: エージェント向けに専用メールアドレスを作成し、 人間のチームメンバーのようにメールの送受信を独自で行えるようにします。

  • メールワークフローの自動化: 初期コンタクト送信、返信の読み取り、スレッド追跡を含め、 メール会話をエンドツーエンドで処理させます。

  • インボックス横断で会話を管理: スレッドとメッセージを検索・一覧表示し、メール転送や添付ファイル取得を行って エージェントが常時最新の状態を維持できるようにします。

前提条件

エージェントでの使用

from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters

AGENTMAIL_API_KEY = "YOUR_AGENTMAIL_API_KEY"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="agentmail_agent",
    instruction="Help users manage email inboxes and send messages",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "agentmail-mcp",
                    ],
                    env={
                        "AGENTMAIL_API_KEY": AGENTMAIL_API_KEY,
                    }
                ),
                timeout=30,
            ),
        )
    ],
)
import { LlmAgent, MCPToolset } from "@google/adk";

const AGENTMAIL_API_KEY = "YOUR_AGENTMAIL_API_KEY";

const rootAgent = new LlmAgent({
    model: "gemini-2.5-pro",
    name: "agentmail_agent",
    instruction: "Help users manage email inboxes and send messages",
    tools: [
        new MCPToolset({
            type: "StdioConnectionParams",
            serverParams: {
                command: "npx",
                args: ["-y", "agentmail-mcp"],
                env: {
                    AGENTMAIL_API_KEY: AGENTMAIL_API_KEY,
                },
            },
        }),
    ],
});

export { rootAgent };
package main

import (
    "context"
    "log"
    "os"
    "os/exec"

    "github.com/modelcontextprotocol/go-sdk/mcp"
    "google.golang.org/genai"

    "google.golang.org/adk/v2/agent"
    "google.golang.org/adk/v2/agent/llmagent"
    "google.golang.org/adk/v2/cmd/launcher"
    "google.golang.org/adk/v2/cmd/launcher/full"
    "google.golang.org/adk/v2/model/gemini"
    "google.golang.org/adk/v2/tool"
    "google.golang.org/adk/v2/tool/mcptoolset"
)

const agentMailAPIKey = "YOUR_AGENTMAIL_API_KEY"

func main() {
    ctx := context.Background()

    model, err := gemini.NewModel(ctx, "gemini-flash-latest", &genai.ClientConfig{
        APIKey: os.Getenv("GOOGLE_API_KEY"),
    })
    if err != nil {
        log.Fatalf("Failed to create the model: %v", err)
    }

    server := exec.CommandContext(ctx, "npx", "-y", "agentmail-mcp")
    // Forward only what npx needs, plus the AgentMail key. The parent environment
    // may hold unrelated secrets, such as the GOOGLE_API_KEY read above.
    server.Env = []string{"AGENTMAIL_API_KEY=" + agentMailAPIKey}
    for _, k := range []string{
        "PATH", "HOME", // POSIX
        "APPDATA", "LOCALAPPDATA", "TEMP", "USERPROFILE", // Windows
    } {
        if v, ok := os.LookupEnv(k); ok {
            server.Env = append(server.Env, k+"="+v)
        }
    }

    agentmail, err := mcptoolset.New(mcptoolset.Config{
        Transport: &mcp.CommandTransport{Command: server},
    })
    if err != nil {
        log.Fatalf("Failed to create the AgentMail tool set: %v", err)
    }

    rootAgent, err := llmagent.New(llmagent.Config{
        Model:       model,
        Name:        "agentmail_agent",
        Instruction: "Help users manage their inboxes and send emails with AgentMail",
        Toolsets:    []tool.Toolset{agentmail},
    })
    if err != nil {
        log.Fatalf("Failed to create the agent: %v", err)
    }

    l := full.NewLauncher()
    cfg := &launcher.Config{AgentLoader: agent.NewSingleLoader(rootAgent)}
    if err := l.Execute(ctx, cfg, os.Args[1:]); err != nil {
        log.Fatalf("Run failed: %v\n\n%s", err, l.CommandLineSyntax())
    }
}

利用可能なツール

インボックス管理

ツール 説明
list_inboxes すべてのインボックスを一覧表示します。
get_inbox 特定のインボックスの詳細を取得します。
create_inbox ユーザー名とドメインを指定して新しいインボックスを作成します。
delete_inbox インボックスを削除します。

スレッド管理

ツール 説明
list_threads インボックス内のスレッドを一覧します。
get_thread 特定のスレッドとメッセージを取得します。
get_attachment メッセージから添付ファイルをダウンロードします。

メッセージ操作

ツール 説明
send_message 新しいメールをインボックスから送信します。
reply_to_message 既存メッセージへ返信します。
forward_message メッセージを別の受信者へ転送します。
update_message 既読状態などのメッセージ属性を更新します。

追加リソース