Building an agent
Wire Agent Handler into your product so each user connects their own third-party accounts.
Wire Agent Handler into your product so each user connects their own third-party accounts.
This is the setup guide for Building an agent - your product runs an agent, and each user of your product (whether a customer or one of your own employees on an internal tool) connects their own Salesforce, Slack, GitHub, and the rest. Agent Handler holds their credentials, scoped per Registered User, and your backend orchestrates everything.
If your employees would rather plug an MCP URL into their own AI assistant or coding tool than use one you built, see Context layer for employees instead. For a comparison, see Use cases.
By the end of this guide your stack will look like this:
Production keys live at Settings → API Keys. You start with one production key and any number of test keys; test keys are sandboxed and isolated from production data. Use a test key while you build; switch when you’re ready for real customers.
Never expose the API key client-side. It authorizes calls on behalf of every one of your customers’ Registered Users. Keep it in your backend secret store.
Tool Packs decide what tools your agent can call. Create one in the Tool Packs dashboard, add the Connectors you need, and pick the specific tools to expose (most Connectors have 30–80 tools; you usually want a subset). Copy the pack’s ID from the URL - you’ll need it on every MCP call.
For one-vs-many packs, lifecycle, and overrides, see Tool Packs.
Create one Registered User per customer user, the moment they sign up for your product. The origin_user_id you pass is your own user ID - that’s how you find this Registered User later.
Store registered_user_id against your user record. The API call is idempotent on origin_user_id - calling it twice returns the existing Registered User rather than creating a duplicate.
The shared_credential_group is optional. Pass it when you want to Group users by tenant - typical in B2B products where one customer org has multiple users. See Companies and Groups for the details.
When a customer needs to authenticate a Connector, your frontend opens Link. There are two ways the flow gets triggered:
authenticate_meta tool result with a link_token. Your frontend catches it and opens Link.Pre-flight is more common; users prefer to set up integrations once instead of being interrupted mid-conversation.
Link tokens are short-lived (30 minutes) and single-use. Generate one per Link session.
Install the React component:
Open Link with the token your backend just minted:
For the authenticate_meta flow, intercept the tool call result in the agent’s response stream and feed the link_token field straight into the same component. See Link.
For email-driven authentication or any context where rendering a React component isn’t an option, use Magic Link instead - your backend mints a signed URL, you send it to the user, they authenticate in their own browser.
When the agent runs, your backend constructs the MCP URL and calls Agent Handler:
A minimal Python client using the official MCP SDK:
If you’re building a custom MCP client (for example, in a language without an SDK), you’re speaking JSON-RPC 2.0 over HTTP. See MCP integration for the wire-level walkthrough.
A few real failure modes worth anticipating.
Tool call returns 403 with unauthorized_tool. The tool isn’t in the Registered User’s Tool Pack. Check the Tool Pack contains the tool, and that you’re calling the right Tool Pack ID in the URL.
Tool call returns 401. Your API key is invalid, expired, or you’re using a test key against a production Registered User (or vice versa). Test and production data are isolated.
Tool call returns reauth_required. The user’s stored OAuth token is expired or revoked. Generate a fresh link token for the same Connector and reopen Link. The user re-authenticates; the call retries cleanly.
Tool call result is missing fields. The Security Gateway redacted them. Check the Alerts dashboard to see which rule fired. If you want the data through unredacted for one Tool Pack, add an override.
Link won’t open. Most often the link token expired (30-minute window) or it’s being reused. Generate a new token and open Link with that one.
For a fuller error catalog, see Troubleshooting.
Before you flip the switch on real customers:
Read Tool Packs for the full tool-pack lifecycle, or jump to Security Gateway to set up your data rules.