Skip to content
CLI tool · Cloud & deploy

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.

gcloudby Google CloudOfficial MCP option
What it is

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

Install Google Cloud CLI

The install commands from the official docs. Check it worked with gcloud --version.

Interactive installer (macOS, Linux)
curl https://sdk.cloud.google.com | bash
Auth

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.

Check the sign-in (read-only)
gcloud auth list
Interactive sign-in (human)
gcloud auth login
Credentials for client libraries (human)
gcloud auth application-default login
Set the default project
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.

Common agent tasks

What agents use Google Cloud CLI for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Show the active account and project

    gcloud
    gcloud config list
  2. List Cloud Run services

    gcloud
    gcloud run services list --region=us-central1
  3. Read recent errors as JSON

    gcloud
    gcloud logging read "severity>=ERROR" --limit=20 --freshness=1h --format=json
  4. Deploy a Cloud Run service from source

    gcloud
    gcloud run deploy my-service --source . --region=us-central1

    Creates a new revision that takes traffic. Needs approval.

Safety

Safety rules for agents

Safe to run without asking

  • gcloud config list
  • gcloud auth list
  • gcloud projects list
  • gcloud <service> list / describe
  • gcloud logging read

Ask a human first

  • 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.
Agent instructions

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.

AGENTS.md
## 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.
CLI or MCP server?

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.

Same category
All Cloud & deploy tools
FAQ

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.