Add Currency Tools to an Agent using MCP

Lab 20 minuti universal_currency_alt 1 credito show_chart Introduttivi
info Questo lab potrebbe incorporare strumenti di AI a supporto del tuo apprendimento.
Questi contenuti non sono ancora ottimizzati per i dispositivi mobili.
Per un'esperienza ottimale, visualizza il sito su un computer utilizzando un link inviato via email.

GML016

Google Cloud self-paced labs logo

Overview

Large language models (LLMs) are powerful, but they have two major limitations: their knowledge is frozen at the time of their training, and they can't interact with the outside world to access real-time data or perform actions like booking a meeting or updating a customer record.

This is where the Model Context Protocol (MCP) comes to the rescue! MCP is an open standard designed to solve the limitations of LLMs.

Why use MCP?

MCP provides a secure and standardized "language" for LLMs to communicate with external data, applications, and services. It acts as a bridge, allowing AI Agents to move beyond static knowledge and become dynamic—with MCP they can retrieve current information and take action, making them more accurate, useful, and automated.

This lab provides step-by-step instructions for installing the Agent Development Kit (ADK), modifying an existing ADK agent to use MCP, and deploying the updated Agent to initialize an interactive session via the command-line interface.

Objectives

In this lab, you learn how to perform the following tasks:

  • Install the Agent Development Kit (ADK) and create a virtual environment for your project.
  • Test the currency-agent system (the "before" state).
  • Modify the Agent to use an MCP server.
  • Restart the MCP server and the Agent for the changes to take effect.
  • Verify the changes made to the MCP server (the "after").

Setup and requirements

  • Labs are timed and cannot be paused. The timer starts when you click Start Lab.
  • The included cloud terminal is preconfigured with the gcloud SDK.
  • Use the terminal to execute commands and then click Check my progress to verify your work.

Configure the environment and install the relevant dependencies

  1. Run the following command in the terminal to copy code files from a Cloud Storage bucket for this lab:

    gcloud storage cp -r gs://{{{project_0.project_id| YOUR_GCP_PROJECT_ID}}}-bucket/currency-agent .
  2. Set up the environment and create the .env file in the currency-agent directory using the following commands:

    cd currency-agent cp /home/student/keys.json . uv venv --python 3.12 source .venv/bin/activate uv sync touch .env echo "GOOGLE_CLOUD_PROJECT={{{ project_0.project_id }}}" >> .env echo "GOOGLE_CLOUD_LOCATION=global" >> .env echo "GOOGLE_GENAI_USE_VERTEXAI=True" >> .env echo "MODEL={{{project_0.startup_script.gemini_flash_model_id | gemini_flash_model_id}}}" >> .env

Task 1. Install the Agent Development Kit (ADK)

  1. In a new terminal (select Terminal > New Terminal in the menu bar or press CTRL+SHIFT+'), start the MCP Server using the following commands:

    cd currency-agent uv run mcp-server/server.py
  2. In a new terminal (select Terminal > New Terminal in the menu bar or press CTRL+SHIFT+'), start the A2A Server (it starts on port 10000) using the following commands:

    cd currency-agent uv run uvicorn currency_agent.agent:a2a_app --host localhost --port 10000

Task 2. Run the baseline Agent (the "before")

  1. In your initial terminal instance, launch the existing Currency Agent using the following commands:

    adk run currency_agent Note: If you encounter a timeout error (e.g., asyncio.exceptions.CancelledError) when starting the agent, verify that both the MCP Server (Task 1, step 1) and A2A Server (Task 1, step 2) are running without errors in their respective terminal tabs.
  2. Wait for the [user]: prompt to appear in the terminal, then interact with the agent by entering the following:

    What's the exchange rate between USD and EUR?

The agent should give you the real time exchange rate between the US Dollar and Euro.

  1. Try another prompt:

    What's the exchange rate between USD and CNY?

The agent should give you the real time exchange rate between the US Dollar and Chinese Yuan.

  1. Interact with the agent by prompting it as follows:

    What's the price of Bitcoin?

From the response, you should be able to tell that the Agent only knows about flat currencies (i.e. it can't give you any current data about crypto).

Task 3. Modify the Agent

In this task, you modify your Currency Agent to be able to use the Model Context Protocol (MCP) server. Think of it as a way to call a separate "Currency Server" (via the publicly available Coinbase API) to get rates that the Agent doesn't otherwise have access to.

  1. Click on the File Explorer icon in the left pane and navigate to your currency-agent/mcp-server project folder.

  2. In the File Explorer, within the mcp-server directory, open the server.py file, insert the following code at line 53, and save your changes:

    @mcp.tool() def get_crypto_price(currency_pair: str = "BTC-USD") -> dict: """Get the current price of a cryptocurrency pair.""" # No API key required for this public endpoint url = f"https://api.coinbase.com/v2/prices/{currency_pair}/spot" response = httpx.get(url) return response.json()["data"]

Task 4. Restart the MCP and A2A servers

  1. Switch to the terminal instance where the MCP server is still running.

  2. Press CTRL+C to stop the server.

  3. Still in the same terminal, run the following command to restart the MCP Server:

    uv run mcp-server/server.py
  4. Switch to the terminal instance where the A2A server is still running.

  5. Press CTRL+C to stop the server.

  6. Still in this terminal, run the following command to restart the Agent:

    uv run uvicorn currency_agent.agent:a2a_app --host localhost --port 10000

Task 5. Run and test your updated Agent (the "after")

  1. Switch to the terminal instance where the currency_agent had previously been running.

  2. Enter exit to end the original session.

  3. Execute the following command to re-run and test your Agent:

    adk run --save_session currency_agent Note: You can ignore any warnings related to Python version dependencies.
  4. Try issuing the following prompt to interact with the Agent:

    Use the get_crypto_price tool to get me the current price of Bitcoin.

The Agent now has access to the get_crypto_price tool (via MCP), which enables it to answer questions about more than just flat currencies!

  1. Enter exit and input 1 when prompted for a session ID.

Click Check my progress to verify the objective. Modify an ADK Agent to use MCP.

Congratulations!

You've successfully deploying an ADK agent and modified it to use the Model Context Protocol (MCP) server.

Manual Last Updated April 9, 2026

Lab Last Tested April 9, 2026

Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Prima di iniziare

  1. I lab creano un progetto e risorse Google Cloud per un periodo di tempo prestabilito
  2. I lab hanno un limite di tempo e non possono essere messi in pausa. Se termini il lab, dovrai ricominciare dall'inizio.
  3. In alto a sinistra dello schermo, fai clic su Inizia il lab per iniziare

Utilizza la navigazione privata

  1. Copia il nome utente e la password forniti per il lab
  2. Fai clic su Apri console in modalità privata

Accedi alla console

  1. Accedi utilizzando le tue credenziali del lab. L'utilizzo di altre credenziali potrebbe causare errori oppure l'addebito di costi.
  2. Accetta i termini e salta la pagina di ripristino delle risorse
  3. Non fare clic su Termina lab a meno che tu non abbia terminato il lab o non voglia riavviarlo, perché il tuo lavoro verrà eliminato e il progetto verrà rimosso

Questi contenuti non sono al momento disponibili

Ti invieremo una notifica via email quando sarà disponibile

Bene.

Ti contatteremo via email non appena sarà disponibile

Un lab alla volta

Conferma per terminare tutti i lab esistenti e iniziare questo

Utilizza la navigazione privata per eseguire il lab

Il modo migliore per eseguire questo lab è utilizzare una finestra del browser in incognito o privata. Ciò evita eventuali conflitti tra il tuo account personale e l'account studente, che potrebbero causare addebiti aggiuntivi sul tuo account personale.