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.
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
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/tool-call.json
npx shadcn@latest add https://examples.lumoauth.dev/r/tool-call.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/tool-call.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/tool-call.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge button collapsibleInstall the packages.
npm install lucide-reactCopy the code into your project.
components/tool-call.tsx'use client';import * as React from 'react';import { Ban, Check, ChevronRight, CircleDollarSign, Hand, Loader2, Wrench } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';import { cn } from '@/lib/utils';export type ToolDecision = 'allowed' | 'needs_approval' | 'refused' | 'budget_exceeded';export interface ToolCallData {id: string;/** The name of the tool, for example `refund_invoice`. */tool: string;/** The MCP server or the service that holds the tool. */server?: string;args?: Record<string, unknown>;decision: ToolDecision;/** The reason that LumoAuth gave for the decision. */reason?: string | null;/** What decided: `capability`, `pdp` (a policy) or `deny_override`. */decidedBy?: string | null;/** Set while the tool runs, and when it is done. */status?: 'running' | 'done' | 'error';result?: React.ReactNode;/** The ID of the audit record of the decision. */auditId?: string | null;}/** Maps the answer of the Ask API (`agent.ask()`) to the decision of a call. */export function fromAskResult(result: { allowed: boolean; reason?: string | null; audit_id?: string | null; [key: string]: unknown },): Pick<ToolCallData, 'decision' | 'reason' | 'auditId' | 'decidedBy'> {return {decision: result.allowed ? 'allowed' : 'refused',reason: result.reason ?? null,auditId: result.audit_id ?? null,decidedBy: typeof result.decided_by === 'string' ? result.decided_by : null,};}const DECIDED_BY: Record<string, string> = {capability: 'a capability of the agent',pdp: 'a policy',deny_override: 'a deny rule',};const DECISION = {allowed: { icon: Check, label: 'Allowed', tone: 'text-emerald-700 dark:text-emerald-400', badge: 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-400' },needs_approval: { icon: Hand, label: 'Needs approval', tone: 'text-amber-700 dark:text-amber-400', badge: 'bg-amber-500/15 text-amber-700 dark:text-amber-400' },refused: { icon: Ban, label: 'Refused', tone: 'text-red-700 dark:text-red-400', badge: 'bg-red-500/15 text-red-700 dark:text-red-400' },budget_exceeded: { icon: CircleDollarSign, label: 'Budget spent', tone: 'text-red-700 dark:text-red-400', badge: 'bg-red-500/15 text-red-700 dark:text-red-400' },} as const;export interface ToolCallProps {call: ToolCallData;/** Shown for a call that needs approval. */onRequestApproval?: (id: string) => void;/** Builds the link to the audit record. */auditHref?: (auditId: string) => string;defaultOpen?: boolean;className?: string;}export function ToolCall({ call, onRequestApproval, auditHref, defaultOpen = false, className }: ToolCallProps) {const [open, setOpen] = React.useState(defaultOpen);const decision = DECISION[call.decision];const DecisionIcon = decision.icon;const hasArgs = call.args && Object.keys(call.args).length > 0;const source = call.decidedBy ? DECIDED_BY[call.decidedBy] ?? call.decidedBy : null;return (<Collapsible open={open} onOpenChange={setOpen} className={cn('w-full max-w-lg rounded-lg border bg-card text-sm text-card-foreground', className)}><div className="flex items-center gap-2 px-3 py-2"><CollapsibleTriggerdisabled={!hasArgs}className="flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"><ChevronRightclassName={cn('size-4 shrink-0 text-muted-foreground transition-transform', open && 'rotate-90', !hasArgs && 'opacity-0')}aria-hidden="true"/><Wrench className="size-4 shrink-0 text-muted-foreground" aria-hidden="true" /><span className="truncate font-mono text-[0.8125rem]">{call.tool}</span>{call.server && <span className="truncate text-xs text-muted-foreground">{call.server}</span>}</CollapsibleTrigger><Badge className={cn('border-transparent', decision.badge)}><DecisionIcon aria-hidden="true" />{decision.label}</Badge></div><CollapsibleContent><pre className="overflow-x-auto border-t bg-muted/40 px-3 py-2 font-mono text-xs leading-5">{JSON.stringify(call.args, null, 2)}</pre></CollapsibleContent><div className="grid gap-2 border-t px-3 py-2">{(call.reason || source) && (<p className={cn(call.decision === 'allowed' ? 'text-muted-foreground' : decision.tone)}>{call.reason ?? (call.decision === 'allowed' ? 'The agent may run this tool.' : 'The agent may not run this tool.')}{source && <span className="text-muted-foreground"> Decided by {source}.</span>}</p>)}{call.decision === 'allowed' && call.status === 'running' && (<p className="flex items-center gap-2 text-muted-foreground"><Loader2 className="size-4 animate-spin" aria-hidden="true" />Running…</p>)}{call.decision === 'allowed' && call.status === 'done' && call.result && (<div className="rounded-md bg-muted/60 px-2.5 py-2">{call.result}</div>)}{call.decision === 'allowed' && call.status === 'error' && (<p className="text-red-700 dark:text-red-400">{call.result ?? 'The tool failed.'}</p>)}<div className="flex flex-wrap items-center gap-2 empty:hidden">{call.decision === 'needs_approval' && onRequestApproval && (<Button size="sm" onClick={() => onRequestApproval(call.id)}>Ask for approval</Button>)}{call.auditId && auditHref && (<a href={auditHref(call.auditId)} className="text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground">Audit record</a>)}</div></div></Collapsible>);}Change the import paths if your project keeps its components in another place.
Usage
Ask LumoAuth before the tool runs, and render the answer with the call. fromAskResult maps the answer of the Ask API.
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 shows | Call |
|---|---|
| The decision for an action | agent.ask(action, context): allowed, reason, decided_by, audit_id |
| The decision for one MCP tool, in the agent | agent.authorizeMcpTool() |
| The decision for one MCP tool, in the server | lumo.mcp.authorizeTool({ serverId, subject, tool }) |
| A spent budget | 429 budget_exceeded, LumoAuthBudgetExceededError |
States
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
callrequired | ToolCallData | The tool call and its decision. | |
onRequestApproval | (id: string) => void | Shows "Ask for approval" on a call that needs approval. | |
auditHref | (auditId: string) => string | Builds the link to the audit record. | |
defaultOpen | boolean | false | Show the arguments at first. |
className | string | Class name for the block. |
ToolCallData
| Option | Type | Description |
|---|---|---|
idrequired | string | An ID for the call. |
toolrequired | string | The name of the tool. |
decisionrequired | 'allowed' | 'needs_approval' | 'refused' | 'budget_exceeded' | The decision. |
server | string | The MCP server or the service that holds the tool. |
args | Record<string, unknown> | The arguments. They are collapsed at first. |
reason | string | null | The reason that LumoAuth gave. |
decidedBy | string | null | What decided: capability, pdp (a policy) or deny_override. |
status | 'running' | 'done' | 'error' | The state of an allowed call. |
result | ReactNode | The result of the tool, or the message of its failure. |
auditId | string | null | The ID of the audit record. |