Looker के साथ इंटरैक्ट करने के लिए, Google ADK और MCP की मदद से एआई एजेंट बनाना

1. खास जानकारी

इस कोडलैब में, आपको Google Agent Development Kit (ADK) और डेटाबेस के लिए एमसीपी टूलबॉक्स का इस्तेमाल करके, एक इंटरैक्टिव एआई एजेंट बनाना होगा. इससे आपको अपने Looker इंस्टेंस के साथ इंटरैक्ट करने में मदद मिलेगी.

Google Agent Development Kit (एडीके) की मदद से बनाए गए Looker एआई एजेंट का इंटिग्रेशन स्टैक. यह ओपन-सोर्स एमसीपी सर्वर के ज़रिए कनेक्ट होता है, ताकि Looker API को ऐक्सेस किया जा सके.

एडीके और एमसीपी क्या है?

  • Google ADK (Agent Development Kit): यह Gemini की मदद से काम करने वाले, कई टूल वाले एलएलएम एजेंट बनाने, टेस्ट करने, और उन्हें मैनेज करने के लिए एक आसान फ़्रेमवर्क है.
  • मॉडल कॉन्टेक्स्ट प्रोटोकॉल (एमसीपी): यह एक ओपन स्टैंडर्ड है. इसकी मदद से, एलएलएम को बाहरी टूल, डेटाबेस, और एपीआई से सुरक्षित तरीके से कनेक्ट किया जा सकता है. इसके लिए, कस्टम अडैप्टर कोड की ज़रूरत नहीं होती.

आपको क्या बनाना होगा

  • Gemini 3.8 Flash की मदद से काम करने वाला, Python पर आधारित लोकल एजेंट.
  • Looker से कनेक्ट करने के लिए, एमसीपी टूलबॉक्स इंटिग्रेशन.
  • इंटरैक्टिव ADK लोकल वेब यूआई की मदद से टेस्ट किया गया एक रनिंग एजेंट.

ज़रूरी शर्तें

  • एपीआई क्रेडेंशियल जनरेट करने के लिए, एडमिन या डेवलपर की अनुमतियों वाला Looker इंस्टेंस.
  • Python 3.10 या इसके बाद का वर्शन इंस्टॉल किया गया हो.
  • Go 1.21+ इंस्टॉल किया गया हो (toolbox बाइनरी को बनाने/इंस्टॉल करने के लिए).
  • Google Gemini API पासकोड या Vertex AI की सुविधा वाला Google Cloud प्रोजेक्ट.

2. Looker API के क्रेडेंशियल सुरक्षित करना

एमसीपी सर्वर को आपके Looker इंस्टेंस के साथ पुष्टि करने की अनुमति देने के लिए, आपके पास एपीआई 3 क्रेडेंशियल होने चाहिए.

  1. अपने Looker इंस्टेंस में लॉग इन करें.
  2. एडमिन > उपयोगकर्ता पर जाएं. अगर क्रेडेंशियल जनरेट करने की सुविधा चालू है, तो खाते की सेटिंग पर जाएं.
  3. अपना उपयोगकर्ता खाता ढूंढें और बदलाव करें को चुनें.
  4. API 3 Keys सेक्शन में, New API Key पर क्लिक करें.
  5. जनरेट किए गए क्लाइंट आईडी और क्लाइंट सीक्रेट को सेव करें.

[चेतावनी] अपने क्लाइंट सीक्रेट को सुरक्षित रखें. वर्शन कंट्रोल के लिए, अपनी .env फ़ाइल को कभी भी कमिट न करें.

3. अपना डेवलपमेंट एनवायरमेंट सेट अप करना और एमसीपी टूलबॉक्स इंस्टॉल करना

प्रोजेक्ट डायरेक्ट्री बनाएं, Python वर्चुअल एनवायरमेंट सेट अप करें, और Go का इस्तेमाल करके ज़रूरी MCP टूलबॉक्स बाइनरी इंस्टॉल करें.

प्रोजेक्ट डायरेक्ट्री और वर्चुअल एनवायरमेंट बनाना

mkdir looker-mcp-agent && cd looker-mcp-agent
python3 -m venv .venv
source .venv/bin/activate

Python डिपेंडेंसी इंस्टॉल करना

Google ADK, MCP क्लाइंट SDK, और Python एनवायरमेंट मैनेजर इंस्टॉल करें:

pip install google-adk mcp python-dotenv

Go का इस्तेमाल करके, एमसीपी टूलबॉक्स बाइनरी इंस्टॉल करें

एमसीपी कनेक्शन, एमसीपी टूलबॉक्स बाइनरी (toolbox) पर निर्भर करता है. इसे सीधे go install का इस्तेमाल करके इंस्टॉल किया जा सकता है:

# Install the MCP toolbox binary from source
go install github.com/googleapis/genai-toolbox/cmd/toolbox@latest

पुष्टि करें कि बाइनरी को आपकी $(go env GOPATH)/bin डायरेक्ट्री में इंस्टॉल किया गया है:

# Check if MCP toolbox is in your Go bin
ls $(go env GOPATH)/bin/toolbox

अपनी स्क्रिप्ट को आसानी से रेफ़रंस देने के लिए, पक्का करें कि $(go env GOPATH)/bin आपके $PATH पर हो या बाइनरी को अपनी प्रोजेक्ट डायरेक्ट्री में कॉपी/सिमलिंक करें:

# Symlink or copy the MCP toolbox into your current project directory
cp $(go env GOPATH)/bin/toolbox ./toolbox
chmod +x ./toolbox

4. एनवायरमेंट वैरिएबल कॉन्फ़िगर करना

looker-mcp-agent/ के रूट में .env फ़ाइल बनाएं:

LOOKER_BASE_URL="https://your-looker-instance.com"
LOOKER_CLIENT_ID="your_client_id"
LOOKER_CLIENT_SECRET="your_client_secret"
GEMINI_API_KEY="your_gemini_api_key"

पुष्टि करें कि .env आपकी .gitignore फ़ाइल में मौजूद है.

ध्यान दें: OAuth के ज़रिए भी Looker से कनेक्ट किया जा सकता है

5. tools.yaml में टूल तय करना

tools.yaml क्या है?

tools.yaml, एमसीपी टूलबॉक्स (toolbox) के लिए डिक्लेरेटिव कॉन्फ़िगरेशन मेनिफ़ेस्ट है. Looker API के साथ इंटरैक्ट करने के लिए, कस्टम बॉयलरप्लेट या मैन्युअल एचटीटीपी हैंडलर लिखने के बजाय, एमसीपी टूलबॉक्स tools.yaml का इस्तेमाल करता है. इससे Looker की सुविधाओं को आपके एलएलएम एजेंट के लिए, स्टैंडर्ड मॉडल कॉन्टेक्स्ट प्रोटोकॉल (एमसीपी) टूल के तौर पर डाइनैमिक तरीके से दिखाया जाता है.

इसके दो मुख्य मकसद हैं:

  1. यह आपके Looker इंस्टेंस के कनेक्शन को कॉन्फ़िगर करता है. जैसे, एंडपॉइंट यूआरएल, पुष्टि करने वाले क्रेडेंशियल, प्रोजेक्ट, जगह की जानकारी, और टाइम आउट.
  2. इससे यह तय होता है कि एमसीपी सर्वर, Gemini को Looker की कौनसी सुविधाएं उपलब्ध कराएगा. जैसे, कनेक्शन की सूची बनाना, डैशबोर्ड बनाना, और क्वेरी चलाना. साथ ही, इसमें नैचुरल लैंग्वेज में ब्यौरे शामिल होते हैं. Gemini इनका इस्तेमाल, टूल चुनने और आर्ग्युमेंट जनरेट करने के लिए करता है.

फ़ाइल की जगह: प्रोजेक्ट रूट में tools.yaml को डालना

tools.yaml फ़ाइल, प्रोजेक्ट की रूट डायरेक्ट्री (basic_looker_agent/ की पैरंट डायरेक्ट्री) में होनी चाहिए. यह basic_looker_agent/ सबडायरेक्ट्री में नहीं होनी चाहिए.

प्रोजेक्ट डायरेक्ट्री का स्ट्रक्चर ऐसा होना चाहिए:

looker-mcp-agent/                 <-- Project root directory
├── tools.yaml                    <-- Place tools.yaml here!
├── toolbox                       <-- MCP Toolbox binary executable
└── basic_looker_agent/           <-- Agent package directory created by ADK
    ├── .env                      <-- Local environment variables (keys & credentials)
    ├── __init__.py
    └── agent.py                  <-- Agent code (references ../tools.yaml)

प्रोजेक्ट रूट में क्यों? agent.py में, एजेंट ../tools.yaml (basic_looker_agent/ से एक डायरेक्ट्री ऊपर) के ज़रिए एमसीपी सर्वर कॉन्फ़िगरेशन को रिज़ॉल्व करता है. tools.yaml को प्रोजेक्ट रूट में रखने से, आपके एमसीपी टूल की परिभाषाएं और डेटा सोर्स, आपके Python एजेंट कोड से साफ़ तौर पर अलग हो जाते हैं. अगर tools.yaml को basic_looker_agent/ में रखा जाता है, तो एजेंट उसे नहीं ढूंढ पाएगा.

sources:
  my-looker-source:
    kind: looker
    base_url: https://your-looker-instance.com
    client_id: $LOOKER_CLIENT_ID
    client_secret: $LOOKER_CLIENT_SECRET
    project: your-looker-project
    location: us-east1
    verify_ssl: true
    timeout: 600s

tools:
    get_connections:
        kind: looker-get-connections
        source: my-looker-source
        description: |
          This tool retrieves a list of all database connections configured in the Looker system.

          Parameters:
          This tool takes no parameters.

          Output:
          A JSON array of objects, each representing a database connection.
    create_dashboard:
        kind: looker-make-dashboard
        source: my-looker-source
        description: |
          This tool creates a dashboard from a prompt.

ध्यान दें: $LOOKER_CLIENT_ID और $LOOKER_CLIENT_SECRET प्लेसहोल्डर, एमसीपी सर्वर प्रोसेस में पास किए गए एनवायरमेंट से अपने-आप रिज़ॉल्व हो जाएंगे.

6. एजेंट को लागू करना

agent.py नाम की फ़ाइल बनाएं. यह स्क्रिप्ट, एमसीपी सर्वर की प्रोसेस को एडीके LlmAgent से कनेक्ट करती है.

import os
from dotenv import load_dotenv
from mcp import StdioServerParameters
from google.adk.agents import LlmAgent
from google.adk.tools import MCPToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams

# Load environment variables
load_dotenv()

# Configure MCP Stdio server parameters
base_dir = os.path.dirname(os.path.abspath(__file__))
# Reference the toolbox binary in your project root or from GOPATH
toolbox_path = os.path.abspath(os.path.join(base_dir, "toolbox"))
tools_path = os.path.abspath(os.path.join(base_dir, "tools.yaml"))

looker_server = StdioServerParameters(
    command=toolbox_path,
    args=["--stdio", "--tools-file", tools_path],
    env={
        "LOOKER_BASE_URL": os.getenv("LOOKER_BASE_URL"),
        "LOOKER_CLIENT_ID": os.getenv("LOOKER_CLIENT_ID"),
        "LOOKER_CLIENT_SECRET": os.getenv("LOOKER_CLIENT_SECRET"),
    },
)

# Create the ADK MCP Toolset
looker_toolset = MCPToolset(
    connection_params=StdioConnectionParams(server_params=looker_server)
)

# Define the root LLM Agent
root_agent = LlmAgent(
    model="gemini-3.8-flash",
    name="looker_pro",
    description="A helpful assistant that queries Looker and uses mcp-toolbox-for-databases.",
    instruction="You are a helpful assistant that retrieves Looker connection information and assists users with available Looker tools.",
    tools=[looker_toolset],
)

7. एजेंट को चलाना और उसकी जांच करना

एडीके में पहले से मौजूद डेवलपमेंट वेब इंटरफ़ेस होता है.

ADK वेब सर्वर लॉन्च करना

अपनी प्रोजेक्ट डायरेक्ट्री से यह कमांड चलाएं:

adk web
``` This will spin up a lightweight locally hosted server to
review your agent.

### Interact with Your Agent

1.  Open the URL printed in the terminal (typically `http://localhost:8080` or
    `http://127.0.0.1:8000`).
2.  Test tool discovery by prompting the agent:

आपके पास कौन-कौनसे टूल उपलब्ध हैं?

    inspect its toolset and report the `get_connections` and the
    `create_dashboard` tool.

3.  Test tool execution:

क्या मुझे Looker में डेटाबेस कनेक्शन दिखाए जा सकते हैं?

" class="language->">    Response: The agent will invoke `get_connections` over MCP and list your
    instance's active database connections.

---

## Congratulations & Next Steps

Duration: 1:00

You have built an AI agent using Google ADK connected to Looker via the Model
Context Protocol (MCP).

### What you learned:

*   How to install and configure `toolbox` using `go install`.
*   How to configure Looker API credentials for external integrations.
*   How to define MCP sources and tools in `tools.yaml`.
*   How to link an MCP toolset to an ADK `LlmAgent`.
*   How to test tool invocation in the ADK web interface.

### Next Steps:

*   Create a dashboard with the agent defined in the codelab.
*   Add more [Looker tools](https://mcp-toolbox.dev/integrations/looker/source/)
    to `tools.yaml` (such as `looker-query`, `looker-run-look`).
*   Check out [Google ADK Documentation](https://github.com/google/adk) for
    multi-agent routing and state persistence.