Add Currency Tools to an Agent using MCP

Lab 20 годин universal_currency_alt 1 кредит show_chart Початковий
info This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by 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.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.