Skip to main content
Glama
ranger-rag-mcp

ranger-rag-mcp

by WarinChi

Ranger RAG MCP Server

MCP server that integrates Apache Ranger authorization with RAG (Retrieval Augmented Generation). When a user queries a knowledge base, the server first checks Ranger policies to verify the user has permission — if denied, the query is rejected before reaching the RAG system.

Architecture

User (AI Agent) ──→ MCP Server ──→ Ranger Policy Check ──→ RAG Studio
                                        │
                                  DENY → "Access Denied"
                                  ALLOW → Forward query, return results

Related MCP server: ToolBridge

Features

  • Per-knowledge-base authorization — Ranger policies control which users can access which knowledge bases

  • Transparent enforcement — denied queries never reach the RAG system

  • Policy-based access control — uses existing Ranger infrastructure (policies, users, groups)

  • Automatic retries — exponential backoff on transient errors

  • Fallback evaluation — if Ranger's evaluateOnce API isn't available, evaluates policies locally

MCP Tools

Tool

Description

query_knowledge_base(user, knowledge_base, query)

Query a KB with Ranger auth check

list_knowledge_bases(user)

List KBs the user can access

check_access(user, knowledge_base, access_type)

Pre-flight permission check

list_policies()

Show all RAG Ranger policies (admin)

Setup

1. Create a Ranger Service for RAG

In Ranger Admin, create a new service (or use an existing custom service type) with:

  • Service Name: rag

  • Resource: knowledge_base (string, supports wildcards)

  • Access Types: read, write

2. Create Ranger Policies

Example policies:

Policy Name

Resource

Users

Access

Finance KB - Analysts

Finance KB

alice, bob

read

HR KB - HR Team

HR Policies

charlie

read

All KBs - Admin

*

admin

read, write

3. Install and Configure

git clone <repo-url>
cd ranger-rag-mcp
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Copy .env.example to .env and fill in your values:

cp .env.example .env
# Edit .env with your Ranger and RAG Studio credentials

4. Configure MCP Client

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "ranger-rag-mcp-server": {
      "command": "/FULL/PATH/TO/ranger-rag-mcp/.venv/bin/python",
      "args": ["-m", "ranger_rag_mcp_server.server"],
      "env": {
        "RANGER_GATEWAY_URL": "https://<gateway>/<topology>/cdp-proxy-api/ranger/",
        "RANGER_USER": "<workload_username>",
        "RANGER_PASS": "<workload_password>",
        "RANGER_SERVICE_NAME": "rag",
        "RAG_STUDIO_URL": "https://<rag-studio-url>",
        "RAG_STUDIO_API_KEY": "<api_key>"
      }
    }
  }
}

Agent Studio / Kiro:

{
  "mcpServers": {
    "ranger-rag-mcp-server": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/<your-org>/ranger-rag-mcp@main",
        "run-server"
      ],
      "env": {
        "RANGER_GATEWAY_URL": "https://<gateway>/<topology>/cdp-proxy-api/ranger/",
        "RANGER_USER": "<workload_username>",
        "RANGER_PASS": "<workload_password>",
        "RANGER_SERVICE_NAME": "rag",
        "RAG_STUDIO_URL": "https://<rag-studio-url>",
        "RAG_STUDIO_API_KEY": "<api_key>"
      }
    }
  }
}

Configuration

Ranger

Variable

Required

Description

RANGER_GATEWAY_URL

Yes

Ranger Admin REST API URL via Knox

RANGER_USER

Yes

Workload username for Ranger API auth

RANGER_PASS

Yes

Workload password for Ranger API auth

RANGER_SERVICE_NAME

No

Ranger service name (default: rag)

RAG Studio

Variable

Required

Description

RAG_STUDIO_URL

Yes

RAG Studio base URL

RAG_STUDIO_API_KEY

Yes

RAG Studio API key

RAG_STUDIO_PROJECT_ID

No

Project ID (default: 1)

RAG_RESPONSE_CHUNKS

No

Number of chunks to retrieve (default: 5)

RAG_INFERENCE_MODEL

No

LLM model for response generation

TLS/HTTP

Variable

Default

Description

VERIFY_SSL

true

Set false to disable SSL verification

CA_BUNDLE

—

Path to CA certificate bundle

HTTP_TIMEOUT_SECONDS

30

Request timeout in seconds

Example Usage

Once configured, ask the AI:

# User with access → gets results
"As user 'alice', query the 'Finance KB' knowledge base: What was Q3 revenue?"

# User without access → gets denied
"As user 'bob', query the 'HR Policies' knowledge base: What is the PTO policy?"

# Check what a user can access
"List all knowledge bases that user 'alice' can access"

# Admin: see all policies
"Show me all the RAG access policies"

How It Works

  1. User calls query_knowledge_base(user="alice", knowledge_base="Finance KB", query="...")

  2. MCP server calls Ranger: POST /service/plugins/policies/evaluateOnce — "Can alice read Finance KB?"

  3. Ranger evaluates policies:

    • Checks all enabled policies for the rag service

    • Looks for policies where resource knowledge_base matches "Finance KB"

    • Checks if user "alice" or any of her groups appear in policyItems with read access

  4. If ALLOWED: Forward query to RAG Studio, return answer

  5. If DENIED: Return ACCESS_DENIED with reason — RAG Studio is never contacted

Ranger Policy Structure

The server expects Ranger policies with this structure:

{
  "service": "rag",
  "name": "Finance KB Access",
  "isEnabled": true,
  "resources": {
    "knowledge_base": {
      "values": ["Finance KB"],
      "isRecursive": false
    }
  },
  "policyItems": [
    {
      "users": ["alice", "bob"],
      "groups": ["finance-team"],
      "accesses": [
        {"type": "read", "isAllowed": true}
      ]
    }
  ]
}

License

Apache License 2.0

Available Tools

4 tools
check_accessA

Check if a user has access to a specific knowledge base without querying it.

Useful for pre-flight permission checks before attempting a query.

Args: user: Username to check permissions for. knowledge_base: Name of the knowledge base. access_type: Type of access to check ('read' or 'write'). Default: 'read'.

Returns: Access decision with policy details.

Inputs: user (required), knowledge_base (required), access_type. Returns: result

list_knowledge_basesA

List all knowledge bases the user has access to.

Checks Ranger authorization for each knowledge base and returns only those the user is permitted to query.

Args: user: Username to check permissions for.

Returns: List of accessible knowledge bases with their details.

Inputs: user (required). Returns: result

list_policiesA

List all Ranger policies for the RAG service.

Shows which users/groups have access to which knowledge bases. Useful for administrators to understand the current access control setup.

Returns: List of policies with their resource definitions and access rules.

Inputs: no named parameters. Returns: result

query_knowledge_baseA

Query a RAG knowledge base with Ranger authorization check.

First checks Apache Ranger to verify the user has 'read' access to the specified knowledge base. If allowed, forwards the query to RAG Studio and returns the answer. If denied, returns an access denied message.

Args: user: Username to check permissions for (e.g., 'alice', 'bob'). knowledge_base: Name of the knowledge base to query (e.g., 'Finance KB', 'HR Policies'). query: The question to ask the knowledge base.

Returns: If authorized: The RAG response with answer and sources. If denied: An access denied message with the reason.

Inputs: user (required), query (required), knowledge_base (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.5/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: querying a KB, listing accessible KBs, checking access pre-flight, and listing all policies. There is no meaningful overlap that would cause confusion, as even the access check in query is incidental to its primary function.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun snake_case pattern (query_knowledge_base, list_knowledge_bases, check_access, list_policies). The two 'list' verbs are used consistently with different objects, and there are no mixed conventions.

    Tool Count5/5

    Four tools is a well-scoped count for a RAG query service with authorization checks. Each tool covers a necessary function without redundancy, fitting the typical 3-15 range comfortably.

    Completeness4/5

    The core workflows of querying, listing accessible bases, pre-flight access checks, and viewing policies are covered. Minor gaps exist such as no policy management or write operations, but these are likely out of scope for a read-oriented query server.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      A governed MCP server for integrating AI agents with customer data, featuring role-based access control, field redaction, and human-in-the-loop approval for secure support operations.
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that enforces runtime governance on AI agent actions — file access, command execution, delegation chains, and permission escalation.
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      MCP server for a modular RAG system that enables natural language question answering over enterprise documents with intent-aware routing, adaptive retrieval, and citation-backed responses.
      -