ranger-rag-mcp

ranger-rag-mcp

MCP server that integrates Apache Ranger authorization with RAG, enforcing Ranger policies to control access to knowledge bases before forwarding queries to RAG Studio.

Category
访问服务器

README

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

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选