Skip to main content
Glama
WarinChi

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
userYes
access_typeNoread
knowledge_baseYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry full behavioral disclosure. It discloses that the tool does not query the knowledge base, which is a key behavioral trait. However, it does not state whether it modifies anything, requires special permissions, or how policy decisions are derived. It only says 'Returns: Access decision with policy details,' which is minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a compact docstring with a purpose sentence, a usage note, and structured Args/Returns sections. Each part adds necessary information and nothing is redundant. It is front-loaded with the core purpose before diving into details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple access check tool, the description covers what, when, parameters, and return value. It does not mention edge cases like unknown users, unconfigured policies, or differences between the check and actual query behavior. However, the output schema exists to formalize return structure, so the description is adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero description coverage, but the description includes an Args section explaining each parameter in plain language. It specifies that access_type accepts 'read' or 'write' and defaults to 'read', which is not discernible from the schema alone. This fully compensates for the schema gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Check if a user has access to a specific knowledge base without querying it,' using a specific verb and resource. The phrase 'without querying it' clearly distinguishes it from sibling query_knowledge_base. This is a strong, specific purpose statement.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states 'Useful for pre-flight permission checks before attempting a query,' which provides clear usage context. It doesn't name alternatives or exclusions, but the scenario is clearly defined. Sibling tools are listed but not explicitly compared.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
userYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the burden. It explicitly discloses that it checks Ranger authorization and returns only permitted KBs, which is a key behavioral trait. It does not detail failure modes or pagination, but for a read-only list operation this is adequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and well-structured, with a clear purpose statement, a brief authorization note, and Args/Returns sections. Every sentence adds value, and there is no unnecessary repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that the tool has one parameter, a clear purpose, and an output schema (per context signals), the description fully enables an agent to select and invoke it correctly. It does not need to elaborate further on return values or error handling.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero description coverage for the 'user' parameter. The description compensates by specifying 'user: Username to check permissions for,' clarifying its purpose and type. This is sufficient for a single simple parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'List all knowledge bases the user has access to,' which is a specific verb (list) plus resource (knowledge bases) with a scope (user access). This distinguishes it from siblings like query_knowledge_base and list_policies by focusing on the set of accessible KBs rather than querying content or listing policies.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for discovering KBs a user can query, and the mention of Ranger authorization gives clear context. However, it does not explicitly name alternative tools or state when not to use it, so it falls short of a full 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden for behavioral disclosure. It clearly describes the output (list of policies with resource definitions and access rules) but does not mention any access requirements, side effects, or limitations beyond the return value. It is a read-only operation by implication but not explicitly stated.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, with the main action stated in the first line. The 'Returns:' section adds useful detail without redundancy or unnecessary length. Every sentence contributes value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no parameters and an output schema exists, the description provides sufficient context for a simple list operation. It describes the return format and the intended audience, though it could have explicitly stated its relationship to sibling tools for more complete context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, and the description correctly adds no parameter-specific information. Per the rubric, a baseline score of 4 is appropriate for 0 parameters, as there is nothing to describe beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'List all Ranger policies for the RAG service' with a specific verb and resource. It further explains the purpose as showing access mappings, which distinguishes it from sibling tools like list_knowledge_bases and check_access.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description says 'Useful for administrators to understand the current access control setup,' which provides clear context for when to use the tool. However, it does not explicitly exclude alternatives or state when not to use it, so it lacks explicit comparisons to sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
userYes
queryYes
knowledge_baseYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description fully discloses behavior: it checks Ranger read access, conditionally forwards to RAG Studio, returns an access denied message on failure, and describes the return values for both paths. This is rich and transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with an intro, a flow explanation, and clearly labeled Args and Returns sections. Each sentence adds valuable information, and the length is appropriate for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description fully covers the tool's purpose, authorization flow, parameters, and return values. Given the absence of annotations and the complexity involving RAG and Ranger, this description is complete and self-sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description includes an Args section that explains each parameter with examples (user, knowledge_base, query), adding meaningful semantics beyond the bare input schema. It even outlines the return behavior based on authorization, which ties to parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Query') and resource ('RAG knowledge base'), and distinguishes itself from siblings by explicitly mentioning the Ranger authorization check. It clearly communicates the core action and scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly explains the tool's context: it performs an authorization check before querying, and describes authorization flow. It does not explicitly mention when to use this tool instead of siblings like check_access, but it provides sufficient context for an agent to decide.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 4 tool updatesv0.1.0
    • First observedcheck_access
    • First observedlist_knowledge_bases
    • First observedlist_policies
    • First observedquery_knowledge_base

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.

Maintenance

ActivityMaintained
ResponsivenessSyncing

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
    C
    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
    B
    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.
    -