createVetoGuard. Denied tool calls never reach your handler — Veto intercepts them and returns an MCP-compatible error response.
Prerequisites
- A Veto account and API key from app.veto.tools
- An existing MCP server, or follow the steps below to create one
Create VetoClient and the guard wrapper
Initialize the client with your API key, then create a
protect function using createVetoGuard. Every tool handler you wrap with protect will be authorized against Veto before it runs.onDenied is optional but useful for logging and metrics. The agentId tells Veto which agent’s policies to evaluate.Register an agent in Veto
If you haven’t created an agent yet, register one. You only need to do this once — store the returned
id as VETO_AGENT_ID in your environment.Create a policy for this server
Create a policy that defines exactly which tools your MCP server is allowed to use. This example allows
file.read and file.write but explicitly denies file.delete.Veto is default deny: any tool not explicitly listed in an allowlist is blocked, even without a denylist rule. The denylist here makes the intent explicit and produces a clearer denial reason in the audit log.
Wrap tool handlers with protect()
Use When
protect(vetoAction, handler) when registering each tool. The first argument is the Veto action name (what Veto evaluates against your policies). The second is your existing tool handler.file_delete is called, Veto returns a denial before fs.unlink is ever reached.Understand fail-closed behavior
By default, if Veto is unreachable (network error, timeout, or 5xx response), You can switch to fail-open for development, but this is not recommended in production because it removes the authorization layer entirely when Veto is down:
createVetoGuard blocks the tool call. Your handler does not run.Complete example
Here is the full server in a single file:Using vetoMiddleware instead
If you prefer to call the authorization check manually inside your handler (for example, to add custom pre-authorization logic), usevetoMiddleware. It throws a VetoError if the action is denied.
What’s next
- Review all authorization decisions in the audit log
- See how policies are evaluated in Core concepts: authorization