Exchange Salesforce OAuth2 Authorization Code for Tokens
sf_exchange_oauth_codeExchanges an OAuth2 authorization code for a refresh token and instance URL, enabling persistent Salesforce API access without handling short-lived access tokens directly.
Instructions
Exchanges an OAuth2 authorization code for tokens. Set sandbox=true if the code was obtained from test.salesforce.com.
Returns the refresh_token (save this — it's long-lived!) and instance_url. The short-lived access_token is intentionally masked in the output to keep it out of MCP transcripts; you don't need it directly — pass refresh_token to the other tools and they obtain fresh access tokens on demand.
Error Handling:
"invalid_grant": code expired or already used — re-run sf_get_oauth_auth_url
"invalid_client": wrong client_id / client_secret (or Connected App still activating; wait 2-10 min after creating it)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sf_client_id | Yes | Salesforce Connected App Consumer Key (Client ID) | |
| sf_client_secret | Yes | Salesforce Connected App Consumer Secret (Client Secret) | |
| code | Yes | Authorization code from the OAuth redirect | |
| redirect_uri | No | Same redirect URI used when generating the auth URL | https://login.salesforce.com/services/oauth2/success |
| sandbox | No | Exchange against test.salesforce.com (sandbox) instead of login.salesforce.com |