1. Prepare the environment and platform credentials
Clink configures credentials separately for each environment. Do not mix Sandbox UAT and Production tokens, user connections, MCP URLs, or callback URLs.
Below,
{API_BASE_URL} and {MCP_URL} stand for the URLs of the selected environment. The MCP URL is also the OAuth resource parameter and the audience of user tokens.
MCP uses the platform client_id and client_secret issued through Pre-registration, and shares the same platform client with the RESTful API. For how to apply, what Clink registers, and the RSA public key, see How to get platform credentials. When the client is set up, register the redirect_uri used for the user’s first authorization and the MCP scopes below.
In addition to the platform credentials, the backend also stores CLINK_API_BASE_URL and CLINK_MCP_URL. User tokens and decrypted card fields can be stored only on a trusted server. The MCP client configuration contains only the MCP URL; do not put a token or secret in it.
Set up a separate connection for each user, and store each user’s tokens separately on the server. All users share the same platform client; do not apply for a new client for each user.
Scope configuration
Clink configures scopes centrally based on the capabilities enabled for the platform; the platform does not need to register or assemble scopes one by one. When you apply, describe the capabilities the platform needs, and Clink configures the scopes for user authorization accordingly. The platform only needs to use the configuration Clink provides in the authorization flow. If the agent calls a capability that is not enabled, the tool returnsinsufficient_scope. To add a capability, contact Clink to update the configuration, then have the user authorize again. OAuth scopes only determine which tools the agent can call; they are not the same as the user authorizing a specific purchase. See Wallet Service for the difference.
2. Configure the agent’s system prompt
The platform’s agent needs a set of rules to know how to call Clink MCP tools, how to choose among the payment methods, and which operations are not allowed. Copy the rules below into the agent’s system prompt:- Copy the “Common rules” first. They are required.
- Then copy the modules that match the capabilities enabled for the platform, and append them in order after the common rules. The agent does not use a capability whose module you did not copy.
- Browser Pay, UCP Pay, and Quick Pay all use cards in the user’s wallet. When you integrate any of these payment methods, we recommend also copying Wallet Services.
clink://skill/rules from the server. When rules or a next_action returned by the server disagree with the system prompt, the server takes precedence. The common rules already state this.
Common rules (required)
Wallet Services
Manage cards, the default card, purchase authorizations, and risk rules. See Wallet Service for what it covers.Browser Pay
Pay by card on any merchant website. See Browser Pay for the flow.UCP Pay
UCP product search, UCP checkout, and benefit redemption. See UCP Pay for the flow.Quick Pay
Place orders directly with Clink merchants, and look up orders and refunds. See Quick Pay for the flow.3. Code integration
Clink MCP uses the Streamable HTTP transport with protocol version2026-07-28. Use an MCP client SDK or agent framework that supports this version; it handles protocol negotiation, request headers, and streamed responses.
After a user completes the first OAuth authorization and the tokens are exchanged, the platform server must persist the returned access_token, refresh_token, expiration time, and granted scopes per platform user and environment. Do not keep tokens only in the memory of the current request or agent process; otherwise the user’s MCP connection cannot be used after the service restarts.
access_token: used to call MCP. When it expires or you receive401, use the matchingrefresh_tokento get a new token.refresh_token: store it encrypted. Each refresh returns a new refresh token. Save the new value atomically first, then use the new access token. Refreshes for the same user and environment must be serialized so that concurrent refreshes do not reuse an old token.- User identifier: use the platform’s own stable user ID as the primary key, isolated by environment. Do not use an email address as the primary key, and do not reuse tokens across users or environments.
- After revocation or a failed refresh, delete the invalid local tokens and run the user authorization flow again. Do not bypass user authorization to create a new connection.
tokenStore should connect to a server-side database or secret store. withUserTokenRefreshLock should use a database lock or distributed lock to ensure that the same user and environment are never refreshed concurrently:
tokenStore needs a unique record per platformUserId + environment. A production implementation should also encrypt tokens with a key management service and keep token contents out of exceptions, logs, and monitoring. When revocation or refresh fails, delete the invalid credentials and guide the user through authorization again.
Register Clink as a remote MCP server in the agent framework:
url: the{MCP_URL}of the selected environment.Authorization:Bearer {USER_ACCESS_TOKEN}, the current user’s access token, injected per user at runtime.
/platform/sessions first:
- Returns
authorized: readaccess_tokenfrom the response, persist the tokens, then start this agent run. - Returns
authorization_required: do not start the agent or connect to MCP. Give theauthorization_urlfrom the response to the current user unchanged, and wait for the user to sign in and authorize. After the OAuth callback is validated, retry/platform/sessions, get theauthorizedresponse, and persist the tokens.
getAccessToken(), as shown below. It returns an access token that is still valid, or, when the token is about to expire, refreshes it serially and returns the new access token. Then inject this value into the agent framework’s MCP configuration.
authorization_required, the platform gives authorizationUrl to the current user. After the user authorizes and the callback succeeds, call startAgentRun() again. The server callback handler should first validate state, iss, and PKCE, then retry /platform/sessions and persist the access_token, refresh_token, expiration time, and scopes from the authorized response.
Do not get one token at service startup and share it across all users, and do not hardcode tokens in the agent configuration. After the MCP session is established, if a request returns 401, first close or rebuild the current MCP connection, then refresh that user’s token and retry once. Do not put tokens in tool arguments.
The platform server obtains and refreshes user access tokens through /platform/sessions and OAuth; see Agent Platform MCP Login for the flow. Inject tokens only on the server; do not write them into configuration files, the system prompt, or tool arguments.
- Claude Agent SDK
- OpenAI Agents SDK
- LangChain
- MCP TypeScript SDK
get_account_state: if you can read paymentMethods, the connection works; an empty list only means the wallet has no cards yet. On 401, refresh the user token. On 403 insufficient_scope, contact Clink to add the scope, then have the user authorize again.
Related docs
- How to get platform credentials: apply for
client_idandclient_secret, and the three registration methods. - Browser Pay guide: merchant checkout, credential protection, result reporting, and recovery.
- Wallet Service: how wallets, cards, and purchase authorizations relate.
- Agent Platform MCP Login:
/platform/sessionsfields and error handling. - Browser Pay tools: MCP tool fields and response structure.
- Operations and recovery: Operation states and recovery rules.
- Encrypted credential decryption: examples for decrypting
key/payload. - How to integrate RESTful API: integrate through the Agent Portal API without MCP.
- How to integrate Vault SDK: SDK integration in which the agent only handles placeholder cards.