mcp_authorization v0.7.1

mcp_authorization

Read the cookbook Reference

read it

Rails engine for serving MCP tools with per-request schema discrimination compiled from RBS type annotations.

Add it to your Gemfile and your Rails app speaks MCP. Write @rbs type comments in plain Ruby service classes, tag fields and variants with @requires(:flag), and the gem compiles tailored JSON Schema per request. The type definitions are the authorization policy.

Looking for task-oriented "how do I X?" recipes rather than reference? See the Cookbook.

Cookbook

Task-oriented recipes: I want to do X, what do I write?

Reference

Every option, DSL method, annotation tag, and lifecycle detail.

  • Three layers of authorization

    The gem gives you three independent controls over what each user sees:

  • Install

    Routes install automatically at /mcp. No mount needed.

  • Configuration

    Two configuration methods (not attributes) turn a domain into grouped facades โ€” see Tool grouping:

  • The contract

    The gem has two opinions about your app:

  • Quick example

    Define reusable types as .rbs files. These are plain RBS -- no comment markers.

  • Handler interface

    A handler includes McpAuthorization::DSL and implements two methods:

  • @requires rules

    On input params -- the param is excluded from the input schema when can? returns false. Tag them in the #: annotation above def call:

  • Shared types

    Define reusable types as .rbs files in sig/shared/ (configurable via shared_type_paths):

  • Tool DSL

    authorization :perm is just a convenience for gate :requires, :perm โ€” internally there is one gate pipeline, not two. Multiple gate declarations AND together...

  • Contract validation

    If a handler is missing required methods or schema definitions, the gem raises an ArgumentError on first request with a full diagnostic:

  • Multi-domain routing

    Tag a tool with multiple domains to make it available in each:

  • Tool grouping (facades)

    As a domain grows into the hundreds of tools, a flat tools/list spends the

  • RBS type syntax

    The @rbs type comments compile to JSON Schema:

  • Performance

    Source files are parsed once at boot and cached in memory. Only @requires filtering runs per request (hash lookups and can? calls). In development, caches ar...

  • Caching tools/list

    tools/list must materialize a per-user schema for every tool in a domain. That cost can be cached. Default is no caching, so nothing changes unless you opt in:

  • Development

    In development mode, the gem wires into the Rails reloader. Edit an @rbs type annotation, save, and the next MCP request returns the updated schema. No serve...

  • How it works

    Different users hitting the same endpoint can see different tools, different descriptions, different input fields, and different output shapes.

  • Stateless transport and schema lifetime

    The gem uses the MCP SDK's Streamable HTTP transport in stateless mode. Each HTTP request creates a fresh MCP::Server, materialized with tools filtered and s...

  • Requirements
  • License

    MIT

Design docs

The reasoning behind larger features, as written before they shipped.

Releases

Every released version, what changed in it, and why.

Open Releases

Every page on this site is collected from the markdown in the repository by site/collect.rb at build time. The repo docs are the source of truth.