MadgicxMCP Docs

Google ADK

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

Google ADK

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://mcp.madgicx.com/oauth/token
MADGICX_MCP_URL=https://mcp.madgicx.com/mcp
 
# LLM provider
OPENAI_API_KEY=your_openai_key

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",
]

On this page