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

# Salesforce MCP server

Install the Salesforce (AI) integration and its MCP server so agents behind the P0 AI Gateway can request Salesforce permission sets.

The **Salesforce (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 permission sets in your Salesforce org. Each gateway session gets its own API-only Salesforce user, and the gateway calls Salesforce's hosted MCP server as that user. The permission sets granted to the user decide what each tool can reach. When a grant ends, P0 removes its permission sets, and deactivates the user once it has none left.

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

Setup has four parts, in this order:

1. Install the P0 agent access package in your Salesforce org.
2. Install the org in P0, which deploys P0's connector in AWS or Google Cloud.
3. Add the Salesforce MCP server to your gateway.
4. Write the policies that decide which agents get which permission sets.

## 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://api.salesforce.com` and your org's My Domain host.
* One of these, with permission to apply Terraform where it's installed. P0's connector runs there, and stores the provisioner's consumer secret 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.
  * 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.
* A Salesforce admin user, and the [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli) and `jq` on the machine you set up from.
* A free Salesforce Integration user license for each agent user that is active at the same time. Every agent user has this license, and the package's tests create one during setup.

## Install the agent access package

The package holds what P0 needs in your org: the Apex classes that create agent users and exchange gateway tokens, the **P0 Agent** and **P0 Provisioner** external client apps, a `P0_Agents` role, and the permission sets those parts use.

1. **Create two users** in the org:
   * **The provisioner**: any user with API access and no admin permissions, such as a Salesforce Platform user. P0's connector signs in as this user, so give it nothing else.
   * **The handler's user**: the user that the token-exchange handler runs as. It must be an admin. Don't use the provisioner.
2. **Log in to the org** as an admin with the Salesforce CLI:

   ```bash
   sf org login web --alias <alias>
   ```
3. **Run the setup script** from P0's [Salesforce agent access repository](https://github.com/p0-security/p0-salesforce-agent-access). `--gateway-issuer` is your gateway's URL.

   ```bash
   git clone https://github.com/p0-security/p0-salesforce-agent-access.git
   cd p0-salesforce-agent-access
   ./setup.sh --target-org <alias> --gateway-issuer https://<gateway-host> \
     --provisioner-username <provisioner-username> \
     --handler-username <handler-username> --contact-email <admin-email>
   ```

   The script deploys the package and the two apps, gives the provisioner its permission set, and prints the org's full domain and both apps' consumer keys. Keep these for the next section. You can run the script again safely, and `./org-values.sh <alias>` prints the values again later.
4. **Choose the permission sets agents may request.** In Setup, open **Custom Metadata Types**, and add a **P0 Grantable Permission Set** record for each one. Agents can only request permission sets on this list.

   Agent users have the Salesforce Integration license, so a permission set with object permissions must use the **Salesforce API Integration** permission set license. P0 refuses permission sets that grant Modify All Data, View All Data, Manage Users, Author Apex, Customize Application, or Manage Profiles and Permission Sets.
5. **Turn on MCP.** In Setup, under **User Interface**, select **Enable MCP Service**. Then activate the `sobject-all` hosted MCP server.

{% hint style="info" %}
A new external client app can take up to 10 minutes to work. Until then, installing the org in P0 and agent tool calls fail.
{% endhint %}

## Install the org in P0

1. Navigate to **Integrations** on [p0.app](https://p0.app), select **Salesforce (AI)**, and choose the **Salesforce org** component.
2. Click **Add organization**, and enter the org's My Domain name, such as `acme` for `acme.my.salesforce.com`. Agents and policies use this name for the org. Use letters, digits, and hyphens.
3. Fill in the org details, then click **Next**:
   * **Full Salesforce domain**: the full domain the setup script printed. Enter only the host, without `https://`. Leave it empty if the domain is `<my-domain-name>.my.salesforce.com`.
   * **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.
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-salesforce-ai-aws`, that runs it with its own IAM role.
   * A secret for the org's provisioner consumer secret, `p0/install/salesforce/<my-domain-name>/consumer-secret`, which only the connector can read.
   * 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-salesforce-ai`, that runs P0's connector under its own service account.
   * A secret for the org's provisioner consumer secret, which only the connector can read.
   * 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 P0 Provisioner app's consumer secret. In Salesforce Setup, open **External Client App Manager**, then **P0 Provisioner**, and copy its consumer secret. Set `SF_CONSUMER_SECRET` to it, and run the command P0 shows. P0 never sees the secret: only your connector reads it.
6. Enter the consumer keys the setup script printed:
   * **Provisioner consumer key**: the P0 Provisioner app's key.
   * **Agent app consumer key**: the P0 Agent app's key.
7. Review the summary and click **Finish**. P0 checks that the connector can sign in to the org as the provisioner, and the org then appears with the state **Installed**.

Repeat for each org you want agents to reach.

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

## Add the Salesforce 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 **Token exchange (RFC 8693)**.
   * **Definition**: choose **P0**, then select **Salesforce**.
2. The server now appears with the state **Installed**.

One Salesforce MCP server serves every org you install. Each grant names the org it is for.

## How agents request access

An agent requests access with the server's `access` tool. It names one or more permission sets by their API names. If you install more than one org, it also names the org by its P0 identifier. Only an agent in a gateway session can request this access.

Once a request is approved, the agent's tool calls run as its agent user with those permission sets. Each gateway session has its own agent user, so a new session starts with no permission sets.

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" %}
Salesforce doesn't let P0 delete users, so every session leaves a deactivated agent user in your org.
{% endhint %}

## Write policies for Salesforce

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

* `org`: the org, keyed on `value`, the identifier you gave the org in P0.
* `permission-set`: the permission set, keyed on `name`, its API name. A rule covers a request only if it matches every permission set in it.

For example, auto-approve one read-only permission set for one agent, but only in the `acme` org:

```yaml
- requestor:
    type: agentic
    actor:
      type: agent-client
      clientId: reporting-agent
    subject:
      type: any
  resource:
    type: integration
    service: salesforce-ai
    accessType: permission-set
    filters:
      org:
        effect: keep
        key: value
        pattern: ^acme$
      permission-set:
        effect: keep
        key: name
        pattern: ^Agent_Read_Only$
  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 Salesforce access.
