grafana/gcx/setup-gcx

Claude Code and agent skill by grafana/gcx

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Installs and configures gcx: contexts, authentication, connection to Grafana Cloud or on-premise Grafana, env var overrides for CI/CD, default datasources. Use for first-time setup, or when gcx fails with auth or connection errors (401, 403, connection refused, missing namespace).

Install

npx vskill@latest install grafana/gcx/setup-gcx

SKILL.md

The same SKILL.md was published earlier as grafana/gcx/setup-gcx.

Setup gcx

Three configuration paths: Grafana Cloud (Path A), on-premise (Path B), and environment variables for CI/CD (Path C). For the complete config reference (all config set paths, TLS options, namespace resolution rules, multi-context patterns), see configuration.md.

Step 0: Install gcx

First, check whether gcx is already installed:

bash
gcx --version

If the command is not found, build it from source. Requires git and a recent Go toolchain:

bash
tmp=$(mktemp -d) && git clone --depth 1 https://github.com/grafana/gcx.git "$tmp" && (cd "$tmp" && go install ./cmd/gcx) && rm -rf "$tmp"

After installing, verify the binary is on PATH:

bash
gcx --version

Configuration Model

gcx uses a context-based configuration model inspired by kubectl's kubeconfig. One or more layered YAML files (with the user file at ~/.config/gcx/config.yaml by default) store named stacks (Grafana destination, credentials, provider config), named cloud entries (Grafana Cloud platform credentials and endpoints), and thin contexts that reference a stack and optional Cloud entry. One context is selected at a time; all commands operate against it unless overridden. Single-source legacy configs are migrated automatically after a safe preflight. When several layers participate, gcx converts them in memory and asks the user to migrate each layer explicitly rather than partially persisting the result.

Use gcx config view to inspect the current configuration at any time. Use gcx config check to validate that the active context is correct and can reach the server.


Path A: Grafana Cloud

Use this path when connecting to a Grafana Cloud instance (URLs ending in .grafana.net).

No Grafana Cloud account yet? Skip Steps 1 to 4 and run:

bash
gcx signup cloud

It opens the Grafana Cloud sign-up page (in agent mode it prints the URL for the user to open). The user creates the account, verifies their email, creates a first stack, and approves "Connect gcx"; gcx then saves the connection to the cloud context and makes it current. A browser already signed in to Grafana Cloud skips sign-up and asks for one of that account's stacks, or goes straight to "Connect gcx" with one organization and one stack; the user then approves as usual. To create a separate account instead, the user signs out of Grafana Cloud in that browser first. Signup asks no questions, and it only saves a new connection, so it refuses a context or stack entry that already exists: do not run Step 1 first. If it fails once the browser step has started, run the gcx login command the error shows, not gcx signup again, which could start a second account. It saves no Grafana Cloud management credentials; for Cloud product APIs (SLOs, Synthetic Monitoring, k6), add a Cloud Access Policy token afterwards with gcx cloud login --context cloud --cloud-token <token>.

Step 1: Create a stack and context
bash
gcx config set stacks.cloud.grafana.server https://myorg.grafana.net
gcx config set contexts.cloud.stack cloud

Replace cloud with any name you prefer (e.g., prod, myorg-cloud). Replace the server URL with your Grafana Cloud URL. The first command creates the stack entry; the second creates a context pointing at it.

Step 2: Authenticate

Option A-1: Browser OAuth (recommended for Grafana Cloud)

bash
gcx login cloud --server https://myorg.grafana.net --oauth

Opens a browser for the user to approve. This works non-interactively and in agent mode — the agent issues the command, the browser opens, and the user approves. No token to create or paste. gcx login also sets the context as current and verifies connectivity, so Steps 1, 3, and 4 are handled for you; skip them when using this option.

Option A-2: Service account token

bash
gcx config set stacks.cloud.grafana.token glsa_XXXXXXXXXXXXXXXX

Obtain a service account token from Administration > Service accounts in your Grafana Cloud instance. The token must have sufficient permissions for the operations you intend to run (Viewer for read-only, Editor or Admin for write operations).

The grafana.token field takes precedence over grafana.user/grafana.password when both are present.

Grafana Cloud product APIs use a separate credential. A Cloud Access Policy token has the widest compatibility and can be supplied during unified login:

bash
gcx login cloud --server https://myorg.grafana.net \
--token glsa_XXXXXXXXXXXXXXXX --cloud-token glc_XXXXXXXXXXXXXXXX --yes

For interactive use, the Cloud step of gcx login can keep an existing CAP or unexpired OAuth credential, accept a CAP, run the experimental direct Cloud OAuth flow, or skip. gcx cloud login --context cloud runs direct Cloud OAuth separately. OAuth retains expiry, granted scopes, and its coherent OAuth/API endpoint pair, but not every Cloud product command supports it yet; use a CAP for full compatibility.

Step 3: Switch to the context
bash
gcx config use-context cloud
Step 4: Verify the connection
bash
gcx config check

A successful check prints the active context name and server URL without errors. For Grafana Cloud, the stack ID (namespace) is auto-discovered from the server's /apis/iam.grafana.app/v0alpha1/whoami endpoint (falling back to /bootdata on older servers) -- you do not need to set grafana.stack-id manually unless auto-discovery fails.

If the discovered stack ID conflicts with a manually configured grafana.stack-id, gcx raises a validation error - see Namespace resolution issues.


Path B: On-Premise Grafana

Use this path when connecting to a self-hosted Grafana instance.

Step 1: Create a stack and context
bash
gcx config set stacks.onprem.grafana.server https://grafana.example.com
gcx config set contexts.onprem.stack onprem

Replace onprem with a name that identifies this environment (e.g., production, staging, local).

Step 2: Set authentication

Option B-1: API token (recommended)

bash
gcx config set stacks.onprem.grafana.token glsa_XXXXXXXXXXXXXXXX

Option B-2: Username and password

bash
# Supply the password through GRAFANA_PASSWORD
gcx login onprem --basic-auth --user admin --yes

Agents must supply GRAFANA_PASSWORD; agent mode disables prompting. Humans running in a terminal can omit --yes to enter the password without echoing. Login verifies the credentials with a fresh GET /api/user before saving them through the configured credential store.

Use Option B-1 when service accounts are available. Use Option B-2 for server administration or when service accounts are not configured.

Step 3: Set the org ID

On-premise Grafana uses an org ID to identify the namespace for API calls. Set it to the numeric ID of the organization (default org is 1):

bash
gcx config set stacks.onprem.grafana.org-id 1

To find the org ID: in Grafana, go to Administration > Organizations and note the numeric ID shown in the URL when you select an org.

Step 4: Switch to the context
bash
gcx config use-context onprem
Step 5: Verify the connection
bash
gcx config check

TLS options (optional): If your Grafana instance uses a self-signed certificate or a custom CA, configure TLS:

bash
# Skip TLS verification (development only -- do not use in production)
gcx config set stacks.onprem.grafana.tls.insecure-skip-verify true
# Supply a custom CA certificate (base64-encoded PEM)
gcx config set stacks.onprem.grafana.tls.ca-data <base64-encoded-pem>

Path C: Environment Variables (CI/CD)

Use this path when gcx runs in a CI/CD pipeline or another automated environment where writing a config file is impractical. Environment variables override the selected context's fields at runtime without modifying the config file.

Environment VariableRuntime overrideDescription
GRAFANA_SERVERselected stack's grafana.serverServer URL
GRAFANA_TOKENselected stack's grafana.tokenAPI token (takes precedence over user/pass)
GRAFANA_USERselected stack's grafana.userUsername for basic auth
GRAFANA_PASSWORDselected stack's grafana.passwordPassword for basic auth
GRAFANA_ORG_IDselected stack's grafana.org-idOrg ID (on-premise namespace)
GRAFANA_STACK_IDselected stack's grafana.stack-idStack ID (Grafana Cloud namespace)
GRAFANA_PROXY_ENDPOINTselected stack's OAuth proxyAssistant proxy endpoint
GRAFANA_TLS_CERT_FILEselected stack's TLS cert filemTLS client certificate
GRAFANA_TLS_KEY_FILEselected stack's TLS key filemTLS client key
GRAFANA_TLS_CA_FILEselected stack's TLS CA fileCustom CA bundle
GRAFANA_CLOUD_TOKENephemeral Cloud entryCloud Access Policy token
GRAFANA_CLOUD_API_URLephemeral Cloud entryCloud API endpoint
GRAFANA_CLOUD_OAUTH_URLephemeral Cloud entryCloud OAuth endpoint
GRAFANA_CLOUD_STACKselected stack's slugCloud stack slug

When an endpoint override changes a credential destination, supply the corresponding credential variable in the same invocation. Login commands turn one supplied endpoint into a coherent OAuth/API pair; set both endpoint variables when a custom environment deliberately uses distinct origins.

An auto-discovered repository .gcx.yaml cannot attach runtime or freshly prompted credentials, or external mTLS client key files, to destinations and transport settings supplied by that file. Review it and select it explicitly with --config .gcx.yaml or GCX_CONFIG=.gcx.yaml before login or direct provider authentication. Provider endpoint environment overrides also require their matching runtime credential and still do not authorize repository TLS or proxy settings.

Example: GitHub Actions
yaml
- name: Run gcx
env:
GRAFANA_SERVER: ${{ secrets.GRAFANA_SERVER }}
GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}
GRAFANA_ORG_ID: "1"
run: gcx resources get dashboards -o json

Environment variables apply to the selected context only and do not modify the config file on disk. --context selection happens before these overrides, and write-back paths never serialize the env-mutated runtime object.

Config file location

To supply a config file path explicitly:

bash
gcx --config /path/to/config.yaml resources get dashboards
# or
export GCX_CONFIG=/path/to/config.yaml

For the full config file search order, see configuration.md.


Default Datasource Configuration

To avoid passing -d <uid> on every query command, configure default datasource UIDs for the active context.

Find your datasource UIDs
bash
gcx datasources list -o json

Locate the uid field for each datasource. Example output:

json
{
"datasources": [
{ "uid": "prometheus-uid-abc123", "name": "Prometheus", "type": "prometheus" },
{ "uid": "loki-uid-def456", "name": "Loki", "type": "loki" }
]
}
Set defaults
bash
# Set the default Prometheus datasource
gcx config set contexts.cloud.datasources.prometheus prometheus-uid-abc123
# Set the default Loki datasource
gcx config set contexts.cloud.datasources.loki loki-uid-def456

Replace cloud with your context name and the UID values with those from the output above. After setting these, query commands that support a -d flag will use the configured defaults automatically.


Multi-Context Management

To work with multiple Grafana environments, repeat Path A or B once per environment with a distinct context name, then:

bash
# Switch between contexts
gcx config use-context staging

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
531
Repository forks
42
7-day trend score
31

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/grafana/gcx/setup-gcx/badge)](https://verified-skill.com/skills/grafana/gcx/setup-gcx)

Something wrong with this skill or its page? Tell us.