Cloud Run पर सुरक्षित MCP सर्वर को डिप्लॉय करने का तरीका

1. परिचय

खास जानकारी

इस लैब में, मॉडल कॉन्टेक्स्ट प्रोटोकॉल (एमसीपी) सर्वर बनाया और डिप्लॉय किया जाएगा. एमसीपी सर्वर, एलएलएम को बाहरी टूल और सेवाओं का ऐक्सेस देने के लिए फ़ायदेमंद होते हैं. आपको इसे Cloud Run पर एक सुरक्षित और प्रोडक्शन के लिए तैयार सेवा के तौर पर कॉन्फ़िगर करना होगा. इसे कई क्लाइंट ऐक्सेस कर सकते हैं. इसके बाद, Gemini CLI से रिमोट एमसीपी सर्वर से कनेक्ट करें.

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

हम FastMCP का इस्तेमाल करके, zoo MCP सर्वर बनाएंगे. इसमें दो टूल होंगे: get_animals_by_species और get_animal_details. FastMCP, MCP सर्वर और क्लाइंट बनाने का एक तेज़ और Pythonic तरीका है.

Zoo MCP Server का ग्राफ़िक

आपको क्या सीखने को मिलेगा

  • MCP सर्वर को Cloud Run पर डिप्लॉय करें.
  • अपने सर्वर के एंडपॉइंट को सुरक्षित करें. इसके लिए, सभी अनुरोधों के लिए पुष्टि करने की सुविधा चालू करें. इससे यह पक्का किया जा सकेगा कि सिर्फ़ मंज़ूरी पा चुके क्लाइंट और एजेंट ही उससे कम्यूनिकेट कर पाएं.
  • Gemini CLI से अपने सुरक्षित एमसीपी सर्वर एंडपॉइंट से कनेक्ट करना

2. प्रोजेक्ट सेटअप करना

  1. अगर आपके पास पहले से कोई Google खाता नहीं है, तो आपको Google खाता बनाना होगा.
    • ऑफ़िस या स्कूल वाले खाते के बजाय, निजी खाते का इस्तेमाल करें. ऑफ़िस और स्कूल वाले खातों पर कुछ पाबंदियां हो सकती हैं. इनकी वजह से, इस लैब के लिए ज़रूरी एपीआई चालू नहीं किए जा सकते.
  2. Google Cloud Console में साइन इन करें.
  3. Cloud Console में बिलिंग चालू करें.
    • इस लैब को पूरा करने में, Cloud संसाधनों पर 1 डॉलर से कम का खर्च आना चाहिए.
    • ज़्यादा शुल्क से बचने के लिए, इस लैब के आखिर में दिए गए निर्देशों का पालन करके संसाधनों को मिटाया जा सकता है.
    • नए उपयोगकर्ता, 300 डॉलर के मुफ़्त क्रेडिट पा सकते हैं.
  4. नया प्रोजेक्ट बनाएं या किसी मौजूदा प्रोजेक्ट का फिर से इस्तेमाल करें.

3. Cloud Shell Editor खोलें

  1. सीधे Cloud Shell Editor पर जाने के लिए, इस लिंक पर क्लिक करें
  2. अगर आज किसी भी समय अनुमति देने के लिए कहा जाता है, तो जारी रखने के लिए अनुमति दें पर क्लिक करें. Cloud Shell को अनुमति देने के लिए क्लिक करें
  3. अगर टर्मिनल स्क्रीन पर सबसे नीचे नहीं दिखता है, तो इसे खोलें:
    • देखें पर क्लिक करें
    • टर्मिनलCloud Shell Editor में नया टर्मिनल खोलें पर क्लिक करें
  4. टर्मिनल में, इस निर्देश का इस्तेमाल करके अपना प्रोजेक्ट सेट करें:
    • फ़ॉर्मैट:
      gcloud config set project [PROJECT_ID]
      
    • उदाहरण:
      gcloud config set project lab-project-id-example
      
    • अगर आपको अपना प्रोजेक्ट आईडी याद नहीं है, तो:
      • अपने सभी प्रोजेक्ट आईडी की सूची देखने के लिए, यह तरीका अपनाएं:
        gcloud projects list | awk '/PROJECT_ID/{print $2}'
        
      Cloud Shell Editor के टर्मिनल में प्रोजेक्ट आईडी सेट करना
  5. आपको यह मैसेज दिखेगा:
    Updated property [core/project].
    
    अगर आपको WARNING दिखता है और आपसे Do you want to continue (Y/n)? पूछा जाता है, तो इसका मतलब है कि आपने प्रोजेक्ट आईडी गलत डाला है. n दबाएं, Enter दबाएं, और gcloud config set project कमांड को फिर से चलाने की कोशिश करें.

4. एपीआई चालू करें

टर्मिनल में, इन एपीआई को चालू करें:

gcloud services enable \
  run.googleapis.com \
  artifactregistry.googleapis.com \
  cloudbuild.googleapis.com

अगर अनुमति देने के लिए कहा जाए, तो जारी रखने के लिए अनुमति दें पर क्लिक करें. Cloud Shell को अनुमति देने के लिए क्लिक करें

इस कमांड को पूरा होने में कुछ मिनट लग सकते हैं. हालांकि, आखिर में आपको इस तरह का मैसेज दिखेगा:

Operation "operations/acf.p2-73d90d00-47ee-447a-b600" finished successfully.

5. अपना Python प्रोजेक्ट तैयार करना

  1. डिप्लॉयमेंट के लिए सोर्स कोड सेव करने के लिए, mcp-on-cloudrun नाम का फ़ोल्डर बनाएं:
      mkdir mcp-on-cloudrun && cd mcp-on-cloudrun
    
  2. pyproject.toml फ़ाइल जनरेट करने के लिए, uv टूल का इस्तेमाल करके Python प्रोजेक्ट बनाएं:
      uv init --description "Example of deploying an MCP server on Cloud Run" --bare --python 3.13
    
    uv init कमांड, आपके प्रोजेक्ट के लिए pyproject.toml फ़ाइल बनाती है.फ़ाइल का कॉन्टेंट देखने के लिए, यह कमांड चलाएं:
    cat pyproject.toml
    
    आउटपुट ऐसा दिखना चाहिए:
    [project]
    name = "mcp-on-cloudrun"
    version = "0.1.0"
    description = "Example of deploying an MCP server on Cloud Run"
    requires-python = ">=3.13"
    dependencies = []
    

6. ज़ू एमसीपी सर्वर बनाना

एमसीपी के साथ एलएलएम के इस्तेमाल को बेहतर बनाने के लिए, अहम कॉन्टेक्स्ट उपलब्ध कराएं. इसके लिए, FastMCP के साथ एक ज़ू एमसीपी सर्वर सेट अप करें. यह मॉडल कॉन्टेक्स्ट प्रोटोकॉल के साथ काम करने के लिए एक स्टैंडर्ड फ़्रेमवर्क है. FastMCP, Python की मदद से MCP सर्वर और क्लाइंट बनाने का एक तेज़ तरीका है. यह एमसीपी सर्वर, एक काल्पनिक चिड़ियाघर में मौजूद जानवरों के बारे में डेटा उपलब्ध कराता है. आसानी के लिए, हम डेटा को मेमोरी में सेव करते हैं. प्रोडक्शन एमसीपी सर्वर के लिए, आपको डेटाबेस या एपीआई जैसे सोर्स से डेटा देना होगा.

  1. pyproject.toml फ़ाइल में FastMCP को डिपेंडेंसी के तौर पर जोड़ने के लिए, यह कमांड चलाएं:
    uv add fastmcp==2.11.1 --no-sync
    
    इससे आपके प्रोजेक्ट में एक uv.lock फ़ाइल जुड़ जाएगी.
  2. एमसीपी सर्वर के सोर्स कोड के लिए, नई server.py फ़ाइल बनाएं और उसे खोलें:
    cloudshell edit server.py
    
    cloudshell edit कमांड, टर्मिनल के ऊपर मौजूद एडिटर में server.py फ़ाइल खोलेगी.
  3. server.py फ़ाइल में, नीचे दिया गया zoo MCP सर्वर का सोर्स कोड जोड़ें:
    import asyncio
    import logging
    import os
    from typing import List, Dict, Any
    
    from fastmcp import FastMCP
    
    logger = logging.getLogger(__name__)
    logging.basicConfig(format="[%(levelname)s]: %(message)s", level=logging.INFO)
    
    mcp = FastMCP("Zoo Animal MCP Server 🦁🐧🐻")
    
    # Dictionary of animals at the zoo
    ZOO_ANIMALS = [
        {
            "species": "lion",
            "name": "Leo",
            "age": 7,
            "enclosure": "The Big Cat Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "lion",
            "name": "Nala",
            "age": 6,
            "enclosure": "The Big Cat Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "lion",
            "name": "Simba",
            "age": 3,
            "enclosure": "The Big Cat Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "lion",
            "name": "King",
            "age": 8,
            "enclosure": "The Big Cat Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "penguin",
            "name": "Waddles",
            "age": 2,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "penguin",
            "name": "Pip",
            "age": 4,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "penguin",
            "name": "Skipper",
            "age": 5,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "penguin",
            "name": "Chilly",
            "age": 3,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "penguin",
            "name": "Pingu",
            "age": 6,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "penguin",
            "name": "Noot",
            "age": 1,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "elephant",
            "name": "Ellie",
            "age": 15,
            "enclosure": "The Pachyderm Sanctuary",
            "trail": "Savannah Heights"
        },
        {
            "species": "elephant",
            "name": "Peanut",
            "age": 12,
            "enclosure": "The Pachyderm Sanctuary",
            "trail": "Savannah Heights"
        },
        {
            "species": "elephant",
            "name": "Dumbo",
            "age": 5,
            "enclosure": "The Pachyderm Sanctuary",
            "trail": "Savannah Heights"
        },
        {
            "species": "elephant",
            "name": "Trunkers",
            "age": 10,
            "enclosure": "The Pachyderm Sanctuary",
            "trail": "Savannah Heights"
        },
        {
            "species": "bear",
            "name": "Smokey",
            "age": 10,
            "enclosure": "The Grizzly Gulch",
            "trail": "Polar Path"
        },
        {
            "species": "bear",
            "name": "Grizzly",
            "age": 8,
            "enclosure": "The Grizzly Gulch",
            "trail": "Polar Path"
        },
        {
            "species": "bear",
            "name": "Barnaby",
            "age": 6,
            "enclosure": "The Grizzly Gulch",
            "trail": "Polar Path"
        },
        {
            "species": "bear",
            "name": "Bruin",
            "age": 12,
            "enclosure": "The Grizzly Gulch",
            "trail": "Polar Path"
        },
        {
            "species": "giraffe",
            "name": "Gerald",
            "age": 4,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "giraffe",
            "name": "Longneck",
            "age": 5,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "giraffe",
            "name": "Patches",
            "age": 3,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "giraffe",
            "name": "Stretch",
            "age": 6,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "antelope",
            "name": "Speedy",
            "age": 2,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "antelope",
            "name": "Dash",
            "age": 3,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "antelope",
            "name": "Gazelle",
            "age": 4,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "antelope",
            "name": "Swift",
            "age": 5,
            "enclosure": "The Tall Grass Plains",
            "trail": "Savannah Heights"
        },
        {
            "species": "polar bear",
            "name": "Snowflake",
            "age": 7,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "polar bear",
            "name": "Blizzard",
            "age": 5,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "polar bear",
            "name": "Iceberg",
            "age": 9,
            "enclosure": "The Arctic Exhibit",
            "trail": "Polar Path"
        },
        {
            "species": "walrus",
            "name": "Wally",
            "age": 10,
            "enclosure": "The Walrus Cove",
            "trail": "Polar Path"
        },
        {
            "species": "walrus",
            "name": "Tusker",
            "age": 12,
            "enclosure": "The Walrus Cove",
            "trail": "Polar Path"
        },
        {
            "species": "walrus",
            "name": "Moby",
            "age": 8,
            "enclosure": "The Walrus Cove",
            "trail": "Polar Path"
        },
        {
            "species": "walrus",
            "name": "Flippers",
            "age": 9,
            "enclosure": "The Walrus Cove",
            "trail": "Polar Path"
        }
    ]
    
    @mcp.tool()
    def get_animals_by_species(species: str) -> List[Dict[str, Any]]:
        """
        Retrieves all animals of a specific species from the zoo.
        Can also be used to collect the base data for aggregate queries
        of animals of a specific species - like counting the number of penguins
        or finding the oldest lion.
    
        Args:
            species: The species of the animal (e.g., 'lion', 'penguin').
    
        Returns:
            A list of dictionaries, where each dictionary represents an animal
            and contains details like name, age, enclosure, and trail.
        """
        logger.info(f">>> 🛠️ Tool: 'get_animals_by_species' called for '{species}'")
        return [animal for animal in ZOO_ANIMALS if animal["species"].lower() == species.lower()]
    
    @mcp.tool()
    def get_animal_details(name: str) -> Dict[str, Any]:
        """
        Retrieves the details of a specific animal by its name.
    
        Args:
            name: The name of the animal.
    
        Returns:
            A dictionary with the animal's details (species, name, age, enclosure, trail)
            or an empty dictionary if the animal is not found.
        """
        logger.info(f">>> 🛠️ Tool: 'get_animal_details' called for '{name}'")
        for animal in ZOO_ANIMALS:
            if animal["name"].lower() == name.lower():
                return animal
        return {}
    
    if __name__ == "__main__":
        logger.info(f"🚀 MCP server started on port {os.getenv('PORT', 8080)}")
        asyncio.run(
            mcp.run_async(
                transport="http",
                host="0.0.0.0",
                port=os.getenv("PORT", 8080),
            )
        )
    

आपका कोड पूरा हो गया है! अब MCP सर्वर को Cloud Run पर डिप्लॉय करने का समय है.

7. Cloud Run पर डिप्लॉय करना

अब सोर्स कोड से सीधे Cloud Run पर एमसीपी सर्वर डिप्लॉय करें.

  1. Cloud Run पर डिप्लॉय करने के लिए, नया Dockerfile बनाएं और उसे खोलें:
    cloudshell edit Dockerfile
    
  2. server.pyफ़ाइल को चलाने के लिए, uv टूल का इस्तेमाल करने के लिए, Dockerfile में यह कोड शामिल करें:
    # Use the official Python image
    FROM python:3.13-slim
    
    # Install uv
    COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
    
    # Install the project into /app
    COPY . /app
    WORKDIR /app
    
    # Allow statements and log messages to immediately appear in the logs
    ENV PYTHONUNBUFFERED=1
    
    # Install dependencies
    RUN uv sync
    
    EXPOSE $PORT
    
    # Run the FastMCP server
    CMD ["uv", "run", "server.py"]
    
  3. Cloud Run पर ऐप्लिकेशन डिप्लॉय करने के लिए, gcloud निर्देश चलाएं
    gcloud run deploy zoo-mcp-server \
        --no-allow-unauthenticated \
        --region=europe-west1 \
        --source=. \
        --labels=dev-tutorial=codelab-mcp
    
    पुष्टि करने की ज़रूरत के लिए, --no-allow-unauthenticated फ़्लैग का इस्तेमाल करें. सुरक्षा की वजहों से ऐसा करना ज़रूरी है. अगर पुष्टि करने की ज़रूरत नहीं है, तो कोई भी व्यक्ति आपके एमसीपी सर्वर को कॉल कर सकता है. इससे आपके सिस्टम को नुकसान पहुंच सकता है.
  4. पुष्टि करें कि नई Artifact Registry रिपॉज़िटरी बन गई है. सोर्स कोड से Cloud Run पर पहली बार डिप्लॉय करने पर, आपको यह दिखेगा:
    Deploying from source requires an Artifact Registry Docker repository to store built containers. A repository named 
    [cloud-run-source-deploy] in region [europe-west1] will be created.
    
    Do you want to continue (Y/n)?
    
    Y टाइप करें और Enter दबाएं. इससे आपके डिप्लॉयमेंट के लिए, Artifact Registry रिपॉज़िटरी बन जाएगी. Cloud Run सेवा के लिए, MCP सर्वर के Docker कंटेनर को सेव करने के लिए इसकी ज़रूरत होती है.
  5. कुछ मिनटों के बाद, आपको इस तरह का मैसेज दिखेगा:
    Service [zoo-mcp-server] revision [zoo-mcp-server-12345-abc] has been deployed and is serving 100 percent of traffic.
    

आपने एमसीपी सर्वर डिप्लॉय किया हो. अब इसका इस्तेमाल किया जा सकता है.

8. Gemini CLI में रिमोट एमसीपी सर्वर जोड़ना

रिमोट एमसीपी सर्वर को डिप्लॉय करने के बाद, अब इसे Google Code Assist या Gemini सीएलआई जैसे अलग-अलग ऐप्लिकेशन से कनेक्ट किया जा सकता है. इस सेक्शन में, हम Gemini CLI का इस्तेमाल करके, आपके नए रिमोट एमसीपी सर्वर से कनेक्शन बनाएंगे.

  1. अपने उपयोगकर्ता खाते को रिमोट एमसीपी सर्वर को कॉल करने की अनुमति दें
    gcloud projects add-iam-policy-binding $GOOGLE_CLOUD_PROJECT \
        --member=user:$(gcloud config get-value account) \
        --role='roles/run.invoker'
    
  2. Gemini की सेटिंग वाली फ़ाइल में इस्तेमाल करने के लिए, Google Cloud के क्रेडेंशियल और प्रोजेक्ट नंबर को एनवायरमेंट वैरिएबल में सेव करें:
    export PROJECT_NUMBER=$(gcloud projects describe $GOOGLE_CLOUD_PROJECT --format="value(projectNumber)")
    export ID_TOKEN=$(gcloud auth print-identity-token)
    
  3. Gemini CLI की सेटिंग वाली फ़ाइल खोलना
    cloudshell edit ~/.gemini/settings.json
    
  4. Cloud Run MCP सर्वर जोड़ने के लिए, Gemini CLI की सेटिंग वाली फ़ाइल बदलें
    {
      "mcpServers": {
        "zoo-remote": {
          "httpUrl": "https://zoo-mcp-server-$PROJECT_NUMBER.europe-west1.run.app/mcp/",
          "headers": {
            "Authorization": "Bearer $ID_TOKEN"
          }
        }
      },
      "selectedAuthType": "cloud-shell",
      "hasSeenIdeIntegrationNudge": true
    }
    

  1. Cloud Shell में Gemini CLI शुरू करना
    gemini
    
    कुछ डिफ़ॉल्ट सेटिंग स्वीकार करने के लिए, आपको Enter दबाना पड़ सकता है.Gemini CLI का शुरुआती व्यू
  2. Gemini को, उसके कॉन्टेक्स्ट में उपलब्ध एमसीपी टूल की सूची बनाने के लिए कहें
    /mcp
    
  3. Gemini से चिड़ियाघर में कुछ खोजने के लिए कहना
    Where can I find penguins?
    
    Gemini CLI को zoo-remote MCP सर्वर का इस्तेमाल करना चाहिए. साथ ही, यह आपसे पूछेगा कि क्या आपको MCP को एक्ज़ीक्यूट करने की अनुमति देनी है.
  4. डाउन ऐरो का इस्तेमाल करें. इसके बाद, चुनने के लिए Enter दबाएं
    Yes, always allow all tools from server "zoo-remote"
    
    Gemini CLI को रिमोट टूल इस्तेमाल करने की अनुमति दें

आउटपुट में सही जवाब दिखना चाहिए. साथ ही, एक डिसप्ले बॉक्स दिखना चाहिए, जिसमें यह बताया गया हो कि एमसीपी सर्वर का इस्तेमाल किया गया है.

Gemini CLI show zoo mcp server result

आपने कर दिखाया! आपने Cloud Run पर रिमोट एमसीपी सर्वर को डिप्लॉय कर दिया है और Gemini सीएलआई का इस्तेमाल करके इसकी जांच कर ली है.

जब आपको सेशन खत्म करना हो, तो /quit टाइप करें. इसके बाद, Gemini CLI से बाहर निकलने के लिए Enter दबाएं.

डीबग करना

अगर आपको इस तरह की गड़बड़ी दिखती है:

🔍 Attempting OAuth discovery for 'zoo-remote'...
❌ 'zoo-remote' requires authentication but no OAuth configuration found
Error connecting to MCP server 'zoo-remote': MCP server 'zoo-remote' requires authentication. Please configure OAuth or check server settings.

ऐसा हो सकता है कि आईडी टोकन की समयसीमा खत्म हो गई हो. इसलिए, आपको ID_TOKEN को फिर से सेट करना होगा.

  1. Gemini CLI से बाहर निकलने के लिए, /quit टाइप करें और फिर Enter दबाएं.
  2. अपने टर्मिनल में प्रोजेक्ट सेट करना
    gcloud config set project [PROJECT_ID]
    
  3. ऊपर दिए गए दूसरे चरण से शुरू करें

9. (ज़रूरी नहीं) सर्वर लॉग में टूल कॉल की पुष्टि करना

यह पुष्टि करने के लिए कि आपके Cloud Run MCP सर्वर को कॉल किया गया था, सेवा के लॉग देखें.

gcloud run services logs read zoo-mcp-server --region europe-west1 --limit=5

आपको एक आउटपुट लॉग दिखेगा, जिसमें टूल कॉल किए जाने की पुष्टि की गई होगी. 🛠️

2025-08-05 19:50:31 INFO:     169.254.169.126:39444 - "POST /mcp/ HTTP/1.1" 200 OK
2025-08-05 19:50:31 [INFO]: Processing request of type CallToolRequest
2025-08-05 19:50:31 [INFO]: >>> 🛠️ Tool: 'get_animals_by_species' called for 'penguin'

10. (ज़रूरी नहीं) सर्वर में एमसीपी प्रॉम्प्ट जोड़ना

एमसीपी प्रॉम्प्ट की मदद से, उन प्रॉम्प्ट के लिए अपने वर्कफ़्लो को तेज़ किया जा सकता है जिन्हें अक्सर चलाया जाता है. इसके लिए, लंबे प्रॉम्प्ट के लिए शॉर्टहैंड बनाया जाता है.

Gemini CLI, MCP प्रॉम्प्ट को अपने-आप कस्टम स्लैश कमांड में बदल देता है, ताकि /prompt_name टाइप करके MCP प्रॉम्प्ट को चालू किया जा सके. यहाँ prompt_name, आपके MCP प्रॉम्प्ट का नाम है.

एक एमसीपी प्रॉम्प्ट बनाएं, ताकि Gemini CLI में /find animal टाइप करके, चिड़ियाघर में मौजूद किसी जानवर को तुरंत ढूंढा जा सके.

  1. इस कोड को अपनी server.py फ़ाइल में, मुख्य गार्ड (if __name__ == "__main__":) से ऊपर जोड़ें
    @mcp.prompt()
    def find(animal: str) -> str:
        """
        Find which exhibit and trail a specific animal might be located.
        """
    
        return (
            f"Please find the exhibit and trail information for {animal} in the zoo. "
            f"Respond with '[animal] can be found in the [exhibit] on the [trail].'"
            f"Example: Penguins can be found in The Arctic Exhibit on the Polar Path."
        )
    
  2. अपने ऐप्लिकेशन को Cloud Run पर फिर से डिप्लॉय करें
    gcloud run deploy zoo-mcp-server \
        --no-allow-unauthenticated \
        --region=europe-west1 \
        --source=. \
        --labels=dev-tutorial=codelab-mcp
    
  3. रिमोट एमसीपी सर्वर के लिए, अपना ID_TOKEN रीफ़्रेश करें
    export ID_TOKEN=$(gcloud auth print-identity-token)
    
  4. अपने ऐप्लिकेशन का नया वर्शन डिप्लॉय करने के बाद, Gemini CLI शुरू करें.
    gemini
    
  5. प्रॉम्प्ट में, बनाई गई नई कस्टम कमांड का इस्तेमाल करें:
    /find --animal="lions"
    

आपको दिखेगा कि Gemini CLI, get_animals_by_species टूल को कॉल करता है और MCP प्रॉम्प्ट में दिए गए निर्देशों के मुताबिक जवाब को फ़ॉर्मैट करता है!

╭───────────────────────────╮
│  > /find --animal="lion"  │
╰───────────────────────────╯

 ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
 │ ✔  get_animals_by_species (zoo-remote MCP Server) get_animals_by_species (zoo-remote MCP Server)  │
 │                                                                                                   │
 │    [{"species":"lion","name":"Leo","age":7,"enclosure":"The Big Cat                               │
 │    Plains","trail":"Savannah                                                                      │
 │    Heights"},{"species":"lion","name":"Nala","age":6,"enclosure":"The Big Cat                     │
 │    Plains","trail":"Savannah                                                                      │
 │    Heights"},{"species":"lion","name":"Simba","age":3,"enclosure":"The Big Cat                    │
 │    Plains","trail":"Savannah                                                                      │
 │    Heights"},{"species":"lion","name":"King","age":8,"enclosure":"The Big Cat                     │
 │    Plains","trail":"Savannah Heights"}]                                                           │
 ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Lions can be found in The Big Cat Plains on the Savannah Heights.

खुद को परखने के लिए स्ट्रेच गोल

ज़्यादा चुनौती के लिए, देखें कि क्या चिड़ियाघर में मौजूद जानवरों की किसी खास प्रजाति के बारे में मज़ेदार तथ्य बताने वाला प्रॉम्प्ट बनाने के लिए, इन्हीं चरणों का पालन किया जा सकता है.

इसके अलावा, आपने जो सीखा है उसे आज़माने के लिए, एक ऐसे टूल का आइडिया सोचें जिसका इस्तेमाल आपको अक्सर करना हो. साथ ही, दूसरा रिमोट एमसीपी सर्वर डिप्लॉय करें. इसके बाद, इसे Gemini CLI की सेटिंग में जोड़ें और देखें कि यह काम करता है या नहीं.

11. नतीजा

बधाई हो! आपने सुरक्षित रिमोट एमसीपी सर्वर को डिप्लॉय कर दिया है और उससे कनेक्ट हो गए हैं.

अगली लैब पर जाएं

यह लैब, तीन हिस्सों वाली सीरीज़ का पहला लैब है. दूसरे लैब में, आपको ADK एजेंट की मदद से बनाए गए MCP सर्वर का इस्तेमाल करना होगा.

ADK एजेंट के साथ Cloud Run पर एमसीपी सर्वर का इस्तेमाल करना

(ज़रूरी नहीं) साफ़ करें

अगर आपको अगले लैब पर नहीं जाना है और आपने जो भी बनाया है उसे मिटाना है, तो अतिरिक्त शुल्क से बचने के लिए अपना Cloud प्रोजेक्ट मिटाया जा सकता है.

Cloud Run, सेवा का इस्तेमाल न किए जाने पर कोई शुल्क नहीं लेता. हालांकि, Artifact Registry में कंटेनर इमेज सेव करने के लिए, आपसे शुल्क लिया जा सकता है. Cloud प्रोजेक्ट मिटाने पर, उस प्रोजेक्ट में इस्तेमाल किए गए सभी संसाधनों के लिए बिलिंग बंद हो जाती है.

अगर आपको प्रोजेक्ट मिटाना है, तो यह तरीका अपनाएं:

gcloud projects delete $GOOGLE_CLOUD_PROJECT

ऐसा भी हो सकता है कि आपको अपने Cloud Shell डिस्क से ग़ैर-ज़रूरी संसाधन मिटाने हों. आप:

  1. कोड लैब प्रोजेक्ट की डायरेक्ट्री मिटाएं:
    rm -rf ~/mcp-on-cloudrun
    
  2. चेतावनी! इस कार्रवाई को पहले जैसा नहीं किया जा सकता! अगर आपको Cloud Shell पर मौजूद सभी फ़ाइलें मिटाकर जगह खाली करनी है, तो अपनी पूरी होम डायरेक्ट्री मिटाएं. ध्यान रखें कि आपको जो भी डेटा रखना है उसे किसी दूसरी जगह पर सेव कर लिया गया हो.
    sudo rm -rf $HOME