===============
LIBRARY RULES
===============
From library maintainers:
- Maven coordinate: com.housedevinci:agent-guard-spring-boot-starter, current version 0.1.2.
- Upgrading from 0.1.x: follow docs/upgrading-0.1.2.md in order; step 3 re-applies the schema once as the table owner.
- The audit-trail trigger check runs at startup only; a trigger switched off later is not seen until the next start.
- Run the application as a separate database role from the table owner; the owner can still switch the triggers off.
### Run sample with Docker Compose and Maven
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Starts PostgreSQL on port 5432 and runs the MCP server on http://localhost:8080/mcp. Requires Docker and Maven wrapper.
```bash
cd agent-guard-sample
docker compose up -d # PostgreSQL on :5432
../mvnw spring-boot:run # MCP server on http://localhost:8080/mcp
```
--------------------------------
### GET /audit
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Retrieves the audit trail of all decisions and actions.
```APIDOC
## GET /audit
### Description
Retrieves the audit trail of all decisions and actions.
### Method
GET
### Endpoint
/audit
### Response
#### Success Response (200)
- The audit log entries.
#### Response Example
```json
[
{
"id": 1,
"action": "approve"
}
]
```
```
--------------------------------
### Detect affected triggers
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/upgrading-0.1.2.md
Query to list all non-internal triggers with names starting with 'agentguard%', showing schema, trigger name, relation, and enabled status. Use this to determine if your installation is affected by the 0.1.2 upgrade.
```sql
SELECT n.nspname, t.tgname, t.tgrelid::regclass AS on_relation, t.tgenabled
FROM pg_catalog.pg_trigger t
JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE NOT t.tgisinternal
AND t.tgname LIKE 'agentguard%'
ORDER BY 1, 2;
```
--------------------------------
### GET /decisions/{id}/arguments
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Retrieves the arguments for a specific decision. The response is complete and redacted.
```APIDOC
## GET /decisions/{id}/arguments
### Description
Retrieves the arguments for a specific decision.
### Method
GET
### Endpoint
/decisions/{id}/arguments
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the decision.
### Response
#### Success Response (200)
- The arguments associated with the decision.
#### Response Example
```json
{
"arguments": []
}
```
```
--------------------------------
### GET /decisions/{id}
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Retrieves a specific decision by its ID. The response is complete and redacted as appropriate.
```APIDOC
## GET /decisions/{id}
### Description
Retrieves a specific decision by its ID.
### Method
GET
### Endpoint
/decisions/{id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the decision.
### Response
#### Success Response (200)
- The decision details.
#### Response Example
```json
{
"id": "uuid",
"status": "pending"
}
```
```
--------------------------------
### GET /decisions
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Retrieves pending decisions that require approval. This endpoint is used to list all decisions awaiting action.
```APIDOC
## GET /decisions
### Description
Retrieves pending decisions that require approval.
### Method
GET
### Endpoint
/decisions
### Response
#### Success Response (200)
- List of pending decisions.
#### Response Example
```json
[
{
"id": "uuid",
"status": "pending"
}
]
```
```
--------------------------------
### Java tool annotations with @ToolPolicy
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Shows how to annotate MCP tools with @ToolPolicy. READ roles are allowed and audited; WRITE side effects are parked until human approval.
```java
@Component
public class OrderTools {
@McpTool(name = "get_order", description = "Status of an order")
@ToolPolicy(roles = "AGENT") // READ: allowed, audited
public String getOrder(@McpToolParam(description = "order id") String orderId) { ... }
@McpTool(name = "refund_order", description = "Refund an order")
@ToolPolicy(roles = "AGENT", sideEffect = SideEffect.WRITE) // WRITE: parked until a human approves
public String refundOrder(@McpToolParam(description = "order id") String orderId) { ... }
}
```
--------------------------------
### Agent Guard YAML configuration
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Configures Agent Guard with JDBC store, HMAC audit secret, endpoints, and budgets. The hmac-secret is required by default; startup fails if missing. For local trial only, set unkeyed: true instead.
```yaml
agentguard:
enabled: true
store: JDBC # PostgreSQL via your DataSource; MEMORY for a quick try
audit:
hmac-secret: ${AGENTGUARD_AUDIT_SECRET} # required; generate with `openssl rand -base64 32`
# — or, local trial only, `unkeyed: true` instead
endpoints:
enabled: true # /agentguard/decisions, /agentguard/audit — protect them with Spring Security
budgets:
limits:
- { scope: PRINCIPAL, kind: TOOL_CALLS, window: 1m, limit: 3 }
```
--------------------------------
### PostgreSQL permission denied error on budget purge
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/SECURITY-REVIEW-docs-runtime-role-grants.md
Failure output when the documented runtime role lacks DELETE on agentguard_budget. The 1000th budget-consuming guarded call fails fail-closed before the counter is incremented.
```text
ERROR: permission denied for table agentguard_budget
at JdbcBudgetStore.lambda$purgeExpired$1(JdbcBudgetStore.java:66)
```
--------------------------------
### SQL: Grant runtime role permissions for Agent Guard tables
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Grants the runtime role SELECT, INSERT on agentguard_audit; USAGE on the sequence agentguard_audit_seq_seq; SELECT, INSERT, UPDATE on agentguard_decision and agentguard_audit_anchor; and SELECT, INSERT, UPDATE, DELETE on agentguard_budget. Without the USAGE grant, the first guarded call fails with 'permission denied for sequence agentguard_audit_seq_seq'. Without DELETE on agentguard_budget, the 1000th budget-consuming call fails with 'permission denied for table agentguard_budget'.
```sql
GRANT SELECT, INSERT ON agentguard_audit TO agentguard_runtime;
GRANT USAGE ON SEQUENCE agentguard_audit_seq_seq TO agentguard_runtime;
GRANT SELECT, INSERT, UPDATE ON agentguard_decision, agentguard_audit_anchor TO agentguard_runtime;
GRANT SELECT, INSERT, UPDATE, DELETE ON agentguard_budget TO agentguard_runtime;
```
--------------------------------
### Maven dependency for agent-guard-spring-boot-starter
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Add this dependency to your Maven pom.xml to use Agent Guard. Version 0.1.2 is specified.
```xml
com.housedevinci
agent-guard-spring-boot-starter
0.1.2
```
--------------------------------
### Approve a parked write call
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Terminal workflow for an approver: read the redacted arguments, then approve with the hash from step 2. The call runs once in the principal's identity; a second approval returns the stored result and runs nothing.
```bash
# 1. the agent calls refund_order and gets back {"status":"AWAITING_APPROVAL","decisionId":"...", ...}
# 2. a human reads the complete, redacted arguments
curl -u alice:alice http://localhost:8080/agentguard/decisions//arguments
# 3. and approves, attesting the hash they reviewed
curl -u alice:alice -X POST "http://localhost:8080/agentguard/decisions//approve?argsHash="
```
--------------------------------
### curl to read decision arguments
Source: https://github.com/1of1canopus/agent-guard/blob/main/README.md
Fetches the recorded arguments for a decision. Use after an agent call returns AWAITING_APPROVAL. Replace with the actual ID.
```bash
curl -u alice:alice http://localhost:8080/agentguard/decisions//arguments
```
--------------------------------
### Check trail and anchor
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/upgrading-0.1.2.md
Queries to check the audit trail row count and the anchor's head hash, row count, and keyed status. Use these to record the state before repair.
```sql
SELECT pg_catalog.count(*) AS rows_in_trail FROM .agentguard_audit;
```
```sql
SELECT head_hash, row_count, keyed FROM .agentguard_audit_anchor WHERE id = 1;
```
--------------------------------
### SQL: Verify guard triggers on fresh audit trail
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Query to check that a fresh audit trail pair carries its five guard triggers, all ENABLE ALWAYS (A). Run after archiving and re-running the schema step. Expect five rows whose nspname is the application schema; archived copies show as five more rows under their own schema.
```sql
SELECT n.nspname, t.tgname, t.tgenabled
FROM pg_catalog.pg_trigger t
JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE NOT t.tgisinternal AND t.tgname LIKE 'agentguard%'
ORDER BY 1, 2;
```
--------------------------------
### POST /decisions/{id}/approve
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Approves a pending decision. The `argsHash` query parameter is required and must match the stored hash; otherwise a 409 conflict is returned.
```APIDOC
## POST /decisions/{id}/approve
### Description
Approves a pending decision. The `argsHash` query parameter is required and must match the stored hash; otherwise a 409 conflict is returned.
### Method
POST
### Endpoint
/decisions/{id}/approve
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the decision.
#### Query Parameters
- **argsHash** (string) - Required - The hash of the arguments to verify before approval.
### Response
#### Success Response (200)
- Approval confirmation.
#### Error Response (409)
- Returned when the argsHash does not match.
#### Response Example
```json
{
"status": "approved"
}
```
```
--------------------------------
### Grant runtime role sequence usage and table DML privileges
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/SECURITY-REVIEW-docs-runtime-role-grants.md
Grants the runtime role read and write access to audit, decision, budget, and anchor tables, plus USAGE on the audit sequence. This is the new grant block added by the branch; it is the only privilege set applied to agentguard_runtime in the verification. GRANT ALL or GRANT USAGE, UPDATE on the sequence would allow setval and seq reuse; USAGE only is required.
```sql
GRANT SELECT, INSERT ON agentguard_audit TO agentguard_runtime;
GRANT USAGE ON SEQUENCE agentguard_audit_seq_seq TO agentguard_runtime;
GRANT SELECT, INSERT, UPDATE ON agentguard_decision, agentguard_budget, agentguard_audit_anchor TO agentguard_runtime;
```
--------------------------------
### JdbcBudgetStore.incrementAndGet purge block
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/SECURITY-REVIEW-docs-runtime-role-grants.md
Inside JdbcBudgetStore.incrementAndGet, this inline block purges expired counters every PURGE_EVERY (1000) calls. It has no try/catch, so JdbcSupport.JdbcAccessException propagates out of budget enforcement.
```java
if (calls.incrementAndGet() % PURGE_EVERY == 0) {
purgeExpired(now); // DELETE FROM agentguard_budget WHERE expires_at < ?
}
```
--------------------------------
### POST /decisions/{id}/reject
Source: https://github.com/1of1canopus/agent-guard/blob/main/docs/index.md
Rejects a pending decision.
```APIDOC
## POST /decisions/{id}/reject
### Description
Rejects a pending decision.
### Method
POST
### Endpoint
/decisions/{id}/reject
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the decision.
### Response
#### Success Response (200)
- Rejection confirmation.
#### Response Example
```json
{
"status": "rejected"
}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.