Skip to main content
Multi-tenant applications need to ensure users can only access data for their authorized sites or tenants. This guide shows you how to build a site-scoped authorization plugin that validates access before tool execution.
Prerequisites:

What You’ll Build

A site authorization plugin that:
  • Validates users can only access their authorized sites
  • Supports admin-only tools within sites
  • Works with tools that have a siteId input parameter

Step 1: Define Types and Metadata Extension


Step 2: Create the Site Authorization Plugin


Step 3: Register the Plugin


Step 4: Mark Tools as Site-Scoped

Basic Site-Scoped Tool

Tools with a siteId input are automatically site-scoped:

Admin-Only Site Tool

Custom Site Field Name

Explicit Site Scoping

Force site validation even without a siteId field:

User Claims Structure

The plugin expects user claims in this format:

How It Works

1

Tool execution requested

Client calls a tool with input including siteId.
2

Will hook intercepts

Before execution, validateSiteAccess hook runs at priority 900.
3

Extract site ID

Plugin reads siteId from input (or custom field name).
4

Check user access

Plugin extracts user’s allowed sites from authInfo.user.sites or authInfo.user.tenants.
5

Validate access

If site isn’t in allowed list, throws error. If admin required, checks roles.
6

Execute or reject

Tool executes only if validation passes.

Combining with Role-Based Authorization

You can use both plugins together:
This gives you:
  1. Role-based filtering - Users only see tools for their roles
  2. Site-based validation - Users can only access their authorized sites

Testing Site Authorization


Best Practices

Make site context explicit in every site-scoped operation:
The demoAllowAllIfNoClaims option is convenient for development but should be disabled in production:
For security auditing, consider logging failed authorization attempts:
For high-traffic applications, cache site access checks:

Next Steps

Role-Based Authorization

Filter tools by user roles

Create a Plugin

Full plugin development guide

Customize Flow Stages

Learn more about hooks

Authentication

Configure authentication providers