@major-tech/agents-client lets an app’s server code start agent runs, read their messages, send follow-ups, stop them, and answer their tool approvals. For when to use it and who a run acts as, see App triggers.
Add an agent to your app
Each agent your app calls gets a generated client in the app’sclients/ folder (src/clients/ if the app has a src directory). The client is bound to the agent’s id and reads the app’s credentials from the environment, so there is nothing to configure.
- Platform Agent or MCP
- Locally
Ask for it: “Use the support-bot agent from this app.” The client is generated for you and the import line is added to your code.
Server code only
Use the client in Server Components, Server Actions, and Route Handlers, never in client components. It sends the app’sMAJOR_JWT_TOKEN, which must not reach the browser. The same credentials are injected while you build and after you deploy, so you can test the whole loop in the editor preview.
Start a run
run() returns { runId, status: "started" } as soon as the run is accepted. The agent runs in the background, so render a pending state and poll for results. Pass runId to every other method.
Read a run’s messages
limit messages (1-100), oldest first. role is user, assistant, or system. content depends on type (message, thinking, tool_use, tool_result, result, and system types), so render it defensively.
Send a follow-up, stop, and list runs
Answer tool approvals
If the agent has tools set to Ask (see Tool permissions), the run pauses when it wants to use one. Your app can show the pending call and let the user decide without leaving the page.- Show
toolNameandtoolArgsso the user sees exactly what will run. Usedescriptionas a summary when it’s present. - An approval left unanswered is denied at its
expiresAttime, and the run continues. - Poll
listPendingApprovalswhen the user opens the run or on a sensible interval, not in a tight loop. The run is already paused.
Methods
All types are exported from
@major-tech/agents-client.
Errors
Every error extendsAgentsClientError, which carries httpStatus and requestId (include the request id when you contact support). Branch on the subclass rather than parsing messages: