Skip to content
Last updated

Auto-Refresh Script for Celonis Access Tokens

This script automatically fetches a fresh Celonis access token and updates your Claude Desktop config file so you never have to do it manually. You can choose to run it once before starting Claude Desktop or set it to run automatically each time you login. Without this script, the access token will need to be manually refreshed every 15 minutes.


Auto-refresh scripts

Save the corresponding script below as either refresh-token.sh (Mac/Linux) or refresh-token.bat (Windows) on your computer.

Mac / Linux (refresh-token.sh)

#!/bin/bash

# ── Celonis credentials ───────────────────────────────────────────────────────
CELONIS_CLIENT_ID="YOUR-CLIENT-ID"
CELONIS_CLIENT_SECRET="YOUR-CLIENT-SECRET"
CELONIS_TEAM="YOUR-TEAM"
CELONIS_REALM="YOUR-REALM"
CELONIS_MCP_SERVER_ID="YOUR-MCP-SERVER-ID"

# ── Config file path ──────────────────────────────────────────────────────────
CONFIG_FILE="$HOME/Library/Application Support/Claude/claude_desktop_config.json"

# ── Fetch a new access token ──────────────────────────────────────────────────
echo "Fetching new Celonis access token..."

TOKEN_RESPONSE=$(curl --silent --request POST \
  --url "https://${CELONIS_TEAM}.${CELONIS_REALM}.celonis.cloud/oauth2/token" \
  --header "content-type: multipart/form-data" \
  --form "client_id=${CELONIS_CLIENT_ID}" \
  --form "client_secret=${CELONIS_CLIENT_SECRET}" \
  --form "grant_type=client_credentials" \
  --form "scope=mcp-asset.tools:execute")

ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")

if [ -z "$ACCESS_TOKEN" ]; then
  echo "❌ Failed to fetch access token. Check your credentials."
  exit 1
fi

echo "✅ Token fetched successfully."

# ── Write updated config file ─────────────────────────────────────────────────
cat > "$CONFIG_FILE" <<EOF
{
  "mcpServers": {
    "celonis": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://${CELONIS_TEAM}.${CELONIS_REALM}.celonis.cloud/studio-copilot/api/v1/mcp-servers/mcp/${CELONIS_MCP_SERVER_ID}",
        "--header",
        "Authorization:\${AUTH_TOKEN}"
      ],
      "env": {
        "AUTH_TOKEN": "Bearer ${ACCESS_TOKEN}"
      }
    }
  }
}
EOF

echo "✅ Claude Desktop config updated. Restart Claude Desktop to apply."

Windows (refresh-token.bat)

@echo off

:: ── Celonis credentials ───────────────────────────────────────────────────────
set CELONIS_CLIENT_ID=YOUR-CLIENT-ID
set CELONIS_CLIENT_SECRET=YOUR-CLIENT-SECRET
set CELONIS_TEAM=YOUR-TEAM
set CELONIS_REALM=YOUR-REALM
set CELONIS_MCP_SERVER_ID=YOUR-MCP-SERVER-ID

:: ── Config file path ──────────────────────────────────────────────────────────
set CONFIG_FILE=%APPDATA%\Claude\claude_desktop_config.json

:: ── Fetch a new access token ──────────────────────────────────────────────────
echo Fetching new Celonis access token...

curl --silent --request POST ^
  --url "https://%CELONIS_TEAM%.%CELONIS_REALM%.celonis.cloud/oauth2/token" ^
  --header "content-type: multipart/form-data" ^
  --form "client_id=%CELONIS_CLIENT_ID%" ^
  --form "client_secret=%CELONIS_CLIENT_SECRET%" ^
  --form "grant_type=client_credentials" ^
  --form "scope=mcp-asset.tools:execute" ^
  --output token_response.json

for /f "tokens=*" %%a in ('python -c "import json; data=json.load(open('token_response.json')); print(data['access_token'])"') do set ACCESS_TOKEN=%%a
del token_response.json

if "%ACCESS_TOKEN%"=="" (
  echo Failed to fetch access token. Check your credentials.
  exit /b 1
)

echo Token fetched successfully.

:: ── Write updated config file ─────────────────────────────────────────────────
(
echo {
echo   "mcpServers": {
echo     "celonis": {
echo       "command": "npx",
echo       "args": [
echo         "-y",
echo         "mcp-remote",
echo         "https://%CELONIS_TEAM%.%CELONIS_REALM%.celonis.cloud/studio-copilot/api/v1/mcp-servers/mcp/%CELONIS_MCP_SERVER_ID%",
echo         "--header",
echo         "Authorization:${AUTH_TOKEN}"
echo       ],
echo       "env": {
echo         "AUTH_TOKEN": "Bearer %ACCESS_TOKEN%"
echo       }
echo     }
echo   }
echo }
) > "%CONFIG_FILE%"

echo Claude Desktop config updated. Restart Claude Desktop to apply.

Run the script manually

Mac / Linux

  1. Open Terminal.
  2. Navigate to the folder where you saved the script: cd ~/Downloads
  3. Make it executable (first time only): chmod +x refresh-token.sh
  4. Run the executable: ./refresh-token.sh
  5. Restart Claude Desktop.

Windows

  1. Open File Explorer and find refresh-token.bat.
  2. Double-click the file to run it.
  3. Restart Claude Desktop.

Run the script automatically on login (optional)

If you want the token refreshed every time you start your computer:

Mac: Add the script to System Settings → General → Login Items.

Windows: Press Win + R, type shell:startup, and then add a shortcut to refresh-token.bat in that folder.


Placeholders to replace

PlaceholderWhat to put here
YOUR-CLIENT-IDOAuth Client ID from Celonis Admin settings
YOUR-CLIENT-SECRETOAuth Client Secret from Celonis Admin settings
YOUR-TEAMYour Celonis team subdomain
YOUR-REALMYour Celonis realm (e.g., us-1, eu-1)
YOUR-MCP-SERVER-IDThe ID of your published MCP Asset in Celonis Studio