# OAuth for external services

Connect to hosted MCP services through Teleport from your workstation or from inside a beam.

Use Notion or Linear's hosted MCP server without running your own MCP or OAuth server. Teleport controls which MCP tools you can call. The provider's OAuth login separately controls what those tools can see in your workspace.

Choose where to run the client-side gateway:

- **On your workstation:** Run your MCP client and Teleport's `tsh` gateway locally. You don't need a client beam.
- **Inside a beam:** Run your MCP client and `tsh` gateway inside the beam. Open the provider's sign-in page on your workstation and forward the browser callback into the beam.

Both modes use the same Teleport Application Service. You run it in a separate beam built from a phase, and it enrolls itself. In workstation mode, your client stays on your workstation; only the Application Service runs in a beam.

**Warning**

An external Teleport Application Service is required today. We plan to remove this requirement in **January 2027**. Until then, the phase below runs the service in a beam, so you don't need a separate Linux host.

**Install the client tools and sign in**

Beams is a [Teleport](https://goteleport.com) project and uses [official Teleport client tools](https://goteleport.com/download/client-tools/).

The client tools include `tsh` to sign in and run commands, and `tctl` to administer your cluster if you have permission.



Cluster: `example.beams.run`. Edit this example to use your cluster name.

Install version **18.11.10** of the client:

**macOS**

Download and open the macOS installer, then follow its instructions.

```sh
curl -O https://cdn.teleport.dev/teleport-tools-18.11.10.pkg
open teleport-tools-18.11.10.pkg
```

**Linux**

For Linux x86-64, download and install the client tools:

```sh
curl -O https://cdn.teleport.dev/teleport-v18.11.10-linux-amd64-bin.tar.gz
tar -xzf teleport-v18.11.10-linux-amd64-bin.tar.gz
sudo ./teleport/install
```

**Windows**

For Windows x86-64, run these commands in PowerShell. Add the extraction directory (`$env:LOCALAPPDATA\Teleport`) to your user PATH to use `tsh` in future terminals; the last command adds it to this terminal's PATH.

```powershell
Invoke-WebRequest -Uri https://cdn.teleport.dev/teleport-v18.11.10-windows-amd64-bin.zip -OutFile teleport.zip
Expand-Archive -Path teleport.zip -DestinationPath "$env:LOCALAPPDATA\Teleport" -Force
$env:Path += ";$env:LOCALAPPDATA\Teleport"
```

Follow the official client [tools install guide](https://goteleport.com/download/client-tools/) for other versions and architectures.

Check that you’re running v18.11.10 of the client with `tsh version`.

```sh
tsh version
```

**Passwordless**

I sign in without a password (e.g. a passkey).

```sh
tsh login --proxy='example.beams.run' --auth=passwordless
```

**Password \& MFA**

I have a password & MFA set up for my account:

Replace `you@example.com` with your Teleport username.

```sh
tsh login --proxy='example.beams.run' --user=you@example.com
```

**SSO**

I sign in with SSO (e.g. Okta, GitHub, SAML).

```sh
tsh login --proxy='example.beams.run'
```

You need a Beams-enabled Teleport cluster with MCP access and a `tsh` version that supports `tsh mcp login`. You also need a Notion or Linear account that can authorize the integration for a test workspace, and a browser on your workstation. For the tool call below, [install and sign in to Claude Code](https://code.claude.com/docs/en/quickstart) wherever you run it, or use another client that can launch a stdio command. An admin needs permission to build a phase, create a beam, enroll applications, and assign roles.



## 1. Choose a provider and test item

| Provider | Hosted streamable HTTP endpoint | Read-only test |
| --- | --- | --- |
| [Notion](https://developers.notion.com/guides/mcp/get-started-with-mcp) | `https://mcp.notion.com/mcp` | Search for a non-sensitive page named `MCP OAuth demo`. Give the OAuth connection access to the page when Notion offers that choice. |
| [Linear](https://linear.app/docs/mcp) | `https://mcp.linear.app/mcp` | Look up a non-sensitive test issue by its identifier, such as `DEMO-123`. Request the `read` OAuth scope. |

You only need one provider. The examples use the Teleport app name `notion-demo`. For Linear, substitute `linear-demo` in the commands and follow the Linear login variant.

## 2. Enroll the hosted MCP server and grant access

### Create the Application Service role

The Application Service beam joins the cluster by itself. It uses its own delegated identity to create a single-use [`bound_keypair`](https://goteleport.com/docs/reference/deployment/join-methods/#bound-keypair-bound_keypair) join token, so you never copy a token into the beam. Save this role as `mcp-oauth-gateway-host.yaml`:

```yaml
kind: role
version: v8
metadata:
  name: mcp-oauth-gateway-host
spec:
  allow:
    rules:
      - resources: [token]
        verbs: [create, update]
```

`tctl create -f` needs both verbs to write a bound keypair token. Create the role and add it to your user while keeping your existing roles, then sign in again:

**Teleport admin terminal**

```sh
tctl create -f mcp-oauth-gateway-host.yaml
me=$(tsh status --format=json | jq -r .active.username)
roles=$(tctl get "users/$me" --format=json | jq -r '.[0].spec.roles | join(",")')
tctl users update "$me" --set-roles="$roles,mcp-oauth-gateway-host"
```

**Warning: Treat the Application Service beam as privileged**

`mcp-oauth-gateway-host` can create and replace join tokens of any type. Delegate it only to the Application Service beam. Never give it to an agent or the client beam.

### Build the Application Service phase

Save the following as `phase.yaml`. The `env` values at the top of each step are the only settings you need to change:

| Setting | Default | Meaning |
| --- | --- | --- |
| `TELEPORT_AGENT_VERSION` | empty | Agent version to install. Empty uses the version your cluster recommends. |
| `MCP_APPS` | `notion-demo=…` `linear-demo=…` | Space-separated `name=URL` pairs. Each hosted MCP endpoint becomes a Teleport app with that name. |
| `MCP_APP_LABELS` | `demo=mcp-oauth` | Comma-separated labels on every app. The demo role below matches `demo: mcp-oauth`. |
| `AGENT_NAME` | `mcp-oauth-gateway` | Name of the Application Service in your cluster. |
| `JOIN_WINDOW` | `10 minutes` | Time the service has to join after it creates its token. |

```yaml
version: v1
metadata:
  name: mcp-oauth-gateway
commands:
  - comment: Install the Teleport agent for this cluster
    env:
      # Leave empty to use the agent version your cluster recommends.
      - name: TELEPORT_AGENT_VERSION
        value: ""
    shell: |
      set -eu
      find=$(curl -fsS "https://$TELEPORT_PROXY/v1/webapi/find")
      version=${TELEPORT_AGENT_VERSION:-$(printf '%s' "$find" | jq -er .auto_update.agent_version)}
      version=${version#v}
      flavor=teleport
      [ "$(printf '%s' "$find" | jq -r .edition)" = ent ] && flavor=teleport-ent
      tarball="$flavor-v$version-linux-$(dpkg --print-architecture)-bin.tar.gz"
      cd "$(mktemp -d)"
      curl -fsSLO "https://cdn.teleport.dev/$tarball"
      curl -fsSL "https://cdn.teleport.dev/$tarball.sha256" | sha256sum --check -
      tar -xzf "$tarball" "$flavor/teleport"
      # Install only the agent; keep the beam's own tsh, tctl and tbot.
      install -D -m 755 "$flavor/teleport" /opt/teleport/bin/teleport
      /opt/teleport/bin/teleport version
services:
  - name: mcp-oauth-gateway
    context: runtime
    env:
      # Space-separated name=URL pairs. Remove a provider you don't use.
      - name: MCP_APPS
        value: notion-demo=https://mcp.notion.com/mcp linear-demo=https://mcp.linear.app/mcp
      # Comma-separated labels added to every app. Roles match on these.
      - name: MCP_APP_LABELS
        value: demo=mcp-oauth
      # Name shown for this Application Service.
      - name: AGENT_NAME
        value: mcp-oauth-gateway
      # Time allowed for the service to join after the token is created.
      - name: JOIN_WINDOW
        value: 10 minutes
    shell: |
      set -eu
      . /etc/environment
      # Wait for the beam's tbot to deliver this beam's identity.
      timeout 120 sh -c 'until [ -s ~/.tsh/current-profile ]; do sleep 1; done'
      state=$HOME/.mcp-oauth-gateway
      install -d -m 700 "$state"
      cd "$state"
      token="mcp-oauth-gateway-$BEAM_ID"
      # Create the single-use join token on first start only. A restart
      # reuses the identity the service already holds in data/.
      if [ ! -f teleport.yaml ]; then
        (umask 077; head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > secret)
        cat > token.yaml <<EOF
      kind: token
      version: v2
      metadata:
        name: $token
        expires: "$(date -u -d '+12 hours' +%Y-%m-%dT%H:%M:%SZ)"
      spec:
        roles: [App]
        join_method: bound_keypair
        bound_keypair:
          onboarding:
            registration_secret: "$(cat secret)"
            must_register_before: "$(date -u -d "+$JOIN_WINDOW" +%Y-%m-%dT%H:%M:%SZ)"
          recovery:
            limit: 1
            mode: standard
      EOF
        tctl create -f token.yaml
        rm token.yaml
      fi
      labels=$(printf '%s' "$MCP_APP_LABELS" | tr ',' '\n' | sed -n 's/^ *\([^=]*\)=\(.*\)$/        \1: "\2"/p')
      {
        cat <<EOF
      version: v3
      teleport:
        nodename: $AGENT_NAME
        data_dir: $state/data
        proxy_server: $TELEPORT_PROXY
        join_params:
          method: bound_keypair
          token_name: $token
          bound_keypair:
            registration_secret_path: $state/secret
      auth_service: { enabled: false }
      proxy_service: { enabled: false }
      ssh_service: { enabled: false }
      app_service:
        enabled: true
        apps:
      EOF
        for app in $MCP_APPS; do
          printf '    - name: %s\n      uri: mcp+%s\n      labels:\n%s\n' "${app%%=*}" "${app#*=}" "$labels"
        done
      } > teleport.yaml.tmp
      mv teleport.yaml.tmp teleport.yaml
      exec /opt/teleport/bin/teleport start --config="$state/teleport.yaml"
```

The **command** installs only the `teleport` binary, at the version and edition your cluster reports. It keeps the beam's own `tsh`, `tctl` and `tbot`. The image contains no tokens or credentials.

The **service** runs only in beams started from the phase (`context: runtime`). On first start it waits for `tbot`, then:

- Generates a random registration secret, readable only by the beam user.
- Creates a `bound_keypair` token named after the beam's ID, with the `App` role. The secret works once, and only until `JOIN_WINDOW` ends. The token itself expires an hour after the beam does.
- Writes the Application Service configuration and starts the service.

A restart reuses the identity the service already holds and doesn't create another token.

Build the phase, then start a beam from it, delegating only `mcp-oauth-gateway-host`. Don't publish this beam. The Application Service connects out to your cluster and the provider over HTTPS.

**Teleport admin terminal**

```sh
tsh phase apply -f phase.yaml
tsh beams add --phase=mcp-oauth-gateway --roles=mcp-oauth-gateway-host --no-share-connected-accounts --no-console
```

The apps register within a minute. Check them with `tctl`, because you haven't granted MCP access yet:

**Teleport admin terminal**

```sh
tctl get app_server --format=json | jq -r '.[] | select(.spec.app.metadata.labels.demo == "mcp-oauth") | .spec.app.metadata.name' | sort -u
```

```text
linear-demo
notion-demo
```

If they don't appear, read the service logs with `tsh beams exec SERVICE_BEAM -- beamctl logs mcp-oauth-gateway`. Replace `SERVICE_BEAM` with the beam's name from `tsh beams ls`.

### Grant access to the demo tools

Save the role below as `mcp-oauth-demo.yaml`. It matches the demo apps by label and allows only search and lookup tools. Tool names are case-sensitive. If a provider changes a tool name, check its current tool documentation and update the allowlist rather than allowing every tool.

```yaml
kind: role
version: v8
metadata:
  name: mcp-oauth-demo
spec:
  allow:
    app_labels:
      demo: mcp-oauth
    mcp:
      tools: [notion-search, get_issue]
```

**Teleport admin terminal**

```sh
tctl create mcp-oauth-demo.yaml
```

Assign `mcp-oauth-demo` to your test user through your Teleport role mapping (or edit a local user in the Teleport Web UI), then sign in again. Use a test identity that does not already have unrestricted MCP permissions. For the beam mode, the test user also needs `beam-user` and permission to delegate `mcp-oauth-demo`.

**Local terminal**

```sh
tsh mcp ls
```

Check that your chosen demo app appears. If it is missing, check the Application Service logs, app labels, and your refreshed roles before attempting OAuth.

## 3. Authorize and connect in your chosen mode

### Mode A: Standalone gateway on your workstation

Run the login for your provider. Complete authorization in your workstation browser. If Notion prompts you to select pages, allow the demo page; if Linear prompts you to select a workspace, choose the one with your test issue. The browser can reach `tsh`'s loopback callback directly, so no port forward is needed.

**Local terminal**

```sh
# Notion
tsh mcp login notion-demo

# Or Linear, with read-only OAuth access
tsh mcp login linear-demo --oauth-scope=read
```

For Claude Code, register the local gateway from your project directory. Run only the command for the provider you authorized:

**Local terminal**

```sh
claude mcp add --transport stdio notion-demo -- tsh mcp connect notion-demo
claude mcp add --transport stdio linear-demo -- tsh mcp connect linear-demo
```

### Mode B: Gateway and client inside a beam

Start a separate client beam that holds only the needed roles. Keep the Application Service beam running. Note the client beam's `id` and `uuid` in the output. Use the `uuid` in place of `BEAM_UUID` to start the SSH tunnel from your workstation. Keep the tunnel open in its own terminal.

**Local terminal**

```sh
tsh beams add --roles=beam-user,mcp-oauth-demo --no-share-connected-accounts --no-console --format=json
tsh ssh -N -L 127.0.0.1:3118:127.0.0.1:3118 beams@BEAM_UUID
```

Use plain `tsh ssh` for forwarding; `tsh beams ssh` does not accept `-L`. The tunnel forwards only the browser callback. The OAuth issuer itself still needs a public HTTPS URL.

In a second workstation terminal, connect using the beam's `id` in place of `my-beam`:

**Local terminal**

```sh
tsh beams ssh my-beam
```

Inside the beam, confirm the MCP server is visible, then run the login for your provider:

**Inside the beam**

```sh
tsh mcp ls

# Notion
tsh mcp login notion-demo --callback-port=3118 --browser=none

# Or Linear, with read-only OAuth access
tsh mcp login linear-demo --callback-port=3118 --browser=none --oauth-scope=read
```

Open the printed authorization URL in your workstation browser, authorize the test workspace, then return to the beam terminal and confirm that `tsh` reports a successful login. The callback goes through SSH, so `tsh` stores the OAuth tokens in the beam, not on your workstation. Don't paste the authorization URL or token files into chats or logs.

Register the gateway in Claude Code from your project directory inside the beam. Run only the command for the provider you authorized:

**Inside the beam**

```sh
claude mcp add --transport stdio notion-demo -- tsh mcp connect notion-demo --browser=none
claude mcp add --transport stdio linear-demo -- tsh mcp connect linear-demo --browser=none
```

## 4. Verify a read-only tool call

Start Claude Code in the same place you configured the gateway. If it was already running, restart it. Check `/mcp` for the connection, then ask it to find the Notion test page by title or look up the Linear test issue by ID. Confirm the response came from an MCP tool call, not from the model guessing. For another stdio client, configure the same `tsh mcp connect` command and arguments as above.

Do not use your MCP client's built-in OAuth login for the Teleport connection or set a custom `Authorization` header on `tsh mcp connect`; it can override the token from `tsh mcp login`. If authorization expires and refresh fails inside a beam, rerun the login with the callback tunnel open and restart the client.

## 5. Clean up

Stop the MCP client, then run `tsh mcp logout notion-demo` or `tsh mcp logout linear-demo` **where you ran the login**. This clears Teleport's stored provider credentials for that app. If you also want to revoke the provider grant, do so in Notion or Linear. In beam mode, stop the callback tunnel and remove the test beam with `tsh beams rm my-beam` after saving any work you need. Do not include OAuth credentials in a phase snapshot.

Remove the Application Service beam with `tsh beams rm SERVICE_BEAM`. Its apps disappear from the cluster shortly after. Delete its join token, or let it expire an hour after the beam does:

**Teleport admin terminal**

```sh
tctl get tokens --format=json | jq -r '.[].metadata.name | select(startswith("mcp-oauth-gateway-"))'
tctl rm token/TOKEN_NAME
```

Keep the phase for another test, or remove it with `tsh phase rm mcp-oauth-gateway`. Remove the demo role assignments, then use `tctl rm role/mcp-oauth-demo` and `tctl rm role/mcp-oauth-gateway-host` if no one needs them.

## Troubleshoot OAuth

- **The browser says it cannot connect to the callback:** Keep the SSH tunnel open and use the same port on both ends and in `--callback-port`. Restart the login if it timed out.
- **The provider denies access or finds no results:** Check the selected workspace, that the test item is shared with the connection, and that workspace policy allows the integration. For Linear, keep the `read` scope.
- **The server is visible but a tool is missing:** Check the Teleport MCP tool allowlist and the provider's tool names. Provider access does not override Teleport roles.
- **The issuer is rejected:** `tsh` contacts the provider's public HTTPS issuer directly from the machine running `tsh`; private or loopback issuer addresses are not supported. This does not prevent the browser callback from using loopback.
