> 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/oauth-client.md). Agents can also search and read this documentation through its [MCP server](https://docs.p0.dev/~gitbook/mcp).

# Register an upstream OAuth client

Create an OAuth app in an upstream service and register its client ID and secret on the P0 AI Gateway, so users can sign in to an OAuth MCP server that needs a preregistered client.

Some MCP servers with **Credential source** set to **OAuth** sign users in through a service that requires manually configured OAuth clients. For these servers, you create an OAuth app in the upstream service, then enter its client ID and secret on a form hosted by your gateway. The gateway uses that client for every user who signs in to the server.

You enter the secret on your P0 AI Gateway, so it never passes through the P0 controller.

## Prerequisites

* An MCP server with **Credential source** set to **OAuth**, installed on a gateway that has finished setup. See [MCP server](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server.md#add-an-mcp-server).
* The P0 **Owner** role, assigned to you directly or through a group.
* Permission to create OAuth apps in the upstream service.
* The gateway must cache using Valkey. The batteries-included chart includes it by default. A gateway that keeps its cache in memory can't save a client. See [Deploying the gateway](https://docs.p0.dev/agentic-access/agentic-gateway/gateway/deploy.md).

## Create the upstream OAuth app

1. **Create an OAuth app** in the upstream service. The service may call it an OAuth client, an app integration, or a connected app.
2. **Set its callback URL** to your gateway's callback address, where `<gateway-host>` is your gateway's public hostname:

   ```
   https://<gateway-host>/authorize/mcp-callback
   ```

   The service may call this the redirect URL or redirect URI. The registration form below also shows this address, so you can copy it from there.
3. **Copy the client ID and client secret.** Many services show the secret only once, so keep it somewhere safe until you finish the next section.

## Register the client on the gateway

1. **Open the server list.** Go to **Agentic Access** on [p0.app](https://p0.app) and open the **MCP servers** tab.
2. **Open the form.** Click **Register OAuth client** next to the server. The gateway opens in a new tab.
3. **Sign in to the gateway.** Use your normal sign-in for the gateway.
4. **Check the server.** The form shows the **MCP server**, its **Callback URL**, and its **Status**. Make sure the callback URL matches the one you set in the upstream app.
5. **Fill in the form:**
   * **Client ID**: the client ID from the upstream app.
   * **Client secret**: the client secret from the upstream app.
   * **Token endpoint auth method**: how the gateway sends the secret to the upstream service. Choose `client_secret_basic` unless the service's docs ask for `client_secret_post`.
   * **Issuer**: the gateway fills this in from the server's OAuth settings. Leave it as it is. The gateway rejects any other value.
6. **Click Save.** When you see **OAuth client registered**, close the tab.

Users can now sign in to the server through the gateway. Each user signs in with their own upstream account the first time they use the server.

To remove the client, open the form again and click **Clear registration**. Users can't sign in to the server again until you register a client.

## Rotate the client secret

1. **Create a new secret** in the upstream app. If the service lets an app hold two secrets at once, keep the old one until step 4.
2. **Open the form** for the server, as in [#register-the-client-on-the-gateway](#register-the-client-on-the-gateway "mention").
3. **Enter the same client ID and the new secret,** choose the same auth method, and click **Save**. The new secret replaces the old one.
4. **Delete the old secret** in the upstream app.

Users who already signed in stay signed in, as long as the client ID doesn't change. If you switch to a different upstream app, with a new client ID, each user signs in again.

## Enter the secret again

If the form shows **Not configured** for a server you registered before, the gateway no longer has the client. Users can't sign in to the server until you register it again.

1. **Find the client ID and secret.** If you no longer have the secret, create a new one in the upstream app.
2. **Register the client** with the steps in [#register-the-client-on-the-gateway](#register-the-client-on-the-gateway "mention").

## Related

* [SaaS MCP servers](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/saas.md): P0's predefined SaaS servers, which sign users in with OAuth.
* [OAuth servers from a headless agent](https://docs.p0.dev/agentic-access/using-the-gateway/headless-oauth-credentials.md): register an OAuth credential for an agent that has no one to sign in.
