> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/looker.md).

# Looker MCP server

Install the Looker integration and its MCP server so agents behind the P0 AI Gateway can request read or edit access to a LookML model in your Looker (Google Cloud core) instance.

The **Looker** integration lets agents behind the AI Gateway, part of [P0 Runtime Access for AI](https://docs.p0.dev/readme/agentic-control-plane.md), request access to a LookML model in your Looker (Google Cloud core) instance. For each grant, P0 creates a new Looker service account with access to that one model. When the grant ends, P0 deletes the account.

An agent can request one of two levels on a model:

* `read`: explore the model, run queries, and view Looks and dashboards.
* `edit`: everything in `read`, plus saving Looks and dashboards.

Neither level can change LookML, unless a group that every new Looker user joins gives that ability. See **Group roles** below.

{% hint style="info" %}
The Looker integration is in preview. Functionality and configuration may change.
{% endhint %}

Setup has four parts, in this order:

1. Create a Looker service account for P0's connector, with the Admin role and an API key.
2. Install the integration with Terraform, and store the API key in Google Secret Manager.
3. Add the Looker MCP server to your gateway.
4. Write the policies that decide which agents get which access.

## Prerequisites

* A registered [Gateway](https://docs.p0.dev/agentic-access/agentic-gateway/gateway.md) component, with the gateway deployed in your environment.
* A Looker (Google Cloud core) instance with a public endpoint at `https://<name>.looker.app`. P0 reaches the instance over the internet, and doesn't support instances behind a custom domain. Use Enterprise edition if you can: Standard edition allows only 1,000 admin API calls a month.
* The [Google Cloud](https://docs.p0.dev/integrations/resource-integrations/google-cloud.md) integration installed for your Google Cloud organization.
* [Google Secret Manager](https://docs.p0.dev/integrations/resource-integrations/google-secret-manager.md) and [GCP Workload Identity Federation](https://docs.p0.dev/agentic-access/credential-sources/gcp-wif.md) installed on the same Google Cloud project. P0's Looker connector runs in that project and keeps each grant's Looker API key in its Secret Manager. The gateway uses Workload Identity Federation to read each grant's key.
* Permission to apply Terraform in the project.
* A Looker admin, to create the connector's Looker service account.

## Before you install

* **Licenses.** Each active grant's Looker service account takes a Standard user license until the grant ends. Looker counts licenses by the roles an account holds, as described in [Manage users within Looker (Google Cloud core)](https://docs.cloud.google.com/looker/docs/looker-core-user-management).
* **API quota.** Looker (Google Cloud core) limits the admin API calls an instance can make each month, to 10,000 on Enterprise edition. P0's connector uses that quota on every grant. Agents use it too, whenever their tools list models, Explores, fields, Looks or dashboards. Queries count against a separate query quota. See [API limits](https://docs.cloud.google.com/looker/docs/looker-core-overview#api_limits).
* **The Shared folder.** On a default instance, the All Users group can edit everything in the Shared folder, and each grant's account belongs to All Users. So an edit grant can change or delete any content in Shared, including content built on other models. To prevent that, set All Users to **View** on the Shared folder, and give people edit access through their own groups. See [Designing and configuring a system of access levels](https://docs.cloud.google.com/looker/docs/access-levels).
* **Content agents save.** When P0 deletes a grant's account, Looker moves the content in that account's personal folder to Trash, and deletes any schedules built on it. To keep what agents save, set an agent content folder when you install. An edit grant gets edit access to that folder, and content saved there stays after the grant ends.
* **Roles P0 creates.** The first time a grant needs one, P0 creates a permission set, a model set or a role named `p0-looker-ai-...`, and later grants reuse it. P0 never edits or deletes them. If someone changes one, every grant that needs it fails with an error that names it.
* **Group roles.** If a group adds every new Looker user automatically, its roles apply to each grant's account too, on top of the role P0 gives it. A role there that can develop LookML or save content gives every grant that ability, even a `read` grant. Before you install, check these groups in Looker and remove any role you don't want every agent to have.

## Create the connector's Looker service account

P0's connector signs in to Looker with an API key of its own. It needs the Admin role to create the account, API key and role for each grant.

1. **Create a Looker service account** for the connector, and give it the **Admin** role. See [Creating an API-only service account](https://docs.cloud.google.com/looker/docs/looker-core-user-management#creating_an_api-only_service_account). An account with the Admin role takes a Developer user license.
2. **Create an API key** for that account. See [API keys](https://docs.cloud.google.com/looker/docs/admin-panel-users-users#api_keys). Keep its client ID and client secret for the next section.

## Install the integration with Terraform

The configuration below deploys P0's Looker connector to Cloud Run in your project, with a secret for the connector's API key. `p0_looker_ai_staged` registers the instance with P0, and `p0_looker_ai` completes the install.

When P0 completes the install, your connector signs in to Looker with the API key. So the key has to be in its secret before you create `p0_looker_ai`, and you apply the configuration in three steps.

```terraform
# Installs Looker for agentic access. P0's Looker connector runs on Cloud Run,
# and the instance's Admin key is in Google Secret Manager.
#
# Creating p0_looker_ai runs P0's install check, and the connector signs in to
# Looker with the Admin key for it. So the key must be in its secret before
# p0_looker_ai is created. Apply in three steps:
#
#   1. Create the Admin key's secret:
#        terraform apply -target=google_secret_manager_secret.admin_key
#   2. Add the Admin key as a version of that secret, with the gcloud command
#      shown above the secret below.
#   3. Create everything else:
#        terraform apply

terraform {
  required_providers {
    # 0.85.0 added the p0_looker_ai resources.
    p0 = {
      source  = "p0-security/p0"
      version = ">= 0.85.0"
    }
  }
}

resource "p0_gcp" "example" {
  organization_id = "123456789012"
}

locals {
  project  = "my-project-id"
  instance = "acme"
}

resource "google_project_service" "enable_services" {
  for_each = toset([
    "cloudresourcemanager.googleapis.com",
    "iam.googleapis.com",
    "run.googleapis.com",
    "secretmanager.googleapis.com",
  ])
  project            = local.project
  service            = each.key
  disable_on_destroy = false
}

# Holds the Looker API key of a Looker service account with the Admin role.
# Only a Looker admin can create that account and its key. You add the key
# outside Terraform, so it never lands in the Terraform state. After step 1
# above, add it as a version of this secret, as JSON:
#
#   printf '{"client_id":"%s","client_secret":"%s"}' "$LOOKER_CLIENT_ID" "$LOOKER_CLIENT_SECRET" \
#     | gcloud secrets versions add p0_install_looker_acme_admin-key \
#       --project=my-project-id --data-file=-
resource "google_secret_manager_secret" "admin_key" {
  project   = local.project
  secret_id = "p0_install_looker_${local.instance}_admin-key"

  replication {
    auto {}
  }

  depends_on = [google_project_service.enable_services]
}

resource "p0_looker_ai_staged" "example" {
  id               = local.instance
  instance_url     = "https://acme.looker.app"
  admin_key_secret = google_secret_manager_secret.admin_key.secret_id

  secret_manager = {
    type       = "gcp-sm"
    project_id = local.project
  }

  depends_on = [p0_gcp.example]
}

resource "google_service_account" "connector" {
  project      = local.project
  account_id   = split("@", p0_looker_ai_staged.example.secret_manager.connector_service_account)[0]
  display_name = "P0 Cloud Run Looker connector"

  depends_on = [google_project_service.enable_services]
}

resource "google_cloud_run_v2_service" "connector" {
  project             = local.project
  name                = p0_looker_ai_staged.example.secret_manager.connector_service_name
  location            = p0_looker_ai_staged.example.secret_manager.connector_region
  deletion_protection = false
  # P0 calls the connector from outside GCP, so IAM, not origin, gates access.
  ingress = "INGRESS_TRAFFIC_ALL"

  template {
    service_account = google_service_account.connector.email

    containers {
      image = "docker.io/p0security/p0-connector-looker-ai-gcloud:sha-587fbe5@sha256:e986310f36a13b95b1e6c926359d7af78a58e98c9c3841d03a268a607e1aceaf"

      # The connector also checks this against the caller's OIDC token.
      env {
        name  = "INVOKER_SA_EMAIL"
        value = p0_gcp.example.service_account_email
      }
    }
  }

  depends_on = [google_project_service.enable_services]
}

resource "google_cloud_run_v2_service_iam_member" "invoke_connector" {
  project  = local.project
  location = google_cloud_run_v2_service.connector.location
  name     = google_cloud_run_v2_service.connector.name
  role     = "roles/run.invoker"
  member   = "serviceAccount:${p0_gcp.example.service_account_email}"
}

# P0 reads the service to get its invocation URL while it installs. The invoker
# role gives run.routes.invoke only, so it cannot do this read.
resource "google_cloud_run_v2_service_iam_member" "read_connector" {
  project  = local.project
  location = google_cloud_run_v2_service.connector.location
  name     = google_cloud_run_v2_service.connector.name
  role     = "roles/run.viewer"
  member   = "serviceAccount:${p0_gcp.example.service_account_email}"
}

data "google_project" "this" {
  project_id = local.project
}

# The connector keeps each grant's Looker API key in its own secret. GCP checks
# secretmanager.secrets.create on the project, so this binding has no condition.
resource "google_project_iam_custom_role" "connector_secret_create" {
  project     = local.project
  role_id     = "p0LookerConnectorSecretCreate"
  title       = "P0 Looker connector secret creation"
  permissions = ["secretmanager.secrets.create"]

  depends_on = [google_project_service.enable_services]
}

resource "google_project_iam_member" "connector_secret_create" {
  project = local.project
  role    = google_project_iam_custom_role.connector_secret_create.name
  member  = "serviceAccount:${google_service_account.connector.email}"
}

# The connector writes each grant's key to its secret, and deletes the secret
# when the grant ends. secrets.get makes the role match the one that P0's
# in-app install generates. The condition below limits all three permissions
# to the Looker grant secrets.
resource "google_project_iam_custom_role" "connector_secret_manage" {
  project = local.project
  role_id = "p0LookerConnectorSecretManage"
  title   = "P0 Looker connector grant secret management"
  permissions = [
    "secretmanager.secrets.delete",
    "secretmanager.secrets.get",
    "secretmanager.versions.add",
  ]

  depends_on = [google_project_service.enable_services]
}

resource "google_project_iam_member" "connector_secret_manage" {
  project = local.project
  role    = google_project_iam_custom_role.connector_secret_manage.name
  member  = "serviceAccount:${google_service_account.connector.email}"

  # P0 names the grant secrets with this prefix. IAM conditions use the project
  # number, not the project ID.
  condition {
    title      = "P0 Looker grant secrets"
    expression = "resource.name.startsWith('projects/${data.google_project.this.number}/secrets/p0_access-token_looker_${local.instance}_')"
  }
}

# The connector reads the Admin key on every call. Grant read on this secret
# alone. P0 names the secret in each call, so a call could point the connector
# at any other secret it can read.
resource "google_secret_manager_secret_iam_member" "admin_key" {
  project   = local.project
  secret_id = google_secret_manager_secret.admin_key.secret_id
  role      = "roles/secretmanager.secretAccessor"
  member    = "serviceAccount:${google_service_account.connector.email}"
}

# The accessor role gives secretmanager.versions.access only. The connector also
# reads the version's metadata, so the Admin key needs this grant as well.
resource "google_secret_manager_secret_iam_member" "admin_key_read" {
  project   = local.project
  secret_id = google_secret_manager_secret.admin_key.secret_id
  role      = "roles/secretmanager.viewer"
  member    = "serviceAccount:${google_service_account.connector.email}"
}

# Completes the install. Create it only once the Admin key is in its secret
# (step 2 above): P0's install check signs in to Looker with that key.
resource "p0_looker_ai" "example" {
  id               = p0_looker_ai_staged.example.id
  instance_url     = p0_looker_ai_staged.example.instance_url
  admin_key_secret = p0_looker_ai_staged.example.admin_key_secret
  # Optional. The Looker folder that agents save content to, from its URL
  # (/folders/<ID>). Without it, content that an agent saves goes to Trash when
  # its grant ends. To set it, uncomment this line and enter your folder's ID.
  # content_folder_id = "<ID>"

  secret_manager = {
    type       = p0_looker_ai_staged.example.secret_manager.type
    project_id = p0_looker_ai_staged.example.secret_manager.project_id
  }

  depends_on = [
    google_cloud_run_v2_service_iam_member.invoke_connector,
    google_cloud_run_v2_service_iam_member.read_connector,
    google_project_iam_member.connector_secret_create,
    google_project_iam_member.connector_secret_manage,
    google_secret_manager_secret_iam_member.admin_key,
    google_secret_manager_secret_iam_member.admin_key_read,
  ]
}
```

1. **Copy the configuration** into your Terraform project, and set your values:
   * `organization_id` in `p0_gcp`: your Google Cloud organization. If you already manage the Google Cloud integration in Terraform, refer to your existing `p0_gcp` resource instead.
   * `project`: the Google Cloud project for the connector and its secrets.
   * `instance`: the name that agents, policies and the CLI use for this instance in P0, such as `analytics`. Use letters, digits and hyphens.
   * `instance_url`: `https://<name>.looker.app`, in lowercase, with no path or trailing slash.
   * `content_folder_id` (optional): the ID of a Looker folder for agent content. It's the last part of the folder's URL, as in `https://<name>.looker.app/folders/<id>`. To set one, uncomment the line and enter the folder's ID.
2. **Create the Admin key's secret**:

   ```bash
   terraform apply -target=google_secret_manager_secret.admin_key
   ```
3. **Store the API key** as a version of that secret. Set `LOOKER_CLIENT_ID` and `LOOKER_CLIENT_SECRET` to the key's client ID and client secret. Then run this command, with your `instance` value and your project ID in place of the placeholders:

   ```bash
   printf '{"client_id":"%s","client_secret":"%s"}' "$LOOKER_CLIENT_ID" "$LOOKER_CLIENT_SECRET" \
     | gcloud secrets versions add p0_install_looker_<instance>_admin-key --project=<project-id> --data-file=-
   ```

   Keep the key out of your Terraform configuration, so that it never lands in your Terraform state.
4. **Apply the rest** with `terraform apply`. P0 checks the install through your connector, which signs in to Looker with the key. The apply fails with P0's message if:

   * Looker doesn't accept the key
   * a level needs a permission your instance doesn't have
   * a level would need a permission that P0 never grants
   * the agent content folder doesn't exist

   The failure message also lists the groups that add new Looker users automatically and give them roles. A successful install doesn't list them, so check those groups yourself, as **Group roles** above describes.

A Google Cloud project runs one Looker connector, for one Looker instance. To install another instance, apply this configuration in a different project, with that instance's own `instance` value and API key.

## Add the Looker MCP server

You can add the Looker MCP server once you've installed at least one Looker instance.

1. Follow the shared steps in [MCP server](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server.md#add-an-mcp-server) to name the server and choose its gateway. On the configuration screen, set these fields, then click **Finish**:
   * **Credential source**: choose **Vaulted credential**.
   * **Definition**: choose **P0**, then select **Looker** as the predefined server identifier.
2. The server now shows the state **Installed**.

P0 pushes the server definition to the gateway on its next sync. Agents can then reach the Looker MCP server through the gateway URL.

## How agents request access

An agent names the instance by its P0 identifier, the LookML model by its name, and a level. It can choose any of the instance's models that has at least one Explore and isn't hidden. The equivalent CLI request is:

```bash
p0 request looker-ai model <instance> <model> <level> --reason "<reason>"
```

See [Requesting access](https://docs.p0.dev/agentic-access/using-the-gateway/requesting-access.md) for how agents submit and use requests.

## Write policies for Looker

Match Looker requests in an agentic access policy ([Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md)) with `service: looker-ai` and `accessType: model`. Three filters narrow them, each keyed on `name`:

* `instance`: the Looker instance, by the identifier you gave it in P0.
* `model`: the LookML model, by its name.
* `level`: `read` or `edit`.

For example, this policy auto-approves read access for one agent, but only to the `sales` model in the `analytics` instance:

```yaml
- requestor:
    type: agentic
    actor:
      type: agent-client
      clientId: reporting-agent
    subject:
      type: any
  resource:
    type: integration
    service: looker-ai
    accessType: model
    filters:
      instance:
        effect: keep
        key: name
        pattern: ^analytics$
      model:
        effect: keep
        key: name
        pattern: ^sales$
      level:
        effect: keep
        key: name
        pattern: ^read$
  approval:
    - type: persistent
```

## Remove the integration

1. **End or revoke every active grant**, so that P0 deletes their Looker service accounts.
2. **Remove the Looker resources** from your Terraform configuration: `p0_looker_ai`, `p0_looker_ai_staged`, the connector and its service account, the Admin key's secret, and the connector's IAM roles and bindings. Keep `p0_gcp` and the enabled APIs if anything else uses them. Then run `terraform apply`.
3. **Delete what P0 created in Looker.** In Looker, open the **Roles** page in the **Admin** panel. Delete the roles named `p0-looker-ai-...`, then the model sets and permission sets with that prefix. See [Creating, editing, and deleting roles](https://docs.cloud.google.com/looker/docs/admin-panel-users-roles#creating_editing_and_deleting_roles).
4. **Delete the connector's Looker service account** in Looker.

## Next steps

* Define the [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md) that decide which agents and users can request Looker access.
