Mastra
Check every tool call a Mastra agent makes with Thoth before the tool runs.
governMastraTools returns governed copies of the tools you give a
Mastra Agent. Each tool call is checked with Thoth
before the tool's execute runs. It needs @atensec/thoth 0.2.0 or later,
and is tested with @mastra/core 1.81.0
(framework compatibility).
Install
Register the agent in Thoth first, and give your app its connection settings:
Your first governed agent covers registering an agent and creating its key.
Govern an agent's tools
Thoth sees each tool by its key in the object you pass, the name the model
calls it by (sendRefund above), with the tool's input as its arguments.
Mastra's execution context reaches execute unchanged. The governed copies
keep each tool's fields and class, and the tools you pass in aren't changed.
Tools without an execute are returned as they are and aren't checked.
What each decision does
| Decision | What happens |
|---|---|
ALLOW | execute runs. |
DENY | execute never runs. The governed tool throws ThothPolicyViolation, and Mastra passes the refusal to the model as the tool's error output ("Thoth blocked tool 'sendRefund': …"). generate carries on, so the model can tell the user. |
STEP_UP | The call waits for a person to approve it, up to stepUpTimeoutMinutes (15 by default). If it's approved, execute runs; otherwise it's refused as for DENY. |
If Thoth can't be reached, calls are refused unless you set failOpen: true.
Start a new agent in observe: Thoth records what it would have decided and every call runs. Switch the agent to enforce when the observe summary shows it's ready.