Skip to main content
A hook makes the proxy ask a server you own before it uses a service’s credential. The proxy sends your server a signed description of what the agent is about to do, and your server answers allow or deny within 3 seconds. The proxy continues only if your server answers allow. You save a hook in your Agent Vault project with a name, a URL, and a signing secret, then pick it on each service it should check. A service can have one hook, and one hook can check many services. The proxy asks a service’s hook about the service’s requests in every session that uses the service. Use a hook when a service’s methods and paths or allowed tools can’t express the rule you want to apply. For example: to refuse refunds above a set amount, to allow writes to some repositories only, or to have a person approve an action first.
Your server gets the agent’s request, but never the service’s credential.

Prerequisites

  • The Admin role in your Agent Vault project, to save hooks and pick them on services
  • A server that accepts POST requests at an https:// or http:// URL, and that every proxy in the project can reach

How it works

The proxy asks the service’s hook at a different point for each service type:
  • HTTP APIs and MCP servers: Before it sends each request that the hook checks
  • Databases and SSH servers: Once for each connection the agent opens
The proxy checks its own rules first. If the request breaks the proxy’s traffic policy, the service’s methods and paths, or the service’s allowed tools, the proxy refuses the request without asking the hook. If your server denies the request or doesn’t give a usable answer, the proxy refuses it, and the agent gets a message it can act on.

Save a hook

You can save a hook in Infisical or through the API. Each proxy applies a change to a hook at its next check-in, within one poll interval (60 seconds by default).
1
In your Agent Vault project, go to Hooks and select Create Hook.
2
Enter a Name, such as refund-approval, and an optional Description.
3
In URL, enter your server’s URL, such as https://hooks.example.com/agent-vault. The URL can’t include a username, a password, a query string, or a fragment.
4
In Secret, enter the secret your server checks signatures with (see Pick a signing secret).
5
Select Create Hook.
A saved hook checks nothing until you attach it to a service.

Pick a signing secret

The proxy signs every request to your server with the hook’s signing secret, so your server can check that the request came from your proxy. The secret must be 32 to 512 characters long. It can use letters, numbers, and symbols, but no spaces. To generate a secret:
If one server handles several hooks with different secrets, give each hook its own URL path, such as /agent-vault/refunds and /agent-vault/deploys, so your server can tell which secret to check the signature with. The body names the hook too, but your server can’t trust the body until it has checked the signature.

Change the signing secret

When you replace the secret, each proxy keeps signing with the old secret until its next check-in. To keep your server from rejecting requests in the meantime:
1
On your server, accept a signature made with either the old or the new secret.
2
Replace the secret on the hook.
3
After every proxy in the project has checked in (within one poll interval, at most 300 seconds), remove the old secret from your server.

Edit or delete a hook

The Used By column on the Hooks page lists the services each hook checks. To edit a hook, go to Hooks, open the hook’s actions menu, and select Edit. Through the API, call the Update hook endpoint with only the fields you want to change. If you leave out secret, the hook keeps its saved secret. To delete a hook, open its actions menu and select Delete, or call the Delete hook endpoint. From the proxy’s next check-in, the proxy stops asking about requests to the services that used the hook, and those services keep working without a hook.

Attach a hook to a service

You pick a service’s hook on the service itself. Each proxy applies the change at its next check-in.
1
Go to Services, then select Add Service, or open a service’s actions menu and select Edit.
2
On the Hook step, pick a saved hook in Hook. To create a hook here, select Create New Hook.
3
Optionally, narrow the requests the hook checks for this service: Methods and Paths for an HTTP API, or Tools for an MCP server.
4
Check the hook on the Review step, then select Add Service, or Save if you’re editing the service.

Narrow the requests the hook checks

Without narrowing, the proxy asks the hook about every request to the service. To ask about only some of them, narrow the hook on the service. The narrowing depends on the service’s type:
  • HTTP APIs: methods, a list of methods such as POST, and paths, a list of path prefixes that match the same way as a service’s paths (if you set both, a request has to match both)
  • MCP servers: tools, a list of tool names (the proxy then asks only about calls to those tools, and not about calls such as initialize or tools/list)
  • Databases and SSH servers: No narrowing, so the proxy asks the hook about every connection

Use a hook with an inline service

An inline service can use a saved hook too. Name the hook in the inline service’s hook field, with the same narrowing as a service in the project:
If no hook in the project has that name, creating the session fails.

Build the hook server

For each check, your server receives one POST request, verifies the request’s signature, and answers allow or deny in JSON. The proxy waits at most 3 seconds for the answer.

Verify the signature

The proxy signs requests the way the Standard Webhooks specification describes, so you can verify them with any Standard Webhooks library. Load the library in raw-key mode. In the default mode, the library rejects every signature from the proxy. Verify the raw request body, before any framework parses it. The libraries also refuse a request if its webhook-timestamp is more than five minutes off your server’s clock.

Request format

Each request has these headers:
The body describes the hook, the session, the service, and the request or connection the agent is about to make:
Here’s a reference for each of the body’s fields:

Answer the request

Answer with a 2xx status and a JSON body, for both decisions:
string
required
allow or deny, in lowercase.
string
The text the agent gets, up to 2 KB, or 1 KB for databases and SSH servers.
string
Text for the session logs, up to 512 bytes.
The proxy cuts text that’s longer than these limits. In message, tell the agent what to do next, such as whether to try again. The proxy can send the same check twice if a connection to your server drops. Both copies have the same webhook-id, so answer both with the same decision. If your server records or counts checks, count each webhook-id once.

Unusable answers

The proxy refuses the request if any of the following happens:
  • No answer within 3 seconds
  • A connection or TLS error
  • A status other than 2xx
  • A redirect
  • A body larger than 64 KB
  • A body that isn’t valid JSON
  • A missing or unknown decision

Considerations

Your server sees the agent’s request as the agent sent it, before the proxy changes anything. Keep these points in mind when you write a rule:
  • No credentials: The request doesn’t include the service’s credential or its custom headers
  • Substitutions: If the agent sends a substitution placeholder, your server sees the placeholder, not the real value
  • Method overrides: Some APIs accept a header such as X-HTTP-Method-Override that turns a POST into a DELETE, so check those headers as well as method
  • Large bodies: The proxy sends at most the first 1 MB of the body, and sets bodyTruncated to true if it cut the body short
  • Compressed bodies: A body sent with a Content-Encoding header, such as gzip, arrives still compressed, as base64
  • Repeated keys: A header, a query parameter, or a JSON key can appear more than once, and the API might read a different copy than your parser does
If your rule depends on a part of the request that your server can’t read in full, such as a truncated body or a value that appears more than once, deny the request.

Ask a person for approval

Your server has 3 seconds to answer, which isn’t enough time for a person to approve a request. To have a person approve an action, deny the request first, then allow it when the agent tries again:
1
When the request arrives, record a pending approval for the session’s id and the action, and send the approval request to a person, such as in Slack. To find who to ask, use session.metadata or session.onBehalfOf.
2
Deny the request with a message that tells the agent to try again later, such as Approval requested from the on-call engineer. Try again in 5 minutes.
3
When the agent sends the same request again, check the approval. If the person approved it, answer allow and mark the approval as used, so it covers only that one request. If the approval is still pending, deny the request again with a message that tells the agent to wait.
To match the retried request to the approval, compare the request’s content, such as the method, path, and body, or the tool’s name and arguments. The retried request has a new webhook-id, and for MCP servers, a new JSON-RPC id.

Refused requests

When the proxy refuses a request, the agent gets one of these messages:
  • If your server denies the request: Your message, or “Your organization’s hook refused this request.” if you sent none (for databases and SSH servers, “Your organization’s hook refused this connection.”)
  • If your server doesn’t give a usable answer: A message that says the hook didn’t give a usable answer
The proxy delivers the message differently for each service type:
  • HTTP APIs: A 403 response with the hook_denied error code if your server denies the request, or a 503 response with the hook_failed error code and a Retry-After: 5 header if it doesn’t give a usable answer
  • Tool calls to MCP servers: A tool result with isError set to true, which the agent reads as the tool’s answer
  • Other MCP calls: A JSON-RPC error with the message
  • Databases and SSH servers: infisical agent-vault connect prints the service’s name and the message, as in analytics: <message>, and the proxy closes the agent’s connection without opening one to the server
For an HTTP denial, the response looks like the proxy’s other refusals:

Session log entries

Each refusal adds a row to the session logs. For a denial, the row ends with your reason. For databases and SSH servers, the row shows your message instead if you sent no reason.
The session logs of a session, with a PUT request to merge a pull request shown as Blocked, and hovering over Blocked shows: The hook refused this request: merge to main needs approval (rule protect-main)
The session logs of a session, with a connection to the orders-db PostgreSQL service shown as Blocked and expanded to read: The hook refused this connection: orders-db access outside 09:00-18:00 UTC
Don’t put anything in reason that the session’s owner or the project’s admins shouldn’t see. They can read the session logs, and the proxy also writes reason to its own log.

Limitations

  • Session labels and metadata aren’t a safe input: The session’s owner and project admins can change the label and metadata at any time, so never allow a request because of session.label or session.metadata
  • MySQL can switch databases: connection.database is the database the connection opens with, but a MySQL client can switch to any other database the service’s account can reach with USE, so limit the account’s grants on the server
  • One MCP tool call can reach the hook more than once: If an MCP server asks the agent for more input during a tool call, the agent sends the tool call again with a new JSON-RPC ID, and the proxy asks the hook again
  • http:// isn’t encrypted: Over an http:// URL, the request (with the agent’s headers and body) and your server’s answer cross the network unencrypted, so use http:// only on a network you trust
  • Private certificate authorities: If your server’s https:// certificate comes from a private certificate authority, every machine that runs a proxy has to trust that authority (on Linux, set SSL_CERT_FILE or SSL_CERT_DIR in the proxy’s environment to the authority’s certificate)

Troubleshooting

Check that:
  • The service has the hook (the Used By column on the Hooks page lists the hook’s services)
  • The hook’s methods, paths, or tools on the service match the request
  • The proxy has checked in since you last changed the hook or the service (within one poll interval)
The proxy couldn’t get a usable answer from your server. Check that:
  • Every machine that runs a proxy in the project can reach the hook URL
  • Your server answers within 3 seconds, with a 2xx status and a JSON body whose decision is allow or deny
  • Your server doesn’t redirect the request, for example from http:// to https://
The proxy’s own log shows the cause of each failure, such as a timeout or an unexpected status.
Check that:
  • Your server loads the library in raw-key mode, as in Verify the signature
  • The secret on your server matches the hook’s signing secret exactly (if you recently changed it, proxies switch on their next check-in)
  • Your server verifies the raw body, before a framework parses or reformats it
  • The clocks on the proxy’s machine and on your server are both correct, since the library refuses a timestamp more than five minutes off
If the MCP server’s hook has no tools, the proxy asks the hook about every request to the MCP server, including initialize, tools/list, and notifications. Allow those requests on your server, or narrow the hook to the tools you want to check.