Skip to main content

Overview

MCP Server with LangGraph uses OpenFGA for fine-grained, relationship-based authorization (Google Zanzibar model). This enables you to define complex permissions like “who can access what” with precision.
OpenFGA provides the same authorization model used by Google, Airbnb, and GitHub for billions of authorization decisions per day.

Key Concepts

Users

Entities that perform actions (users, service accounts)

Objects

Resources being accessed (tools, documents, organizations)

Relations

Relationships between users and objects (owner, viewer, executor)

Authorization Model

The default model supports:

Quick Start

1

Deploy OpenFGA

2

Initialize Authorization Model

This creates:
  • OpenFGA store
  • Authorization model with types and relations
  • Default permissions for development users
Save the output:
3

Configure Environment

4

Test Authorization

Authorization Model

Default Model Structure

Relationship Examples

Grant user access to specific tools:

Common Patterns

Multi-Tenancy

Isolate resources by organization:

Hierarchical Permissions

Admins inherit all member permissions:

Document Access Control

Fine-grained document permissions:

Keycloak Integration 🆕

NEW in v2.1.0: Automatic role synchronization from Keycloak to OpenFGA.

Automatic Sync

When users authenticate via Keycloak, their roles and groups are synced to OpenFGA:

Role Mapping

Configure role mapping in config/role_mappings.yaml:
See the Keycloak SSO Guide for details.

API Operations

Check Permission

Grant Permission

Revoke Permission

List User Permissions

Monitoring & Debugging

Enable Authorization Logging

View Authorization Decisions

Check application logs for authorization events:

OpenFGA Metrics

Monitor authorization performance:

Production Best Practices

Never use in-memory store in production!
Deploy PostgreSQL with:
  • Replication for high availability
  • Regular backups
  • SSL/TLS encryption
Use different stores for dev/staging/production:
Prevents accidental permission changes across environments.
Track all authorization changes:
Monitor for:
  • Unexpected permission grants
  • Failed authorization attempts
  • Permission revocations
Configure failure behavior:
In production, always fail-closed to prevent unauthorized access.
Reduce latency with caching:
Balance security (fresh decisions) vs performance (cached).
Periodically review permissions:
Run monthly or after major changes.

Troubleshooting

Check:
  1. Store ID and Model ID are correct
  2. Tuples exist: python examples/openfga_usage.py
  3. User ID format matches (e.g., user:alice not alice)
  4. Relation exists in model
  5. Object type matches model
Solutions:
  • Enable caching
  • Use PostgreSQL (not in-memory)
  • Simplify authorization model
  • Add database indexes
  • Monitor query patterns
Re-initialize:

Next Steps

Permission Model

Customize the authorization model

Relationship Tuples

Manage permissions programmatically

OpenFGA Setup

Advanced OpenFGA configuration

Keycloak Integration

Sync Keycloak roles to OpenFGA

Production Ready: OpenFGA provides Google-grade authorization for your MCP server!