Agents
One write path for people and agents
The web app and the AI assistant each had their own code for updating a task. Now both hand the write to one shared service, so they cannot disagree.
The problem
Blackhawk's platform can be driven two ways. A person clicks through the web app, or an assistant calls an MCP tool. Each had its own code for updating a task.
Two copies of one rule drift apart. The repo kept a matrix of the differences between the two, field by field and side effect by side effect. Every new rule had to be added twice and checked twice.
The decision
I moved the rules into one shared function that both surfaces call. The detail that matters: the assistant does not go through the web app's API. The web route and the MCP tool each call the same service underneath.
Both surfaces hand the write to the same function, so the behaviour is identical by construction.
Two callers, one function
This is the web route, after it has signed the user in and checked that the task belongs to their organization.
// Web route: sign in, check the organization, then hand over.
const result = await updateTask({
taskId,
changes: body,
actor: user,
organizationId,
});And this is the MCP tool, after its own checks.
// Assistant tool: resolve names to ids, check the tenant, then hand over
// to the very same function.
const result = await updateTask({
taskId: args.id,
changes: resolved,
actor: session.user,
organizationId: task.organizationId,
});Same function, same shape of arguments. The visible difference is the database client. The route passes the user's own client, where the database enforces what they can see. The MCP tool passes a full-access client, so it has to check the tenant itself before it gets this far.
What each surface keeps
Each surface keeps only the work that belongs to how it is reached.
- The web route signs the user in, checks the organization and returns HTTP errors.
- The MCP tool turns the names and emails an assistant uses into ids, checks the tenant, shows a preview and waits for a person to confirm.
Everything that decides what an update means lives in the shared function: recurrence, cascading a status change to subtasks, moving a task between clients, notifications. A new side effect goes there, never in one caller.
Completing or reopening a task is its own shared operation, used by the web app, bulk edits and the MCP tool. The update function refuses a completion outright, so there is no second path hiding there either.
Preview, then confirm
Every MCP write tool takes a confirm flag. Without it, the tool describes what it would do and writes nothing. For a task update that means each changed field as a from and a to, so the person approves the actual change.
interface Preview<T> {
preview: true;
what: string; // a plain description of the change
would: T; // exactly what would be written
instruction: string;
}
function preview<T>(what: string, would: T): Preview<T> {
return {
preview: true,
what,
would,
instruction:
'Nothing was written. Show this to the user. If they approve, ' +
'call again with the same arguments plus confirm: true.',
};
}There is no pending-write table on the server. The assistant shows the preview to the person and calls again with the same arguments plus confirm. A test reads every write tool's source and fails if the preview gate is missing or sits after a write.
The same refusals, in two dialects
Sometimes the shared function has to stop and ask. Closing a task that still has open subtasks is one case. It throws a conflict error with a stable code. The web app shows that as a dialog. The MCP tool turns the same error into data the assistant can read and act on.
// The shared function refuses with "needs confirmation". The web app shows
// a dialog. For an assistant, the same refusal becomes a question to relay.
function asAssistantQuestion(error: unknown) {
if (!isConfirmationRequired(error)) return null; // stays an ordinary error
return {
confirmationRequired: true,
openSubtasks: error.details.openSubtasks,
instruction:
'Nothing was written. Ask the user whether to complete the ' +
'subtasks too, then call again with their answer.',
};
}The rule itself is written once. Only the way it is presented differs.
What changed
- The matrix of differences was deleted. The document that replaced it lists only what each surface does before and after it calls the shared function.
- I made the first MCP commit in April 2026 and added sign-in for Claude connectors the next day.
- I added the shared task service in June 2026, wrote the parity contract in July and applied the same pattern to creating and updating contracts in September.
- The repo today has 57 shared service files across tasks, contracts, employees and performance reports, and 113 MCP tool files. A teammate also contributed MCP tools.
- The repo now states it as a rule: one write path per mutation.
An agent is only safe to trust with real work if it cannot do anything the product itself would refuse. Sharing the write path makes that true without anyone having to remember it.