Agent Wranglers

AGT-23Recommended

Run agent calls through the same business rules as the app

Agent tools call the same service functions as the app's own screens and API. No rule, limit or check exists in only one of them.

How to do it

A separate agent endpoint that writes to the database directly skips the stock check, the price rule or the audit log sooner or later. Make each tool a thin adapter that maps arguments to an existing service call. Add a rule once, in the service, and every channel gets it. Tests for business rules run against the service, plus one test per channel that proves it calls the service. Validate arguments first, as Design tools like a small public API says.

Examples

JavaScript example

server.registerTool('create_booking', bookingToolSpec, async (args, { auth }) =>
  toToolResult(await bookingService.create({ ...args, actor: actorsOf(auth.claims) })));

Python example

@mcp.tool(name="create_booking")
async def create_booking(slot: str, guests: int, ctx: Context) -> dict:
    return to_tool_result(await booking_service.create(slot=slot, guests=guests, actor=actors_of(ctx.auth.claims)))

How to check

A test runs each business rule case through the HTTP API and through the MCP tool. Both give the same outcome. A search of the tool code finds no SQL and no direct database client.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/agents-as-users/safe-actions/same-rules-for-agents">Agent Wranglers agents as users playbook</a>. In code you write, add a comment next to it with the same link.