-
Notifications
You must be signed in to change notification settings - Fork 298
Description
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.shusing a service account or user lacking theroles/serviceusage.apiKeysAdminrole. - Observe that the script attempts to create an API key, fails, but still creates a
.envfile 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