Google Cloud CLI for AI agents
The Google Cloud CLI (gcloud) for AI agents: check config, list Cloud Run services, read logs as JSON, and deploy from source, with safe prompts.
What Google Cloud CLI does for an agent
The Google Cloud CLI is Google's official command-line tool for Google Cloud. The gcloud command manages projects, Cloud Run, Compute Engine, IAM, logging, and most other services; the same SDK also ships gsutil and bq.
Every command supports --format=json, which gives an agent structured output instead of tables meant for people.
Official site: cloud.google.com/cli
Install Google Cloud CLI
The install commands from the official docs. Check it worked with gcloud --version.
curl https://sdk.cloud.google.com | bash
Signing in Google Cloud CLI for an agent
A human signs in with gcloud auth login, and with gcloud auth application-default login for client libraries. In CI, use a service account or workload identity federation instead of user credentials.
gcloud auth list
gcloud auth login
gcloud auth application-default login
gcloud config set project my-project
Environment variables: CLOUDSDK_CORE_PROJECT, GOOGLE_APPLICATION_CREDENTIALS. Set them in the agent's environment; never paste values into prompts or commit them.
What agents use Google Cloud CLI for
Example commands with placeholder names. Swap in your own project, app, or file names.
Show the active account and project
gcloud config list
List Cloud Run services
gcloud run services list --region=us-central1
Read recent errors as JSON
gcloud logging read "severity>=ERROR" --limit=20 --freshness=1h --format=json
Deploy a Cloud Run service from source
gcloud run deploy my-service --source . --region=us-central1
Creates a new revision that takes traffic. Needs approval.
Safety rules for agents
Safe to run without asking
gcloud config listgcloud auth listgcloud projects listgcloud <service> list / describegcloud logging read
Ask a human first
gcloud run deploygcloud <service> create / update / deletegcloud projects deletegcloud iam ... add-iam-policy-binding
- Pass --project explicitly, or check gcloud config list first, so commands land in the intended project.
- Never add --quiet to delete or update commands; it skips the confirmation prompt that protects you.
- Use --format=json for output the agent parses, and keep service account key files out of the repository.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## Google Cloud CLI (gcloud) Use `gcloud` for reading Google Cloud projects, Cloud Run services, and logs, and preparing deploys. - Check it is installed with `gcloud --version`. If it is missing, ask before installing it. - Auth: a human signs gcloud in. Check with `gcloud auth list`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens (CLOUDSDK_CORE_PROJECT, GOOGLE_APPLICATION_CREDENTIALS). - Run without asking (read-only): `gcloud config list`, `gcloud auth list`, `gcloud projects list`, `gcloud <service> list / describe`, `gcloud logging read`. - Ask a human first (changes or deletes things): `gcloud run deploy`, `gcloud <service> create / update / delete`, `gcloud projects delete`, `gcloud iam ... add-iam-policy-binding`. - Pass --project explicitly, or check gcloud config list first, so commands land in the intended project. - Never add --quiet to delete or update commands; it skips the confirmation prompt that protects you. - Use --format=json for output the agent parses, and keep service account key files out of the repository. - Prefer JSON output where the command supports it, and keep output short.
Google Cloud CLI or an MCP server?
An official MCP option exists. Google publishes MCP servers for some Google Cloud products, such as its database toolbox. Search the directory for the service you need; the CLI covers the rest.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Cloud & deploy tools
Google Cloud CLI questions
How do I install Google Cloud CLI?
Interactive installer (macOS, Linux): curl https://sdk.cloud.google.com | bash. Check the install with gcloud --version, and see the Google Cloud docs for other platforms.
How does an AI agent authenticate Google Cloud CLI?
A human signs in with gcloud auth login, and with gcloud auth application-default login for client libraries. In CI, use a service account or workload identity federation instead of user credentials. The agent can check the sign-in with gcloud auth list and should stop and ask if it fails.
Which Google Cloud CLI commands are safe for an agent to run?
Commands that only read state are safe to run without asking: gcloud config list; gcloud auth list; gcloud projects list; gcloud <service> list / describe; gcloud logging read. Ask a human before anything that changes or deletes something: gcloud run deploy; gcloud <service> create / update / delete; gcloud projects delete; gcloud iam ... add-iam-policy-binding.
Is there an MCP server for Google Cloud CLI?
Google publishes MCP servers for some Google Cloud products, such as its database toolbox. Search the directory for the service you need; the CLI covers the rest.