> 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/servicenow.md).

# ServiceNow MCP server

Install the ServiceNow (AI) integration and its MCP server so agents behind the P0 AI Gateway can request ServiceNow roles.

The **ServiceNow (AI)** integration lets agents behind the P0 AI Gateway (see [P0 Runtime Access for AI](https://docs.p0.dev/readme/agentic-control-plane.md)) request roles in your ServiceNow instance, such as `itil`. Each gateway session gets its own ServiceNow machine user. For each grant, P0's connector gives the user the approved roles, gets a token for the user, and stores it in your secret manager. The gateway runs P0's ServiceNow MCP server with that token, so ServiceNow's roles and access controls decide what each tool can reach. When the last grant of a session ends, P0 deletes the user.

{% hint style="info" %}
The ServiceNow (AI) integration is in beta. Functionality and configuration may change.
{% endhint %}

Setup has four parts, in this order:

1. Set up the instance for P0.
2. Install the instance in P0, which deploys P0's connector in AWS or Google Cloud.
3. Add the ServiceNow MCP server to your gateway.
4. Write the policies that decide which agents get which roles.

## Prerequisites

* A registered [Gateway](https://docs.p0.dev/agentic-access/agentic-gateway/gateway.md) component, with the gateway deployed in your environment. The gateway must be able to reach `https://<instance>.service-now.com` and your secret manager.
* One of these, with permission to apply Terraform where it's installed. P0's connector runs there, and session tokens are stored there.
  * On AWS:
    * The [AWS Secrets Manager](https://docs.p0.dev/integrations/resource-integrations/aws-secrets-manager.md) integration installed on an AWS account. The connector runs there on AWS Lambda. Applying its Terraform also needs Docker and the AWS CLI, signed in to that account, to copy P0's connector image into your Amazon ECR.
    * [AWS OIDC](https://docs.p0.dev/agentic-access/credential-sources/aws-oidc.md) installed for that same account. The gateway uses it to read each grant's token.
  * On Google Cloud:
    * The [Google Cloud](https://docs.p0.dev/integrations/resource-integrations/google-cloud.md) integration installed for your Google Cloud organization.
    * The [Google Secret Manager](https://docs.p0.dev/integrations/resource-integrations/google-secret-manager.md) integration installed on the Google Cloud project where the connector will run. The connector runs there on Cloud Run.
    * [GCP Workload Identity Federation](https://docs.p0.dev/agentic-access/credential-sources/gcp-wif.md) installed for that same project. The gateway uses it to read each grant's token.
* A ServiceNow admin user, and `openssl` and `jq` on the machine you set up from.

## Set up the instance

P0's connector uses two inbound integrations on your instance:

* **The provisioner** creates the agent users and sets their roles. It runs as a machine user that has only the `user_admin` role.
* **The JWT bearer integration** gives the connector a token for each agent user. It trusts a certificate whose private key only your connector holds.

1. **Turn on the client credential grant.** In **System Properties**, in the Global scope, set `glide.oauth.inbound.client.credential.grant_type.enabled` to `true`. If the property doesn't exist, create it as a `true | false` property.
2. **Create the provisioner user.** Create a user, such as `p0-provisioner`, and select **Web service access only**. Give it the `user_admin` role and no other role.
3. **Create the provisioner integration.** In **Machine Identity Console**, add an inbound integration of type **OAuth - Client credential grant**. Set its **OAuth application user** to the provisioner user. Keep its client ID and client secret.
4. **Make a signing key.** Run:

   ```bash
   openssl req -x509 -newkey rsa:2048 -nodes -days 730 \
     -subj "/CN=P0 ServiceNow connector" \
     -keyout p0-servicenow-signing-key.pem \
     -out p0-servicenow-signing-cert.pem
   ```

   Add the contents of `p0-servicenow-signing-cert.pem` as a trust store certificate, under **System Definition > Certificates**. Keep `p0-servicenow-signing-key.pem` for the next section, and delete it once it is stored.
5. **Create the JWT bearer integration.** In **Machine Identity Console**, add an inbound integration of type **OAuth - JWT bearer grant**. Add a JWT verifier map for the certificate, and choose a key ID (`kid`) for it, such as `p0-signing`. Set the user field to **User ID**. Keep its client ID and client secret.
6. **Give both integrations an auth scope** that covers the Table API, such as `useraccount`. Without one, every call fails with "Access to unscoped api is not allowed".

{% hint style="info" %}
A token lasts as long as the JWT bearer integration allows, 30 minutes by default. After that, the agent's tool calls fail, and the agent must request access again.
{% endhint %}

## Install the instance in P0

1. Navigate to **Integrations** on [p0.app](https://p0.app), select **ServiceNow (AI)**, and choose the **ServiceNow instance** component.
2. Click **Add instance**, and enter the instance name, such as `acme` for `acme.service-now.com`. Agents and policies use this name for the instance. Use lowercase letters, digits, and hyphens.
3. For **Secret manager provider**, choose where the connector will run:

   * **AWS Secrets Manager**: choose the installation for the AWS account, and enter the region that stores the secrets.
   * **Google Secret Manager**: choose the installation for the project.

   Click **Next**.
4. P0 generates a Terraform configuration. Copy it into your Terraform project, `apply` it, then click **Next**.

   On AWS, the configuration creates:

   * An Amazon ECR repository with a copy of P0's connector image, and a Lambda function, `p0-connector-servicenow-ai-aws`, that runs it with its own IAM role.
   * A secret for the two client secrets and the signing key, `p0/install/servicenow/<instance>/install`, which only the connector can read.
   * Permission for the connector to create and manage the secrets that hold session tokens. Their names start with `p0/access-token/servicenow/<instance>/`, and the connector can touch no other secret.
   * A policy on P0's IAM role in the account that lets P0 invoke the function.

   On Google Cloud, it creates:

   * A Cloud Run service, `p0-connector-servicenow-ai`, that runs P0's connector under its own service account.
   * A secret for the two client secrets and the signing key, `p0_install_servicenow_<instance>_install`, which only the connector can read.
   * Permission for the connector to create and manage the secrets that hold session tokens. Their names start with `p0_access-token_servicenow_<instance>_`, and the connector can touch no other secret.
   * Bindings that let P0's Google Cloud service account call the connector and read its URL. The connector accepts calls from that service account only.
   * The Cloud Run, Secret Manager, IAM, and Resource Manager APIs, turned on in the project.
5. Store the client secrets and the signing key. Set `SN_PROVISIONER_CLIENT_SECRET` and `SN_JWT_CLIENT_SECRET` to the two integrations' client secrets, put the signing key in `p0-servicenow-signing-key.pem`, and run the command P0 shows. On AWS:

   ```bash
   jq -n \
     --arg provisionerClientSecret "$SN_PROVISIONER_CLIENT_SECRET" \
     --arg jwtClientSecret "$SN_JWT_CLIENT_SECRET" \
     --rawfile signingKey p0-servicenow-signing-key.pem \
     '$ARGS.named' \
     | aws secretsmanager put-secret-value \
       --secret-id p0/install/servicenow/<instance>/install \
       --region <secrets-region> --secret-string file:///dev/stdin
   ```

   On Google Cloud:

   ```bash
   jq -n \
     --arg provisionerClientSecret "$SN_PROVISIONER_CLIENT_SECRET" \
     --arg jwtClientSecret "$SN_JWT_CLIENT_SECRET" \
     --rawfile signingKey p0-servicenow-signing-key.pem \
     '$ARGS.named' \
     | gcloud secrets versions add p0_install_servicenow_<instance>_install \
       --project=<project-id> --data-file=-
   ```

   P0 never sees these values: only your connector reads them.
6. Enter the integration details:
   * **Provisioner client ID**: the client ID of the provisioner integration.
   * **JWT bearer client ID**: the client ID of the JWT bearer integration.
   * **Signing key ID**: the `kid` of the certificate in the JWT verifier map.
7. Review the summary and click **Finish**. P0 checks that the connector can sign in to the instance as the provisioner and read its roles, and the instance then appears with the state **Installed**.

Repeat for each instance you want agents to reach.

{% hint style="warning" %}
Install each ServiceNow instance in its own AWS account or Google Cloud project. The Terraform for a second instance in the same account or project conflicts with the first.
{% endhint %}

To install with Terraform instead, use the `p0_servicenow_ai_staged` and `p0_servicenow_ai` resources of the [P0 Terraform provider](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/servicenow_ai). AWS Secrets Manager needs version 0.81.0 or later.

## Add the ServiceNow MCP server

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 the following fields, then click **Finish**:
   * **Credential source**: choose **Vaulted credential**.
   * **Definition**: choose **P0**, then select **ServiceNow**.
2. The server now appears with the state **Installed**.

One ServiceNow MCP server serves every instance you install. Each grant names the instance it is for.

The server's tools work on any table that the agent's roles allow:

* `query_records`: find records with an encoded query, such as `active=true^priority=1`.
* `get_record`: get one record by its `sys_id`.
* `describe_table`: list a table's fields, including inherited fields.
* `create_record`: create a record.
* `update_record`: change fields of one record.

There is no delete tool. ServiceNow returns no records, not an error, for a table that the agent's roles can't read.

## How agents request access

An agent requests access with the server's `access` tool. It names one or more roles by name, such as `itil`. If you install more than one instance, it also names the instance. Only an agent in a gateway session can request this access. The agent's `list` tool shows the installed instances and the roles it can request.

P0 never grants these roles to agents: `admin`, `impersonator`, `maint`, `mi_admin`, `oauth_admin`, `security_admin`, and `user_admin`. The provisioner can't grant other elevated roles either, because it has only `user_admin`. A request for a role that the provisioner can't grant fails, and the error names the role.

Once a request is approved, access usually works within 15 to 45 seconds, and can take up to two minutes. Each gateway session has its own agent user, so a new session starts with no roles. A new grant in the same session adds its roles to that user, and when a grant ends, P0 removes its roles.

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

{% hint style="info" %}
When the last grant of a session ends, P0 deletes the agent user and the secret that holds its token. ServiceNow stops the user's tokens at once.
{% endhint %}

## Write policies for ServiceNow

Match ServiceNow requests in an agentic access policy (see [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md)) with `service: servicenow-ai` and `accessType: role`. Two filters narrow them:

* `instance`: the instance, keyed on `value`, its instance name.
* `role`: the role, keyed on `name`. A rule covers a request only if it matches every role in it.

For example, auto-approve `itil` for one agent, but only on the `acme` instance:

```yaml
- requestor:
    type: agentic
    actor:
      type: agent-client
      clientId: triage-agent
    subject:
      type: any
  resource:
    type: integration
    service: servicenow-ai
    accessType: role
    filters:
      instance:
        effect: keep
        key: value
        pattern: ^acme$
      role:
        effect: keep
        key: name
        pattern: ^itil$
  approval:
    - type: persistent
```

## Next steps

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