Research & Benchmarks Optimization AI Ads Analytics Why Madgicx? About Us Blog Careers Case Studies Events Glossary Guides Answers Pricing Login Try for Free
MCP docs menu

Connect Google ADK to Madgicx MCP

Connect Madgicx MCP to Google Agent Development Kit using client credentials authentication.

Build agents with Google's Agent Development Kit (ADK) that have access to all Madgicx MCP tools.

Prerequisites

Installation

pip install google-adk[extensions] litellm python-dotenv requests

Setup

1. Configure environment variables

# .env
MADGICX_CLIENT_ID=your_client_id
MADGICX_CLIENT_SECRET=your_client_secret
MADGICX_TOKEN_URL=https://app.madgicx.com/o/token/

# Choose ONE of the MCP server URLs (or attach two MCPToolset instances to use both):
MADGICX_MCP_URL=https://mcp.madgicx.com/mcp                # Facebook Ads
# MADGICX_MCP_URL=https://mcp-google-ads.madgicx.com/mcp   # Google Ads

# LLM provider
OPENAI_API_KEY=your_openai_key

Connecting to both MCP servers

To use both Facebook Ads and Google Ads tools in the same agent, instantiate two MCPToolset objects (one per URL) and pass both into tools=[fb_toolset, google_toolset]. The same auth.headers works for both.

2. Add the auth helper

Copy the MadgicxConfidentialClientAuth helper into your project as auth.py. You can also create a custom auth handler if your setup requires different authentication logic.

3. Create the agent

import asyncio
import os

from dotenv import load_dotenv

load_dotenv()

from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from google.adk.runners import InMemoryRunner
from google.adk.tools.mcp_tool import MCPToolset, StreamableHTTPConnectionParams
from google.genai import types as genai_types

from auth import MadgicxConfidentialClientAuth

MADGICX_MCP_URL = os.getenv("MADGICX_MCP_URL", "https://mcp.madgicx.com/mcp")


async def main():
    auth = MadgicxConfidentialClientAuth()

    model = LiteLlm(
        model="gpt-4o",
    )

    mcp_toolset = MCPToolset(
        connection_params=StreamableHTTPConnectionParams(
            url=MADGICX_MCP_URL,
            headers=auth.headers,
        ),
    )

    agent = LlmAgent(
        model=model,
        name="marketing_expert",
        instruction="You are a Facebook Marketing Expert powered by Madgicx tools.",
        tools=[mcp_toolset],
    )

    runner = InMemoryRunner(agent=agent, app_name="MadgicxMCP")
    runner.auto_create_session = True

    message = genai_types.Content(
        role="user",
        parts=[genai_types.Part(text="What ad accounts do I have access to?")],
    )

    async for event in runner.run_async(
        user_id="user_1",
        session_id="session_1",
        new_message=message,
    ):
        if event.content and event.content.parts:
            for part in event.content.parts:
                if part.text:
                    print(part.text)

    await runner.close()


if __name__ == "__main__":
    asyncio.run(main())

How It Works

  1. MadgicxConfidentialClientAuth obtains an access token using your client credentials
  2. The token is passed via StreamableHTTPConnectionParams headers
  3. MCPToolset discovers all Madgicx tools and makes them available to the ADK agent
  4. The InMemoryRunner manages conversation sessions and agent execution

Dependencies

[project]
requires-python = ">=3.10,<3.14"
dependencies = [
    "google-adk[extensions]>=1.0.0",
    "litellm>=1.60.0",
    "python-dotenv>=1.0.0",
    "requests>=2.31.0",
]
Official Meta Business Partner

Connect your AI assistant to your ad accounts. The 7-day free trial includes both MCPs.

Sign in with your Madgicx login, add the server addresses and ask in plain words. Meta changes wait for your confirmation, and the Google Ads MCP only reads.

Try for Free ($0 Trial)
200,000+ advertisers
$10B+ annual ad spend visibility
4.6 / 5 on G2, from 220+ reviews