Skip to main content

Tool call with a decision

One tool call of an agent, with the authorization decision next to it: allowed, needs approval, or refused with the reason.

PatternReadyView source
Works with
Reactshadcn/ui
Runs on sample data, with the neutral theme of shadcn/ui.

The record of one tool call in an agent interface. It shows the decision before the result, so a reader can see that the agent asked first. Open the second call to see its arguments.

Installation​

The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.

pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/tool-call.json

Usage​

Ask LumoAuth before the tool runs, and render the answer with the call. fromAskResult maps the answer of the Ask API.

app/chat/tool-calls.tsx
import { ToolCall, fromAskResult } from '@/components/tool-call';

// `answer` is what `agent.ask(action, context)` returned on your server.
export function RefundCall({ id, args, answer }: { id: string; args: Record<string, unknown>; answer: any }) {
return (
<ToolCall
call={{ id, tool: 'refund_invoice', server: 'Invoices MCP', args, ...fromAskResult(answer) }}
auditHref={(auditId) => `/admin/audit/${auditId}`}
/>
);
}

The Ask API answers yes or no. Set the decision to needs_approval yourself when your app turns a refusal into an approval request, and to budget_exceeded when the SDK throws LumoAuthBudgetExceededError.

Where the data comes from​

What the pattern showsCall
The decision for an actionagent.ask(action, context): allowed, reason, decided_by, audit_id
The decision for one MCP tool, in the agentagent.authorizeMcpTool()
The decision for one MCP tool, in the serverlumo.mcp.authorizeTool({ serverId, subject, tool })
A spent budget429 budget_exceeded, LumoAuthBudgetExceededError

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • Allowed and running.
  • Needs approval, with a button that starts the request.
  • Refused, with the reason and what decided.
  • Budget spent.
  • Allowed, and the tool failed.

Props​

PropTypeDefaultDescription
callrequiredToolCallDataThe tool call and its decision.
onRequestApproval(id: string) => voidShows "Ask for approval" on a call that needs approval.
auditHref(auditId: string) => stringBuilds the link to the audit record.
defaultOpenbooleanfalseShow the arguments at first.
classNamestringClass name for the block.

ToolCallData​

OptionTypeDescription
idrequiredstringAn ID for the call.
toolrequiredstringThe name of the tool.
decisionrequired'allowed' | 'needs_approval' | 'refused' | 'budget_exceeded'The decision.
serverstringThe MCP server or the service that holds the tool.
argsRecord<string, unknown>The arguments. They are collapsed at first.
reasonstring | nullThe reason that LumoAuth gave.
decidedBystring | nullWhat decided: capability, pdp (a policy) or deny_override.
status'running' | 'done' | 'error'The state of an allowed call.
resultReactNodeThe result of the tool, or the message of its failure.
auditIdstring | nullThe ID of the audit record.