Tool: run_gcloud_command
Executes a single gcloud CLI command within the user's Google Cloud project. CRITICAL SAFETY WARNING (POTENTIALLY DESTRUCTIVE): This tool can create, update, or delete GCP resources (e.g., gcloud compute instances delete). It is NOT restricted to read-only commands. Use extreme caution. FORBIDDEN COMMANDS: An agent MUST NOT execute the following gcloud commands (including their alpha/beta variants): app deploy, app instances ssh, auth, billing, components, config, docker, feedback, info, init, meta, survey. STRICT EXECUTION RULES:
- You MUST provide the 'project' parameter (i.e. project="projects/PROJECT_ID") when using this tool (it is used for Cloud CLI Execution API enablement check, billing, quota, etc.). This is NOT the same as the --project flag in gcloud commands used to specify the project gcloud operates on.
- Flag Formatting: You MUST always use an '=' sign to separate flag keys from their values for all long options. Correct:
--zone=us-central1-aor--project=my-project. Incorrect:--zone us-central1-aor--project my-project. - Billing Project: You cannot assume any pre-configured project or billing settings in the execution environment. For non-project scoped commands (e.g., folder or organization level) or specific scenarios like Cloud Storage Requester Pays, you MUST pass the
--billing-project=PROJECTflag. For project-scoped commands, you MAY additionally specify--billing-project=PROJECTto override the quota project, which will take effect for GCP APIs that do not support resource-project-override. - Project Scope: You SHOULD ALWAYS pass the
--project=PROJECT_IDflag for project-scoped commands. Do not use it for organization or folder-level commands. If you do not provide a --project flag for a project-scoped command, the resource project will default to the project set in the --billing-project flag. - If specifying --billing-project flag in the gcloud command, ensure that the value is a project ID or a project number. The value MUST NOT be a special value (ie LEGACY, CURRENT_PROJECT, CURRENT_PROJECT_WITH_FALLBACK).
- At least one of --project or --billing-project MUST be specified in the command string.
- Asynchronous Operations: For long-running synchronous operations (e.g., creating a VM or a database), you SHOULD ALWAYS pass the
--asyncflag to prevent agent timeouts. - Log Rate Limiting: When using
gcloud logging read, you MUST ALWAYS include a--limitflag (e.g.,--limit=100) to prevent credential and connection timeouts. - Self-Correction: If a command returns an error, analyze the stderr, correct the syntax or flags, and retry in the next iteration.
- input_files: (Optional) A list of files to be created in the environment before running the command. Each file must have a 'path' (relative to the current directory) and 'contents'. The 'contents' must be plain text representing the file's content. This is useful for commands that read from files (e.g. gcloud builds submit --config=cloudbuild.yaml --async --project=PROJECT_ID).
Example gcloud commands/patterns:
- Read GCE instance logs with severity>=ERROR:
gcloud logging read "severity>=ERROR AND resource.type='gce_instance'" --limit=10 --order=DESC --project=PROJECT_ID- Note the use of quotes for the filter expression.
- List all PSC endpoints:
gcloud compute forwarding-rules list --project=PROJECT_ID - Describe a PSC endpoint:
gcloud compute forwarding-rules describe FORWARDING_RULE_NAME --region=REGION --project=PROJECT_ID- Note the use of '=' for the --region flag.
- List all clusters:
gcloud container clusters list --project=PROJECT_ID - Describe a cluster:
gcloud container clusters describe CLUSTER_NAME --region=REGION --project=PROJECT_ID - List compute instances:
gcloud compute instances list --project=PROJECT_ID - Get IAM policy for a project:
gcloud projects get-iam-policy PROJECT_ID --project=PROJECT_ID
Response strings are formatted for terminal output by default (stdout or stderr). Use --format flag to change the format.
The following sample demonstrate how to use curl to invoke the run_gcloud_command MCP tool.
| Curl Request |
|---|
curl --location 'https://cloudcli.googleapis.com/mcp' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "run_gcloud_command", "arguments": { // provide these details according to the tool's MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
Input Schema
Request message for RunGcloud.
RunGcloudRequest
| JSON representation |
|---|
{
"project": string,
"command": string,
"inputFiles": [
{
object ( |
| Fields | |
|---|---|
project |
Required. Project for api enablement and quota consumption for the Cloud CLI Execution API. Format must be projects/ |
command |
Required. The full gcloud command line to run as a single string. Example: "gcloud compute instances create my-vm --zone=us-central1-a" LLMs are instructed to use the |
inputFiles[] |
Optional. Files to be made available to the gcloud command for its execution. |
File
| JSON representation |
|---|
{ "path": string, "contents": string } |
| Fields | |
|---|---|
path |
Required. Filepath relative to the home directory. Must not contain parent directory traversal (..) or shell expansions. |
contents |
Required. Contents of the file. |
Output Schema
Response message for RunGcloud.
RunGcloudResponse
| JSON representation |
|---|
{ "response": { object ( |
| Fields | |
|---|---|
response |
The response from the CLI tool execution, containing independent stdout, stderr stream and an exit code. |
outputFiles[] |
Files generated by the gcloud command from its execution. |
CliExecutionResponse
| JSON representation |
|---|
{ "stdout": string, "stderr": string, "exitCode": string } |
| Fields | |
|---|---|
stdout |
The stdout stream from the CLI tool execution. |
stderr |
The stderr stream from the CLI tool execution. |
exitCode |
The exit code of the CLI tool execution. |
File
| JSON representation |
|---|
{ "path": string, "contents": string } |
| Fields | |
|---|---|
path |
Required. Filepath relative to the home directory. Must not contain parent directory traversal (..) or shell expansions. |
contents |
Required. Contents of the file. |
Tool Annotations
Destructive Hint: ✅ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ❌