Skip to content
Back to search

agentleisure-guard

Local gateway that guards any MCP server: approval for destructive calls, secret blocking, loop breaker, prompt-injection warnings. Zero dependencies, MIT.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/hsearth--agentleisure-guard/badge.svg)](/listings/hsearth--agentleisure-guard)

HTML

<a href="/listings/hsearth--agentleisure-guard"><img src="/api/listings/hsearth--agentleisure-guard/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 117 lines
  1. # agentleisure-guard
  2. Hard limits for AI agent tools, enforced in code instead of the prompt. Node 18+.
  3. **0 dependencies · 0 install scripts.** Installs cleanly under npm v12 defaults, with nothing to approve in `allowScripts`.
  4. - **Human approval** for destructive actions: `DROP`/`TRUNCATE`, `UPDATE`/`DELETE` without `WHERE`, `rm -rf` and PowerShell `Remove-Item -Recurse`, force push and remote branch deletion, `curl | sh`, database resets (`prisma migrate reset`), Terraform/Kubernetes/cloud deletions, `gh repo delete`, `npm unpublish`.
  5. - **Secret blocking**: API keys, private keys and `.env` contents never go out through a network tool.
  6. - **Loop breaker**: stops retrying the same failing call.
  7. - **Budget cap**: refuses a paid call before the money moves.
  8. - **Tamper-evident journal**: every call is written as a hash-chained JSON line.
  9. - **Untrusted text scan**: `scanUntrusted(text)` flags prompt injection in pages, issues, PR comments and tool results (override attempts, hidden characters and HTML, requests to send secrets, `curl | sh`).
  10. - **API deletes**: HTTP `DELETE` requests and GraphQL delete mutations need approval too.
  11. - **Credential files**: opening `.env`, SSH keys or cloud credentials needs approval (`allowSecretAccess: true` turns it off); templates like `.env.example` are fine.
  12. ```sh
  13. npm install agentleisure-guard
  14. ```
  15. ## Local guard
  16. ```js
  17. import { createGuard, agentLeisureApprover } from "agentleisure-guard";
  18. const guard = createGuard({
  19. approve: agentLeisureApprover({ apiKey: process.env.AGENTLEISURE_KEY }), // or your own async ({ tool, args }) => boolean
  20. budgetUsd: 5,
  21. maxFailures: 2,
  22. secretValues: [process.env.OPENAI_API_KEY],
  23. });
  24. const runSql = guard.wrap("run_sql", realRunSql);
  25. const httpPost = guard.wrap("http_post", realPost, { network: true, costUsd: 0.01 });
  26. ```
  27. A refusal throws a `GuardError` with a `code`, so the agent gets a clear, final "no".
  28. ## MCP gateway (no code)
  29. Put the guard in front of any stdio MCP server. Change the server command in your MCP client config:
  30. ```json
  31. {
  32. "mcpServers": {
  33. "github": {
  34. "command": "npx",
  35. "args": ["-y", "agentleisure-guard", "mcp", "--journal", "agent-journal.jsonl", "--",
  36. "npx", "-y", "@modelcontextprotocol/server-github"],
  37. "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "...", "AGENTLEISURE_KEY": "al_..." }
  38. }
  39. }
  40. }
  41. ```
  42. The gateway runs locally and checks every `tools/call` before the server sees it:
  43. - **Destructive calls and credential files**: with `AGENTLEISURE_KEY` set, the call waits until a human approves it (link in the log, or in Slack or Discord via `AGENTLEISURE_NOTIFY_URL`). With no key, the call is refused and the agent is told why. `--ask allow` forwards it with a warning instead.
  44. - **Secrets over the network**: always refused.
  45. - **Loops**: the same call more than 10 times in 5 minutes is refused (`--loop-limit`).
  46. - **Tool results**: text that tries to instruct the agent gets a warning in front of it.
  47. - **Tool descriptions**: a poisoned description hides the tool; a suspicious one gets a warning.
  48. - **Taint after injection**: once a tool result has tried to instruct the agent, any call that can send data out (network tools, commands, URLs) needs a human for the next 10 minutes. This catches the "read a poisoned PR comment, then post the keys" chain that per-call checks miss. `--no-taint` turns it off.
  49. - **Undo**: before a call deletes, moves or overwrites local files, the gateway copies them to `~/.agentleisure/snapshots`. `agentleisure-guard undo` lists snapshots; `agentleisure-guard undo <id>` restores one, and the state it replaces is saved too. `--no-snapshot` turns it off.
  50. - **Journal**: `--journal` writes a hash-chained line per call, which you can verify at https://agentleisure.com/safety/journal.
  51. Arguments and results stay on your machine. Only the approval summary goes to AgentLeisure, and only when you set a key.
  52. **Project rules.** Commit `agentleisure.policy.json` and the gateway adds your rules on top of the built-in ones (they can only make it stricter):
  53. ```json
  54. {
  55. "deny_tools": ["delete_repository", "*_admin"],
  56. "ask_tools": ["send_email", "deploy"],
  57. "protected_paths": ["./.git", "./infra", "~/.ssh"],
  58. "allowed_hosts": ["api.github.com", "*.your-company.com"],
  59. "observe": false
  60. }
  61. ```
  62. `allowed_hosts` is an egress allowlist: a call that would send data anywhere else needs a human, so even a fooled agent cannot ship your data to an attacker's server. `npx agentleisure-guard policy init` writes a starting file and `policy check` validates it.
  63. **Observe mode** (`--observe`, or `"observe": true` in the policy): nothing is blocked, every call that would have been stopped is logged, and a summary is printed on exit. Run it for a week before switching blocking on.
  64. **The guard talks to the agent.** The gateway adds two tools to the server's list: `agentleisure_policy` returns the rules in plain words so the agent can plan around them, and `agentleisure_ask_human` lets the agent ask you a yes/no question through your approval channel when it is unsure. `--no-agent-tools` turns them off.
  65. **Remote MCP servers** (Streamable HTTP) work too: the gateway still runs locally and connects out.
  66. ```json
  67. "remote-tools": {
  68. "command": "npx",
  69. "args": ["-y", "agentleisure-guard", "mcp", "--url", "https://mcp.example.com/mcp", "--bearer-env", "MCP_TOKEN"],
  70. "env": { "MCP_TOKEN": "..." }
  71. }
  72. ```
  73. `--remember-approval 15` lets the exact same call through for 15 minutes after a human approved it, so you are not asked again for a retry. A different call still asks.
  74. Other commands: `agentleisure-guard check <tool> '<json>'` and `agentleisure-guard scan <file>`.
  75. ## Hosted Guard API
  76. The same rules as one HTTP call. Works for tools written in any language.
  77. ```js
  78. import { checkToolCall, guardTool } from "agentleisure-guard";
  79. await checkToolCall("run_sql", { query: "DROP TABLE users" });
  80. // { decision: "ask", rule: "destructive", reason: "..." }
  81. const runSql = guardTool("run_sql", realRunSql, { apiKey: process.env.AGENTLEISURE_KEY });
  82. await runSql({ query: "DROP TABLE users" }); // waits until a human approves, throws if denied
  83. ```
  84. Get a free key, try calls and see approval requests at https://agentleisure.com/console.
  85. Python client: https://agentleisure.com/agentleisure_guard.py. MCP tools: https://agentleisure.com/mcp.
  86. MIT licensed.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.