The setup/setup_env.sh script currently lacks error handling for critical gcloud operations. If API enablement or API key creation fails (common for users with restricted IAM permissions), the script continues execution and generates a .env file with missing or empty values.
This leads to a poor developer experience where the setup appears successful, but the agent fails during adk web execution with cryptic errors regarding the MAPS_API_KEY.
Steps to Reproduce
- Run
./setup/setup_env.sh using a service account or user lacking the roles/serviceusage.apiKeysAdmin role.
- Observe that the script attempts to create an API key, fails, but still creates a
.env file and reports no error.
- Run
adk web.
- The agent fails to initialize the Maps toolset because the environment variable is invalid.
Expected Behavior
The script should exit immediately upon any command failure with a descriptive error message indicating which command failed and which IAM roles might be required (e.g., roles/serviceusage.serviceUsageAdmin or roles/serviceusage.apiKeysAdmin).
Proposed Solution
I can submit a Pull Request to implement set -e for global error handling and explicit validation for the API key generation variable.
Suggested changes to setup/setup_env.sh:
#!/bin/bash
# Exit on any error
set -e
echo "Enabling required Google Cloud APIs..."
# Enable APIs with validation
gcloud services enable compute.googleapis.com \
bigquery.googleapis.com \
maps-backend.googleapis.com --quiet \
|| { echo "❌ Failed to enable APIs. Check permissions (roles/serviceusage.serviceUsageAdmin required)."; exit 1; }
echo "Creating API key..."
# Create API key with validation
MAPS_API_KEY=$(gcloud alpha services api-keys create \
--display-name="MCP Bakery Key" \
--format="value(name)")
if [ -z "$MAPS_API_KEY" ]; then
echo "❌ Failed to create MAPS_API_KEY. Check permissions (roles/serviceusage.apiKeysAdmin required)."
exit 1
fi
# Create the .env file only if the above steps succeeded
echo "GOOGLE_CLOUD_PROJECT=$(gcloud config get-value project)" > .env
echo "MAPS_API_KEY=$MAPS_API_KEY" >> .env
echo "✅ Environment configured successfully."
Files Affected
google/mcp/examples/launchmybakery/setup/setup_env.sh
The
setup/setup_env.shscript currently lacks error handling for criticalgcloudoperations. If API enablement or API key creation fails (common for users with restricted IAM permissions), the script continues execution and generates a.envfile with missing or empty values.This leads to a poor developer experience where the setup appears successful, but the agent fails during
adk webexecution with cryptic errors regarding theMAPS_API_KEY.Steps to Reproduce
./setup/setup_env.shusing a service account or user lacking theroles/serviceusage.apiKeysAdminrole..envfile and reports no error.adk web.Expected Behavior
The script should exit immediately upon any command failure with a descriptive error message indicating which command failed and which IAM roles might be required (e.g.,
roles/serviceusage.serviceUsageAdminorroles/serviceusage.apiKeysAdmin).Proposed Solution
I can submit a Pull Request to implement
set -efor global error handling and explicit validation for the API key generation variable.Suggested changes to
setup/setup_env.sh:Files Affected
google/mcp/examples/launchmybakery/setup/setup_env.sh