Doris MCP Server
Doris MCP (Model Context Protocol) Server is a backend service built with Python and FastAPI. It implements the MCP, allowing clients to interact with it through defined "Tools". It's primarily designed to connect to Apache Doris databases, potentially leveraging Large Language Models (LLMs) for tasks like converting natural language queries to SQL (NL2SQL), executing queries, and performing metadata management and analysis.
🚀 What's New in v0.6.0
- 🔐 Enterprise Authentication System: Revolutionary token-bound database configuration with comprehensive Token, JWT, and OAuth authentication support, enabling secure multi-tenant access with granular control switches and enterprise-grade security defaults
- ⚡ Immediate Database Validation: Real-time database configuration validation at connection time, eliminating query-time blocking and providing instant feedback for invalid configurations - achieving 100% elimination of late-stage connection failures
- 🔄 Hot Reload Configuration Management: Zero-downtime configuration updates with intelligent hot reloading of tokens.json, automatic token revalidation, and comprehensive error handling with rollback mechanisms
- 🏗️ Advanced Connection Architecture: Session caching and connection pool optimization with 60% reduction in connection overhead, intelligent pool recreation, and automatic resource management
- 🌐 Multi-Worker Scalability: True horizontal scaling with stateless multi-worker architecture, efficient load distribution, and enterprise-grade concurrent processing capabilities
- 🔒 Enhanced Security Framework: Comprehensive access control and SQL security validation with immediate validation, role-based permissions, and enhanced injection detection patterns
- 🛠️ Unified Configuration System: Streamlined configuration management with proper command-line precedence, Docker compatibility improvements, and cross-platform deployment support
- 📊 Token Management Dashboard: Complete token lifecycle management with creation, revocation, statistics, and comprehensive audit trails for enterprise token governance
- 🌐 Web-Based Management Interface: Secure localhost-only token administration with intuitive dashboard, database binding configuration, real-time operations, and enterprise-grade access controls
🚀 Major Milestone: v0.6.0 establishes the platform as a production-ready enterprise authentication and database management system with zero-downtime operations (hot reload + immediate validation + multi-worker scaling), advanced security controls, and comprehensive token-bound database configuration - representing a fundamental advancement in enterprise data platform capabilities.
What's Also Included from v0.5.1
- 🔥 Critical at_eof Connection Fix: Complete elimination of connection pool errors with intelligent health monitoring and self-healing recovery
- 🔧 Enterprise Logging System: Level-based file separation with automatic cleanup and millisecond precision timestamps
- 📊 Advanced Data Analytics Suite: 7 enterprise-grade data governance tools including quality analysis, lineage tracking, and performance monitoring
- 🏃♂️ High-Performance ADBC Integration: Apache Arrow Flight SQL support with 3-10x performance improvements for large datasets
- ⚙️ Enhanced Configuration Management: Complete ADBC configuration system with intelligent parameter validation
Core Features
- MCP Protocol Implementation: Provides standard MCP interfaces, supporting tool calls, resource management, and prompt interactions.
- Streamable HTTP Communication: Unified HTTP endpoint supporting both request/response and streaming communication for optimal performance and reliability.
- Stdio Communication: Standard input/output mode for direct integration with MCP clients like Cursor.
- Enterprise-Grade Architecture: Modular design with comprehensive functionality:
- Tools Manager: Centralized tool registration and routing with unified interfaces (
doris_mcp_server/tools/tools_manager.py) - Enhanced Monitoring Tools Module: Advanced memory tracking, metrics collection, and flexible BE node discovery with modular, extensible design
- Query Information Tools: Enhanced SQL explain and profiling with configurable content truncation, file export for LLM attachments, and advanced query analytics
- Resources Manager: Resource management and metadata exposure (
doris_mcp_server/tools/resources_manager.py) - Prompts Manager: Intelligent prompt templates for data analysis (
doris_mcp_server/tools/prompts_manager.py)
- Tools Manager: Centralized tool registration and routing with unified interfaces (
- Advanced Database Features:
- Query Execution: High-performance SQL execution with advanced caching and optimization, enhanced connection stability and automatic retry mechanisms (
doris_mcp_server/utils/query_executor.py) - Security Management: Comprehensive SQL security validation with configurable blocked keywords, SQL injection protection, data masking, and unified security configuration management (
doris_mcp_server/utils/security.py) - Metadata Extraction: Comprehensive database metadata with catalog federation support (
doris_mcp_server/utils/schema_extractor.py) - Performance Analysis: Advanced column analysis, performance monitoring, and data analysis tools (
doris_mcp_server/utils/analysis_tools.py)
- Query Execution: High-performance SQL execution with advanced caching and optimization, enhanced connection stability and automatic retry mechanisms (
- Catalog Federation Support: Full support for multi-catalog environments (internal Doris tables and external data sources like Hive, MySQL, etc.)
- Enterprise Security: Comprehensive security framework with authentication, authorization, SQL injection protection, and data masking capabilities with environment variable configuration support
- Web-Based Token Management: Secure localhost-only interface for complete token lifecycle management with database binding, real-time statistics, and enterprise-grade access controls (
doris_mcp_server/auth/token_handlers.py) - Unified Configuration Framework: Centralized configuration management through
config.pywith comprehensive validation, standardized parameter naming, and smart default database handling with automatic fallback toinformation_schema
System Requirements
- Python: 3.12+
- Database: Apache Doris connection details (Host, Port, User, Password, Database)
🚀 Quick Start
Installation from PyPI
# Install the latest version
pip install doris-mcp-server
# Install specific version
pip install doris-mcp-server==0.6.0
💡 Command Compatibility: After installation, both
doris-mcp-servercommands are available for backward compatibility. You can use either command interchangeably.
Start Streamable HTTP Mode (Web Service)
The primary communication mode offering optimal performance and reliability:
# Full configuration with database connection
doris-mcp-server \
--transport http \
--host 0.0.0.0 \
--port 3000 \
--db-host 127.0.0.1 \
--db-port 9030 \
--db-user root \
--db-password your_password
Start Stdio Mode (for Cursor and other MCP clients)
Standard input/output mode for direct integration with MCP clients:
# For direct integration with MCP clients like Cursor
doris-mcp-server --transport stdio
🌐 Token Management Interface (New in v0.6.0)
Access the Web-Based Token Management Dashboard for enterprise-grade token administration:
Secure Access Requirements
- Localhost Access Only: Interface restricted to
127.0.0.1and::1for maximum security - Admin Authentication: Requires
TOKEN_MANAGEMENT_ADMIN_TOKENfor access - Configuration Prerequisites:
# Required environment variables ENABLE_HTTP_TOKEN_MANAGEMENT=true ENABLE_TOKEN_AUTH=true TOKEN_MANAGEMENT_ADMIN_TOKEN=your_secure_admin_token TOKEN_MANAGEMENT_ALLOWED_IPS=127.0.0.1,::1
Interface Access
# Access the token management interface
http://localhost:3000/token/management?admin_token=your_secure_admin_token
Available Operations
- 📊 Token Statistics: Real-time overview of active, expired, and total tokens
- ➕ Create Tokens:
- Basic information (ID, description, expiration)
- Database binding (host, port, user, password, database)
- Custom token values or auto-generated secure tokens
- 📋 Token Management:
- List all tokens with database binding status
- One-click token revocation
- Automated expired token cleanup
- 🔒 Enterprise Security:
- All operations require admin authentication
- Real-time IP validation
- Complete audit logging
- Automatic persistence to
tokens.json
🔐 Security Note: The interface is designed for localhost administration only. It cannot be accessed remotely, ensuring maximum security for token management operations.
Verify Installation
# Check installation
doris-mcp-server --help
# Test HTTP mode (in another terminal)
curl http://localhost:3000/health
Environment Variables (Optional)
Instead of command-line arguments, you can use environment variables:
# Basic Database Configuration
export DORIS_HOST="127.0.0.1"
export DORIS_PORT="9030"
export DORIS_USER="root"
export DORIS_PASSWORD="your_password"
# Token Management Interface (Security-Critical)
export ENABLE_HTTP_TOKEN_MANAGEMENT=true
export ENABLE_TOKEN_AUTH=true
export TOKEN_MANAGEMENT_ADMIN_TOKEN="your_secure_admin_token"
export TOKEN_MANAGEMENT_ALLOWED_IPS="127.0.0.1,::1"
# Then start with simplified command
doris-mcp-server --transport http --host 0.0.0.0 --port 3000
Command Line Arguments
The doris-mcp-server command supports the following arguments:
| Argument | Description | Default | Required |
|---|---|---|---|
--transport |
Transport mode: http or stdio |
http |
No |
--host |
HTTP server host (HTTP mode only) | 0.0.0.0 |
No |
--port |
HTTP server port (HTTP mode only) | 3000 |
No |
--db-host |
Doris database host | localhost |
No |
--db-port |
Doris database port | 9030 |
No |
--db-user |
Doris database username | root |
No |
--db-password |
Doris database password | - | Yes (unless in env) |
Development Setup
For developers who want to build from source:
1. Clone the Repository
# Replace with the actual repository URL if different
git clone https://github.com/apache/doris-mcp-server.git
cd doris-mcp-server
2. Install Dependencies
pip install -r requirements.txt
3. Configure Environment Variables
Copy the .env.example file to .env and modify the settings according to your environment:
cp .env.example .env
Key Environment Variables:
- Database Connection:
DORIS_HOST: Database hostname (default: localhost)DORIS_PORT: Database port (default: 9030)DORIS_USER: Database username (default: root)DORIS_PASSWORD: Database passwordDORIS_DATABASE: Default database name (default: information_schema)DORIS_MIN_CONNECTIONS: Minimum connection pool size (default: 5)DORIS_MAX_CONNECTIONS: Maximum connection pool size (default: 20)DORIS_BE_HOSTS: BE nodes for monitoring (comma-separated, optional - auto-discovery via SHOW BACKENDS if empty)DORIS_BE_WEBSERVER_PORT: BE webserver port for monitoring tools (default: 8040)FE_ARROW_FLIGHT_SQL_PORT: Frontend Arrow Flight SQL port for ADBC (New in v0.5.0)BE_ARROW_FLIGHT_SQL_PORT: Backend Arrow Flight SQL port for ADBC (New in v0.5.0)
- Authentication Configuration (Enhanced in v0.6.0):
ENABLE_TOKEN_AUTH: Enable token-based authentication (default: false)ENABLE_JWT_AUTH: Enable JWT authentication (default: false)ENABLE_OAUTH_AUTH: Enable OAuth authentication (default: false)ENABLE_DORIS_OAUTH_AUTH: Enable Doris-backed OAuth authentication (default: false)DORIS_OAUTH_BASE_URL: Public base URL used by Doris-backed OAuth discovery and token endpointsTOKEN_FILE_PATH: Path to tokens.json file for token management (default: tokens.json)TOKEN_HOT_RELOAD: Enable hot reloading of token configuration (default: true)DEFAULT_ADMIN_TOKEN: Default admin token (customizable via env)DEFAULT_ANALYST_TOKEN: Default analyst token (customizable via env)DEFAULT_READONLY_TOKEN: Default readonly token (customizable via env)
- Legacy Security Configuration:
AUTH_TYPE: Legacy authentication type (token/basic/oauth, deprecated - use individual switches)TOKEN_SECRET: Legacy token secret key (use token-based auth instead)ENABLE_SECURITY_CHECK: Enable/disable SQL security validation (default: true)BLOCKED_KEYWORDS: Comma-separated list of blocked SQL keywordsENABLE_MASKING: Enable data masking (default: true)MAX_RESULT_ROWS: Maximum result rows (default: 10000)
- ADBC Configuration (New in v0.5.0):
ADBC_DEFAULT_MAX_ROWS: Default maximum rows for ADBC queries (default: 100000)ADBC_DEFAULT_TIMEOUT: Default ADBC query timeout in seconds (default: 60)ADBC_DEFAULT_RETURN_FORMAT: Default return format - arrow/pandas/dict (default: arrow)ADBC_CONNECTION_TIMEOUT: ADBC connection timeout in seconds (default: 30)ADBC_ENABLED: Enable/disable ADBC tools (default: true)
- Performance Configuration:
ENABLE_QUERY_CACHE: Enable query caching (default: true)CACHE_TTL: Cache time-to-live in seconds (default: 300)MAX_CONCURRENT_QUERIES: Maximum concurrent queries (default: 50)MAX_RESPONSE_CONTENT_SIZE: Maximum response content size for LLM compatibility (default: 4096, New in v0.4.0)
- Enhanced Logging Configuration (Improved in v0.5.0):
LOG_LEVEL: Log level (DEBUG/INFO/WARNING/ERROR, default: INFO)LOG_FILE_PATH: Log file path (automatically organized by level)ENABLE_AUDIT: Enable audit logging (default: true)ENABLE_LOG_CLEANUP: Enable automatic log cleanup (default: true, Enhanced in v0.5.0)LOG_MAX_AGE_DAYS: Maximum age of log files in days (default: 30, Enhanced in v0.5.0)LOG_CLEANUP_INTERVAL_HOURS: Log cleanup check interval in hours (default: 24, Enhanced in v0.5.0)- New Features in v0.5.0:
- Level-based File Separation: Automatic separation into
debug.log,info.log,warning.log,error.log,critical.log - Timestamped Format: Enhanced formatting with millisecond precision and proper alignment
- Background Cleanup Scheduler: Automatic cleanup with configurable retention policies
- Audit Trail: Dedicated
audit.logwith separate retention management - Performance Optimized: Minimal overhead async logging with rotation support
- Level-based File Separation: Automatic separation into
Available MCP Tools
The following table lists the main tools currently available for invocation via an MCP client:
| Tool Name | Description | Parameters |
|---|---|---|
exec_query |
Execute SQL query and return results. | sql (string, Required), db_name (string, Optional), catalog_name (string, Optional), max_rows (integer, Optional), timeout (integer, Optional) |
get_table_schema |
Get detailed table structure information. | table_name (string, Required), db_name (string, Optional), catalog_name (string, Optional) |
get_db_table_list |
Get list of all table names in specified database. | db_name (string, Optional), catalog_name (string, Optional) |
get_db_list |
Get list of all database names. | catalog_name (string, Optional) |
get_table_comment |
Get table comment information. | table_name (string, Required), db_name (string, Optional), catalog_name (string, Optional) |
get_table_column_comments |
Get comment information for all columns in table. | table_name (string, Required), db_name (string, Optional), catalog_name (string, Optional) |
get_table_indexes |
Get index information for specified table. | table_name (string, Required), db_name (string, Optional), catalog_name (string, Optional) |
get_recent_audit_logs |
Get audit log records for recent period. | days (integer, Optional), limit (integer, Optional) |
get_catalog_list |
Get list of all catalog names. | random_string (string, Required) |
get_sql_explain |
Get SQL execution plan with configurable content truncation and file export for LLM analysis. | sql (string, Required), verbose (boolean, Optional), db_name (string, Optional), catalog_name (string, Optional) |
get_sql_profile |
Get SQL execution profile with content management and file export for LLM optimization workflows. | sql (string, Required), db_name (string, Optional), catalog_name (string, Optional), timeout (integer, Optional) |
get_table_data_size |
Get table data size information via FE HTTP API. | db_name (string, Optional), table_name (string, Optional), single_replica (boolean, Optional) |
get_monitoring_metrics_info |
Get Doris monitoring metrics definitions and descriptions. | role (string, Optional), monitor_type (string, Optional), priority (string, Optional) |
get_monitoring_metrics_data |
Get actual Doris monitoring metrics data from nodes with flexible BE discovery. | role (string, Optional), monitor_type (string, Optional), priority (string, Optional) |
get_realtime_memory_stats |
Get real-time memory statistics via BE Memory Tracker with auto/manual BE discovery. | tracker_type (string, Optional), include_details (boolean, Optional) |
get_historical_memory_stats |
Get historical memory statistics via BE Bvar interface with flexible BE configuration. | tracker_names (array, Optional), time_range (string, Optional) |
analyze_data_quality |
Comprehensive data quality analysis combining completeness and distribution analysis. | table_name (string, Required), analysis_scope (string, Optional), sample_size (integer, Optional), business_rules (array, Optional) |
trace_column_lineage |
End-to-end column lineage tracking through SQL analysis and dependency mapping. | target_columns (array, Required), analysis_depth (integer, Optional), include_transformations (boolean, Optional) |
monitor_data_freshness |
Real-time data staleness monitoring with configurable freshness thresholds. | table_names (array, Optional), freshness_threshold_hours (integer, Optional), include_update_patterns (boolean, Optional) |
analyze_data_access_patterns |
User behavior analysis and security anomaly detection with access pattern monitoring. | days (integer, Optional), include_system_users (boolean, Optional), min_query_threshold (integer, Optional) |
analyze_data_flow_dependencies |
Data flow impact analysis and dependency mapping between tables and views. | target_table (string, Optional), analysis_depth (integer, Optional), include_views (boolean, Optional) |
analyze_slow_queries_topn |
Performance bottleneck identification with top-N slow query analysis and patterns. | days (integer, Optional), top_n (integer, Optional), min_execution_time_ms (integer, Optional), include_patterns (boolean, Optional) |
analyze_resource_growth_curves |
Capacity planning with resource growth analysis and trend forecasting. | days (integer, Optional), resource_types (array, Optional), include_predictions (boolean, Optional) |
exec_adbc_query |
High-performance SQL execution using ADBC (Arrow Flight SQL) protocol. | sql (string, Required), max_rows (integer, Optional), timeout (integer, Optional), return_format (string, Optional) |
get_adbc_connection_info |
ADBC connection diagnostics and status monitoring for Arrow Flight SQL. | No parameters required |
Note: All metadata tools support catalog federation for multi-catalog environments. Enhanced monitoring tools provide comprehensive memory tracking and metrics collection capabilities. New in v0.5.0: 7 advanced analytics tools for enterprise data governance and 2 ADBC tools for high-performance data transfer with 3-10x performance improvements for large datasets.
Doris-backed OAuth note: The table above describes global server capabilities. Doris-backed OAuth uses configuration gates for its operation surface. MCP resources are available with resource metadata caching disabled. Reviewed metadata tools are callable when DORIS_OAUTH_DB_TOOLS_ENABLED=true; exec_query and get_sql_explain are callable when their Doris OAuth query/explain gates are enabled. These MySQL-channel operations run through the logged-in Doris user pool, so Doris RBAC is the final data authorization backend. Prompts, ADBC, FE HTTP profile/monitoring, audit/governance, and performance analytics remain closed until they have per-user routing or an explicit service-account/admin design.
4. Run the Service
Execute the following command to start the server:
./start_server.sh
This command starts the FastAPI application with Streamable HTTP MCP service.
5. Deploying on docker
If you want to run only Doris MCP Server in docker:
cd doris-mcp-server
docker build -t doris-mcp-server .
docker run -d -p <port>:<port> -v /*your-host*/doris-mcp-server/.env:/app/.env --name <your-mcp-server-name> -it doris-mcp-server:latest
Service Endpoints:
- Streamable HTTP:
http://<host>:<port>/mcp(Primary MCP endpoint - supports GET, POST, DELETE, OPTIONS) - Health Check:
http://<host>:<port>/health
Note: The server uses Streamable HTTP for web-based communication, providing unified request/response and streaming capabilities.
Usage
Interaction with the Doris MCP Server requires an MCP Client. The client connects to the server's Streamable HTTP endpoint and sends requests according to the MCP specification to invoke the server's tools.
Main Interaction Flow:
- Client Initialization: Send an
initializemethod call to/mcp(Streamable HTTP). - (Optional) Discover Tools: The client can call
tools/listto get the list of supported tools, their descriptions, and parameter schemas. - Call Tool: The client sends a
tools/callrequest, specifying thenameandarguments.- Example: Get Table Schema
name:get_table_schemaarguments: Includetable_name,db_name,catalog_name.
- Example: Get Table Schema
- Handle Response:
- Non-streaming: The client receives a response containing
contentorisError. - Streaming: The client receives a series of progress notifications, followed by a final response.
- Non-streaming: The client receives a response containing
Catalog Federation Support
The Doris MCP Server supports catalog federation, enabling interaction with multiple data catalogs (internal Doris tables and external data sources like Hive, MySQL, etc.) within a unified interface.
Key Features:
- Multi-Catalog Metadata Access: All metadata tools (
get_db_list,get_db_table_list,get_table_schema, etc.) support an optionalcatalog_nameparameter to query specific catalogs. - Cross-Catalog SQL Queries: Execute SQL queries that span multiple catalogs using three-part table naming.
- Catalog Discovery: Use
get_catalog_listto discover available catalogs and their types.
Three-Part Naming Requirement:
All SQL queries MUST use three-part naming for table references:
- Internal Tables:
internal.database_name.table_name - External Tables:
catalog_name.database_name.table_name
Examples:
-
Get Available Catalogs:
{ "tool_name": "get_catalog_list", "arguments": {"random_string": "unique_id"} } -
Get Databases in Specific Catalog:
{ "tool_name": "get_db_list", "arguments": {"random_string": "unique_id", "catalog_name": "mysql"} } -
Query Internal Catalog:
{ "tool_name": "exec_query", "arguments": { "random_string": "unique_id", "sql": "SELECT COUNT(*) FROM internal.ssb.customer" } } -
Query External Catalog:
{ "tool_name": "exec_query", "arguments": { "random_string": "unique_id", "sql": "SELECT COUNT(*) FROM mysql.ssb.customer" } } -
Cross-Catalog Query:
{ "tool_name": "exec_query", "arguments": { "random_string": "unique_id", "sql": "SELECT i.c_name, m.external_data FROM internal.ssb.customer i JOIN mysql.test.user_info m ON i.c_custkey = m.customer_id" } }
Security Configuration
The Doris MCP Server includes a comprehensive enterprise-grade security framework with advanced authentication, authorization, SQL security validation, and data masking capabilities enhanced in v0.6.0.
Security Features (Enhanced in v0.6.0)
- 🔐 Multi-Authentication System: Complete Token, JWT, and OAuth authentication with independent control switches
- 🔗 Token-Bound Database Configuration: Revolutionary approach allowing tokens to carry their own database connection parameters
- 🔄 Hot Reload Security: Zero-downtime security configuration updates with intelligent token revalidation
- ⚡ Immediate Validation: Real-time database and authentication validation at connection time
- 🛡️ Role-Based Authorization: Advanced RBAC with four-tier security classification
- 🚫 Enhanced SQL Security: Advanced SQL injection protection with improved pattern detection
- 🎭 Intelligent Data Masking: Automatic sensitive data masking with user-based permissions
- 📊 Security Analytics: Comprehensive audit trails and security monitoring
Authentication Configuration (v0.6.0)
Configure the new authentication system with granular control:
# Individual Authentication Control (New in v0.6.0)
ENABLE_TOKEN_AUTH=true # Enable token-based authentication
ENABLE_JWT_AUTH=false # Enable JWT authentication
ENABLE_OAUTH_AUTH=false # Enable OAuth authentication
# Token Management (New in v0.6.0)
TOKEN_FILE_PATH=tokens.json # Token configuration file
TOKEN_HOT_RELOAD=true # Enable hot reloading
# Default Tokens (Customizable via environment)
DEFAULT_ADMIN_TOKEN=doris_admin_token_123456
DEFAULT_ANALYST_TOKEN=doris_analyst_token_123456
DEFAULT_READONLY_TOKEN=doris_readonly_token_123456
# Legacy Configuration (Deprecated)
# AUTH_TYPE=token # Use individual switches instead
# TOKEN_SECRET=your_secret_key # Use token-based auth instead
Doris-Backed OAuth Authentication
Doris-backed OAuth is a separate OAuth mode where Doris itself is the authorization backend. The MCP client discovers this server's OAuth metadata, the user signs in with a Doris username and password, the server validates those credentials by creating a per-user Doris connection pool, and issued doa_ access tokens route tool calls through that Doris user's pool. MCP scopes control which MCP operations can be called; Doris RBAC controls which catalogs, databases, tables, and metadata the user can see.
This mode is not the same as external OAuth/OIDC. ENABLE_DORIS_OAUTH_AUTH=true conflicts with ENABLE_OAUTH_AUTH=true, OAUTH_ENABLED=true, and legacy AUTH_TYPE=oauth; startup fails fast if both modes are configured. A standard MCP agent enters one MCP URL and should discover exactly one OAuth behavior for that URL, so the existing /auth/* external OAuth login flow is not used in Doris-backed OAuth mode.
Minimal Local Configuration
The following example is for local development on a single worker:
TRANSPORT=http
WORKERS=1
DORIS_HOST=localhost
DORIS_PORT=9030
DORIS_USER=root
DORIS_PASSWORD=<service-account-password>
DORIS_DATABASE=information_schema
ENABLE_DORIS_OAUTH_AUTH=true
DORIS_OAUTH_BASE_URL=http://localhost:3000
ENABLE_OAUTH_AUTH=false
DORIS_OAUTH_DB_TOOLS_ENABLED=true
DORIS_OAUTH_DB_TOOL_ALLOWLIST=get_db_list,get_db_table_list,get_table_schema,get_table_comment,get_table_column_comments,get_table_indexes,get_catalog_list
DORIS_OAUTH_QUERY_TOOLS_ENABLED=true
DORIS_OAUTH_EXPLAIN_TOOLS_ENABLED=true
# Optional: let Doris RBAC, not the legacy MCP SQL guard, decide DDL/DML.
ENABLE_SECURITY_CHECK=false
The configured service Doris account is still required by startup validation and by non-Doris-OAuth compatibility paths. Doris-backed OAuth requests are fail-closed if the per-user pool is missing and must not fall back to the service/global account.
Doris OAuth Tool Access
DORIS_OAUTH_DB_TOOLS_ENABLED=true opens the reviewed metadata bucket. The reviewed tools are:
get_db_listget_db_table_listget_table_schemaget_table_commentget_table_column_commentsget_table_indexesget_catalog_list
For normal MCP OAuth flows, clients do not need to pass a long --scopes list. If the OAuth request omits scope, the server grants the configured Doris OAuth capability envelope. For MySQL-channel operations, Doris RBAC decides whether the logged-in Doris user can actually read metadata, run SQL, or explain SQL.
DORIS_OAUTH_QUERY_TOOLS_ENABLED=true opens exec_query. DORIS_OAUTH_EXPLAIN_TOOLS_ENABLED=true opens get_sql_explain. If ENABLE_SECURITY_CHECK=true, the legacy MCP SQL security layer can still reject some SQL before Doris sees it. Set ENABLE_SECURITY_CHECK=false when the intended policy is to let Doris RBAC decide SQL/DDL/DML.
Doris-backed OAuth still does not open prompts, ADBC, FE HTTP profile/monitoring, audit/governance, or performance analytics in this phase unless those paths are separately routed through per-user credentials or given an explicit service-account/admin design.
Current Operational Limits
Doris-backed OAuth is currently single-process and single-worker:
WORKERS=1is required.WORKERS=0expands to CPU count and fails when Doris-backed OAuth is enabled.- OAuth clients, authorization transactions, authorization codes, access tokens, refresh tokens, and DCR clients are memory-only and process-local.
- Per-user Doris connection pools are process-local.
- Process restart requires users to sign in again.
- Tokens and pools are not shared across workers, processes, or nodes.
- Stateless horizontal scaling and multi-node deployment are not supported for Doris-backed OAuth yet.
If an access token is otherwise valid but its Doris user pool is gone, the request fails with login required / DORIS_OAUTH_POOL_MISSING. The server does not store raw Doris passwords for automatic pool reconstruction.
Production Hardening
For production deployments:
- Use an HTTPS
DORIS_OAUTH_BASE_URLfor any non-loopback address. - Keep
DORIS_OAUTH_ALLOW_INSECURE_HTTP=false; non-loopbackhttp://is rejected unless explicitly overridden for development. - Enable
DORIS_OAUTH_TRUST_PROXY_HEADERSonly behind a controlled reverse proxy and setDORIS_OAUTH_TRUSTED_PROXY_CIDRS. - Keep login, authorize, token, refresh, revoke, and DCR rate limits enabled.
- Use Doris RBAC as the final data authorization boundary and grant Doris users only the data they should inspect.
- Do not log Doris passwords, authorization headers, access tokens, refresh tokens, authorization codes, PKCE verifiers, or client secrets.
- Treat the
doa_prefix as reserved for Doris-backed OAuth access tokens; static tokens and JWT bearer values must not use it. - Keep Dynamic Client Registration in
autofor loopback development or explicitly configure production DCR withENABLE_DORIS_OAUTH_PRODUCTION_DCR=true.
Token-Bound Database Configuration (New in v0.6.0)
Create a tokens.json file for advanced token management with database binding:
{
"version": "1.0",
"tokens": [
{
"token_id": "customer-a-token",
"token": "customer_a_secure_token_12345",
"description": "Customer A dedicated database access",
"expires_hours": null,
"is_active": true,
"database_config": {
"host": "customer-a-db.example.com",
"port": 9030,
"user": "customer_a_user",
"password": "secure_password",
"database": "customer_a_data",
"charset": "UTF8",
"fe_http_port": 8030
}
},
{
"token_id": "customer-b-token",
"token": "customer_b_secure_token_67890",
"description": "Customer B dedicated database access",
"expires_hours": 720,
"is_active": true,
"database_config": {
"host": "customer-b-db.example.com",
"port": 9030,
"user": "customer_b_user",
"password": "secure_password",
"database": "customer_b_data",
"charset": "UTF8",
"fe_http_port": 8030
}
}
]
}
Hot Reload Configuration Updates (New in v0.6.0)
The system automatically detects and applies configuration changes:
- Automatic Detection: File modification monitoring every 10 seconds
- Instant Validation: Immediate database configuration validation for new tokens
- Zero Downtime: Configuration updates without service interruption
- Rollback Protection: Automatic rollback on configuration errors
- Audit Trail: Complete logging of configuration changes
Token Authentication Example
# Client authentication with token
auth_info = {
"type": "token",
"token": "your_jwt_token",
"session_id": "unique_session_id"
}
Basic Authentication Example
# Client authentication with username/password
auth_info = {
"type": "basic",
"username": "analyst",
"password": "secure_password",
"session_id": "unique_session_id"
}
Authorization & Security Levels
The system supports four security levels with hierarchical access control:
| Security Level | Access Scope | Typical Use Cases |
|---|---|---|
| Public | Unrestricted access | Public reports, general statistics |
| Internal | Company employees | Internal dashboards, business metrics |
| Confidential | Authorized personnel | Customer data, financial reports |
| Secret | Senior management | Strategic data, sensitive analytics |
Role Configuration
Configure user roles and permissions:
# Example role configuration
role_permissions = {
"data_analyst": {
"security_level": "internal",
"permissions": ["read_data", "execute_query"],
"allowed_tables": ["sales", "products", "orders"]
},
"data_admin": {
"security_level": "confidential",
"permissions": ["read_data", "execute_query", "admin"],
"allowed_tables": ["*"]
},
"executive": {
"security_level": "secret",
"permissions": ["read_data", "execute_query", "admin"],
"allowed_tables": ["*"]
}
}
SQL Security Validation
The system automatically validates SQL queries for security risks:
Blocked Operations
Configure blocked SQL operations using environment variables (New in v0.4.2):
# Enable/disable SQL security check (New in v0.4.2)
ENABLE_SECURITY_CHECK=true
# Customize blocked keywords via environment variable (New in v0.4.2)
BLOCKED_KEYWORDS="DROP,DELETE,TRUNCATE,ALTER,CREATE,INSERT,UPDATE,GRANT,REVOKE,EXEC,EXECUTE,SHUTDOWN,KILL"
# Maximum query complexity score
MAX_QUERY_COMPLEXITY=100
Default Blocked Keywords (Unified in v0.4.2):
- DDL Operations: DROP, CREATE, ALTER, TRUNCATE
- DML Operations: DELETE, INSERT, UPDATE
- DCL Operations: GRANT, REVOKE
- System Operations: EXEC, EXECUTE, SHUTDOWN, KILL
SQL Injection Protection
The system automatically detects and blocks:
- Union-based injections:
UNION SELECTattacks - Boolean-based injections:
OR 1=1patterns - Time-based injections:
SLEEP(),WAITFORfunctions - Comment injections:
--,/**/patterns - Stacked queries: Multiple statements separated by
;
Example Security Validation
# This query would be blocked
dangerous_sql = "SELECT * FROM users WHERE id = 1; DROP TABLE users;"
# This query would be allowed
safe_sql = "SELECT name, email FROM users WHERE department = 'sales'"
Data Masking Configuration
Configure automatic data masking for sensitive information:
Built-in Masking Rules
# Default masking rules
masking_rules = [
{
"column_pattern": r".*phone.*|.*mobile.*",
"algorithm": "phone_mask",
"parameters": {
"mask_char": "*",
"keep_prefix": 3,
"keep_suffix": 4
},
"security_level": "internal"
},
{
"column_pattern": r".*email.*",
"algorithm": "email_mask",
"parameters": {"mask_char": "*"},
"security_level": "internal"
},
{
"column_pattern": r".*id_card.*|.*identity.*",
"algorithm": "id_mask",
"parameters": {
"mask_char": "*",
"keep_prefix": 6,
"keep_suffix": 4
},
"security_level": "confidential"
}
]
Masking Algorithms
| Algorithm | Description | Example |
|---|---|---|
phone_mask |
Masks phone numbers | 138****5678 |
email_mask |
Masks email addresses | j***[email protected] |
id_mask |
Masks ID card numbers | 110101****1234 |
name_mask |
Masks personal names | 张*明 |
partial_mask |
Partial masking with ratio | abc***xyz |
Custom Masking Rules
Add custom masking rules in your configuration:
# Custom masking rule
custom_rule = {
"column_pattern": r".*salary.*|.*income.*",
"algorithm": "partial_mask",
"parameters": {
"mask_char": "*",
"mask_ratio": 0.6
},
"security_level": "confidential"
}
Security Configuration Examples
Environment Variables
# .env file
AUTH_TYPE=token
TOKEN_SECRET=your_jwt_secret_key
ENABLE_MASKING=true
MAX_RESULT_ROWS=10000
BLOCKED_SQL_OPERATIONS=DROP,DELETE,TRUNCATE,ALTER
MAX_QUERY_COMPLEXITY=100
ENABLE_AUDIT=true
Sensitive Tables Configuration
# Configure sensitive tables with security levels
sensitive_tabl
No comments yet
Be the first to share your take.