콘텐츠로 이동

ADK용 Mailgun MCP 도구

ADK에서 지원PythonTypeScriptGo

Mailgun MCP Server는 ADK 에이전트를 트랜잭션 이메일 서비스인 Mailgun과 연결합니다. 이 통합을 통해 에이전트는 자연어로 이메일 전송, 전달 지표 추적, 도메인/템플릿 관리, 메일링 리스트 처리를 수행할 수 있습니다.

사용 사례

  • 이메일 전송/관리: 트랜잭션 이메일 및 마케팅 이메일을 작성/전송하고, 저장 메시지를 조회하며, 기존 메시지를 재전송합니다.

  • 전달 성능 모니터링: 전달 통계를 조회하고, 반송 분류를 분석하며, 발신자 평판 유지를 위해 suppression 리스트를 검토합니다.

  • 이메일 인프라 관리: 도메인 DNS 구성 검증, 추적 설정 구성, 이메일 템플릿 생성, 인바운드 라우팅 규칙 설정을 수행합니다.

사전 준비 사항

에이전트와 함께 사용

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

MAILGUN_API_KEY = "YOUR_MAILGUN_API_KEY"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="mailgun_agent",
    instruction="Help users send emails and manage their Mailgun account",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "@mailgun/mcp-server",
                    ],
                    env={
                        "MAILGUN_API_KEY": MAILGUN_API_KEY,
                        # "MAILGUN_API_REGION": "eu",  # Optional: defaults to "us"
                    }
                ),
                timeout=30,
            ),
        )
    ],
)
import { LlmAgent, MCPToolset } from "@google/adk";

const MAILGUN_API_KEY = "YOUR_MAILGUN_API_KEY";

const rootAgent = new LlmAgent({
    model: "gemini-2.5-pro",
    name: "mailgun_agent",
    instruction: "Help users send emails and manage their Mailgun account",
    tools: [
        new MCPToolset({
            type: "StdioConnectionParams",
            serverParams: {
                command: "npx",
                args: ["-y", "@mailgun/mcp-server"],
                env: {
                    MAILGUN_API_KEY: MAILGUN_API_KEY,
                    // MAILGUN_API_REGION: "eu",  // Optional: defaults to "us"
                },
            },
        }),
    ],
});

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 mailgunAPIKey = "YOUR_MAILGUN_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", "@mailgun/mcp-server")
    // Forward only what npx needs, plus the Mailgun key. The parent environment
    // may hold unrelated secrets, such as the GOOGLE_API_KEY read above.
    server.Env = []string{
        "MAILGUN_API_KEY=" + mailgunAPIKey,
        // "MAILGUN_API_REGION=eu", // Optional: defaults to "us"
    }
    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)
        }
    }

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

    rootAgent, err := llmagent.New(llmagent.Config{
        Model:       model,
        Name:        "mailgun_agent",
        Instruction: "Help users send emails and manage their Mailgun account",
        Toolsets:    []tool.Toolset{mailgun},
    })
    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())
    }
}

사용 가능한 도구

메시징

도구 설명
send_email HTML 콘텐츠 및 첨부파일을 지원하는 이메일 전송
get_stored_message 저장된 이메일 메시지 조회
resend_message 이전에 보낸 메시지 재전송

도메인

도구 설명
get_domain 특정 도메인 상세 정보 조회
verify_domain 도메인 DNS 구성 검증
get_tracking_settings 추적 설정(클릭, 오픈, 수신거부) 조회
update_tracking_settings 도메인 추적 설정 업데이트

웹훅

도구 설명
list_webhooks 도메인의 이벤트 웹훅 목록 조회
create_webhook 새 이벤트 웹훅 생성
update_webhook 기존 웹훅 업데이트
delete_webhook 웹훅 삭제

라우트

도구 설명
list_routes 인바운드 이메일 라우팅 규칙 조회
update_route 인바운드 라우팅 규칙 업데이트

메일링 리스트

도구 설명
create_mailing_list 새 메일링 리스트 생성
manage_list_members 메일링 리스트 멤버 추가/삭제/업데이트

템플릿

도구 설명
create_template 새 이메일 템플릿 생성
manage_template_versions 템플릿 버전 생성/관리

분석 및 통계

도구 설명
query_metrics 날짜 범위별 발송/사용 지표 조회
get_logs 이메일 이벤트 로그 조회
get_stats 도메인, 태그, 제공자, 기기, 국가별 집계 통계 조회

Suppressions

도구 설명
get_bounces 반송 이메일 주소 조회
get_unsubscribes 수신 거부 이메일 주소 조회
get_complaints 클레임(불만) 기록 조회
get_allowlist allowlist 항목 조회

IP

도구 설명
list_ips IP 할당 정보 조회
get_ip_pools 전용 IP 풀 구성 조회

반송 분류

도구 설명
get_bounce_classification 반송 유형 및 전달 이슈 분석

구성

Variable Required Default Description
MAILGUN_API_KEY Yes — Mailgun API 키
MAILGUN_API_REGION No us API 리전: us 또는 eu

추가 리소스