Orionbelt Semantic Layer
Connects to PostgreSQL databases to analyze schemas, generate RDF/Turtle ontologies and R2RML mappings with SQL references, and execute validated SQL queries for Text-to-SQL workflows.
Connects to Snowflake databases to analyze schemas, generate RDF/Turtle ontologies and R2RML mappings with SQL references, and execute validated SQL queries for Text-to-SQL workflows.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
This repository has been archived. Development continues in the following projects:
Orionbelt Analytics — Analytics platform
Orionbelt Semantic Layer — Semantic layer MCP server
Orionbelt Semantic Layer
Orionbelt Semantic Layer - the Ontology-based MCP server for your Text-2-SQL convenience.
This project provides a production-ready Python-based MCP (Model Context Protocol) server that analyzes relational database schemas (PostgreSQL, Snowflake, and Dremio) and automatically generates comprehensive ontologies in RDF/Turtle format with direct SQL mappings.
Key Philosophy: Automatic Ontology Integration
Our main analysis tool get_analysis_context() automatically includes ontology generation, making semantic context readily available for every query.
Related MCP server: io.github.Optisol-Business/db-metadata-extractor-mcp
🌟 Key Features
🔗 Database Connectivity
PostgreSQL, Snowflake, and Dremio support with connection pooling
Environment variable fallback - parameters optional, uses .env when not provided
Enhanced connection management with retry logic and timeout handling
Automatic dependency management for Snowflake and Dremio connectors
🎯 13 Essential Tools
Streamlined workflow with focused, purpose-built tools
Interactive charting (
generate_chart) with direct image renderingComprehensive schema analysis with automatic ontology generation
Semantic name resolution for business-friendly ontologies
Custom ontology loading from external files
Built-in workflow guidance via FastMCP Context integration
Focus on results - maximum effectiveness with minimum complexity
🧠 Automatic Ontology Generation
Self-sufficient ontologies with direct database references (
db:sqlReference,db:sqlJoinCondition)Business context inference from table and column naming patterns
Complete SQL mappings embedded directly in ontology
Fan-trap detection and query safety validation
🗺️ R2RML Mapping Generation
W3C-compliant R2RML mappings auto-generated alongside schema analysis
SQL query templates with
rr:sqlQueryandrr:sqlVersion rr:SQL2008XSD datatype mapping from SQL types to RDF datatypes
Configurable base IRI via environment variable (
R2RML_BASE_IRI)
🛡️ Advanced SQL Safety
Fan-trap prevention protocols with mandatory relationship analysis
Query pattern validation to prevent data multiplication errors
Safe aggregation patterns (UNION, separate CTEs, window functions)
Comprehensive SQL validation before execution
⚡ Performance & Reliability
Concurrent processing with thread pool management
Connection pooling and resource optimization
Comprehensive error handling with structured responses
Production-ready logging and monitoring
Python Library Installation
Required Dependencies
# Install all required dependencies
uv syncComplete Library List
The project uses the following Python libraries:
Core MCP Framework
fastmcp>=2.12.0 # FastMCP framework for MCP server implementationDatabase Connectivity
sqlalchemy>=2.0.0,<3.0.0 # Database ORM and connection management
psycopg2-binary>=2.9.0,<3.0.0 # PostgreSQL database adapter
snowflake-sqlalchemy>=1.5.0,<2.0.0 # Snowflake SQLAlchemy dialect
snowflake-connector-python>=3.0.0,<4.0.0 # Snowflake Python connector
# Dremio uses PostgreSQL wire protocol (psycopg2-binary above)Configuration & Environment
pydantic>=2.0.0,<3.0.0 # Data validation and settings management
python-dotenv>=1.0.0,<2.0.0 # Environment variable loading from .env filesSemantic Web & Ontology
rdflib>=7.0.0,<8.0.0 # RDF graph creation and manipulation
owlrl>=6.0.0,<7.0.0 # OWL reasoning and validationAutomatic Dependencies (installed with above)
When you install the main dependencies, these will be automatically installed:
Database & Connection:
boto3,botocore- AWS SDK (for Snowflake S3 integration)cryptography- Encryption and security functionspyOpenSSL- SSL/TLS supportcffi- C Foreign Function Interfaceasn1crypto- ASN.1 parsing and encoding
Data Processing:
sortedcontainers- Sorted list/dict implementationsplatformdirs- Platform-specific directory locationsfilelock- File locking utilities
Network & Auth:
requests- HTTP libraryurllib3- HTTP clientcertifi- Certificate bundlepyjwt- JWT token handling
Configuration:
tomlkit- TOML file parsingtyping_extensions- Enhanced type hints
Manual Installation (if needed)
If you encounter issues with automatic installation, install key components manually:
# Core framework
pip install fastmcp>=2.12.0
# Database support
pip install sqlalchemy>=2.0.0 psycopg2-binary>=2.9.0
# Snowflake support (may require additional system dependencies)
pip install snowflake-sqlalchemy snowflake-connector-python
# Dremio support (uses PostgreSQL protocol, psycopg2-binary already installed above)
# Semantic web
pip install rdflib>=7.0.0 owlrl>=6.0.0
# Configuration
pip install pydantic>=2.0.0 python-dotenv>=1.0.0System Dependencies
For some libraries, you might need system-level dependencies:
macOS (via Homebrew):
brew install postgresql # For psycopg2
brew install openssl # For cryptographic functionsUbuntu/Debian:
sudo apt-get install libpq-dev python3-dev # For psycopg2
sudo apt-get install libssl-dev libffi-dev # For cryptographic functionsWindows:
Most dependencies work out of the box with pip
For PostgreSQL support, ensure PostgreSQL client libraries are installed
Project Structure
database-ontology-mcp/
├── src/
│ ├── __init__.py # Package initialization
│ ├── main.py # FastMCP server entry point (13 tools)
│ ├── database_manager.py # Database connection and analysis
│ ├── ontology_generator.py # RDF ontology generation with SQL mappings
│ ├── r2rml_generator.py # W3C R2RML mapping generation
│ ├── dremio_client.py # Dremio database client
│ ├── security.py # Security and validation utilities
│ ├── chart_utils.py # Chart generation utilities
│ ├── config.py # Configuration management with .env support
│ ├── constants.py # Application constants and settings
│ ├── shared.py # Shared utilities and helpers
│ └── tools/ # Tool implementations
│ ├── __init__.py # Tools package initialization
│ ├── chart.py # Chart generation tool
│ ├── connection.py # Database connection tools
│ ├── info.py # Server info tool
│ ├── ontology.py # Ontology generation tool
│ ├── query.py # SQL query execution tool
│ └── schema.py # Schema analysis tools
├── tests/ # Test suite
├── tmp/ # Generated files (ontologies, charts)
├── server.py # Server startup script
├── .env # Environment configuration (DO NOT COMMIT)
├── pyproject.toml # Project metadata and dependencies
└── README.md # This comprehensive guide🚀 Quick Start
Prerequisites
Python 3.13 or higher (required)
uv package manager (recommended) - Install uv
PostgreSQL, Snowflake, or Dremio database access
Installation
Clone the repository:
git clone https://github.com/ralfbecher/database-ontology-mcp
cd database-ontology-mcpInstall dependencies with uv (recommended):
# Install all dependencies using uv (automatically creates venv with Python 3.13)
uv syncAlternative: Manual venv setup
# Create and activate a virtual environment with Python 3.13
python3.13 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e .Note: The charting functionality requires visualization libraries (pandas, plotly, kaleido). These are automatically installed via uv sync or pip install -e .
Configure environment:
# Create .env file with your database credentials
cp .env.template .env # If template exists, or create new .envEnvironment Configuration
Create a .env file in the project root:
# =================================================================
# Database Ontology MCP Server Configuration
# =================================================================
# Server Configuration
LOG_LEVEL=INFO
ONTOLOGY_BASE_URI=http://example.com/ontology/
# R2RML Mapping Configuration
R2RML_BASE_IRI=http://mycompany.com/
OUTPUT_DIR=tmp
# MCP Transport Configuration
# Options: http, sse (Server-Sent Events)
# - http: Standard HTTP transport (streamable, default)
# - sse: Server-Sent Events for (legacy)
MCP_TRANSPORT=http
MCP_SERVER_HOST=localhost
MCP_SERVER_PORT=9000
# PostgreSQL Configuration (optional - can provide via tool parameters)
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
# Snowflake Configuration (optional - can provide via tool parameters)
SNOWFLAKE_ACCOUNT=CLYKFLK-KA74251 # Use your actual account identifier
SNOWFLAKE_USERNAME=your_username
SNOWFLAKE_PASSWORD=your_password
SNOWFLAKE_WAREHOUSE=COMPUTE_WH
SNOWFLAKE_DATABASE=SNOWFLAKE_SAMPLE_DATA
SNOWFLAKE_SCHEMA=TPCH_SF10
SNOWFLAKE_ROLE=PUBLIC
# Dremio Configuration (optional - can provide via tool parameters)
DREMIO_HOST=localhost
DREMIO_PORT=31010
DREMIO_USERNAME=your_username
DREMIO_PASSWORD=your_password
# Snowflake Troubleshooting:
# - Account format: Check Snowflake web UI URL for correct format
# Common formats: CLYKFLK-KA74251, account.region, account.region.cloud
# - Role: Ensure your user has access to the specified role
# - Warehouse: Must be running and accessible
# - Database/Schema: Check permissions and case sensitivity
# Dremio Troubleshooting:
# - Host: Dremio coordinator node hostname or IP
# - Port: Default PostgreSQL wire protocol port is 31010
# - SSL: Enable/disable SSL connections (default: enabled)
# - Connection: Uses PostgreSQL protocol, no additional drivers neededTransport Configuration
The server supports two MCP transport modes:
http(default, recommended): Streamable HTTP transport for modern MCP clients. This is the standard transport for FastMCP servers and provides better performance and reliability.sse: Server-Sent Events transport for legacy compatibility. Use this if you need compatibility with older MCP clients.
You can configure the transport by setting MCP_TRANSPORT in your .env file. The server will automatically validate the transport type and default to http if an invalid value is provided.
Running the Server
With uv (recommended):
uv run server.pyOr with activated virtual environment:
source .venv/bin/activate # On Windows: .venv\Scripts\activate
python server.pyClaude Desktop Integration
Start the server manually:
cd /path/to/database-ontology-mcp
uv run server.pyOr with activated venv:
cd /path/to/database-ontology-mcp
source .venv/bin/activate # On Windows: .venv\Scripts\activate
python server.pyAdd to your Claude Desktop MCP settings (claude_desktop_config.json):
{
"mcpServers": {
"Orionbelt-Semantic-Layer": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:9000/mcp",
"--transport",
"http-only"
]
}
}
}Hint: use Sonnet 4.5 within Claude Desktop. Haiku 4.5 tends to be "looser" with tooling guidance.
LibreChat Integration
Run MCP Transport SSE for LibreChat:
Start the server manually with SSE transport:
cd /path/to/database-ontology-mcp
# Set MCP_TRANSPORT=sse in your .env file first
uv run server.pyAdd to your librechat.yaml:
# MCP Servers Configuration
mcpServers:
Orionbelt-Semantic-Layer:
url: "http://host.docker.internal:9000/sse"
timeout: 60000 # 1 minute timeout for this server
startup: true # Initialize during app startupNote: LibreChat requires SSE transport (having seen some bugs with transport http). Make sure to set MCP_TRANSPORT=sse in your .env file before starting the server.
MCP Tools Reference
Workflow Guidance
The server provides built-in workflow guidance through FastMCP Context integration, automatically suggesting the next recommended tool after each operation. This helps Claude Desktop users follow optimal analytical workflows without confusion.
Key Workflows:
Complete Schema Analysis → Ontology → SQL
connect_database→analyze_schema→generate_ontology→execute_sql_query
Quick Data Exploration
connect_database→list_schemas→sample_table_data
SQL Validation → Execution → Visualization
validate_sql_syntax→execute_sql_query→generate_chart
Relationship Analysis for Complex Queries
analyze_schema(check FKs) →validate_sql_syntax→execute_sql_query
Core Database Tools
1. connect_database
Connect to PostgreSQL, Snowflake, or Dremio with environment variable fallback.
Key Feature: Parameters are optional - uses .env values when not provided.
Parameters:
{
db_type: "postgresql" | "snowflake" | "dremio",
// All other parameters optional - falls back to .env values
host?: string, port?: number, database?: string,
username?: string, password?: string,
account?: string, warehouse?: string, schema?: string, role?: string,
ssl?: boolean // Dremio only
}Examples:
# Simple connection using .env values
connect_database("postgresql")
connect_database("snowflake")
connect_database("dremio")
# Override specific parameters
connect_database("postgresql", host="custom.host.com", port=5433)
connect_database("snowflake", account="CUSTOM-ACCOUNT", warehouse="ANALYTICS_WH")
connect_database("dremio", host="dremio.company.com", port=31010, ssl=False)2. list_schemas
Get available database schemas.
Returns: Array<string> of schema names
3. reset_cache
Clear cached schema analysis and ontology data for the current session.
Returns: Confirmation of cleared cache items
4. analyze_schema
Analyze database schema and return comprehensive table information including relationships.
Parameters:
schema_name(optional): Name of schema to analyze
Returns: Schema structure with tables, columns, primary keys, foreign keys, and relationship information
Output Files:
Schema analysis:
tmp/schema_{schema_name}_{timestamp}.jsonR2RML mapping:
tmp/r2rml_{schema_name}_{timestamp}.ttl
Key Features:
Foreign key analysis is critical for preventing fan-traps in SQL queries
JSON export enables schema reuse and version control
Automatic R2RML generation with W3C-compliant mappings
File paths included in response for easy access
5. generate_ontology
Generate RDF/OWL ontology from database schema with SQL mapping annotations.
Parameters:
schema_info(optional): JSON string with schema informationschema_name(optional): Name of schema to generate ontology frombase_uri(optional): Base URI for ontology (default: http://example.com/ontology/)
Returns: RDF ontology in Turtle format with db: namespace annotations
Output: Ontology is saved to tmp/ontology_{schema}_{timestamp}.ttl
Semantic Name Resolution Tools
6. suggest_semantic_names
Extract and analyze names from a generated ontology to identify abbreviations and cryptic names for business-friendly improvements.
Purpose: Since MCP Sampling is not available in Claude Desktop, this tool enables a workflow where the LLM can review and suggest better names.
Parameters:
ontology_ttl(optional): Turtle format ontology string to analyzeschema_name(optional): Schema name to regenerate ontology from database
Returns:
classes: List of table/class names with analysisproperties: List of column/property names with analysisrelationships: List of foreign key relationships with analysisanalysis_hints: Summary of detected issuesllm_instructions: Instructions for generating name suggestions
Name Detection: Automatically detects abbreviations (cust, ord, amt), cryptic suffixes (_dt, _cd, _no), technical prefixes (pk_, fk_, tbl_), and all-caps acronyms.
7. apply_semantic_names
Apply LLM-suggested semantic names to the ontology, updating labels and adding business descriptions.
Parameters:
suggestions(required): JSON string with name suggestions:{ "classes": [ { "original_name": "cust_mstr", "suggested_name": "Customer Master", "description": "..." } ], "properties": [ { "original_name": "ord_dt", "table_name": "orders", "suggested_name": "Order Date", "description": "..." } ], "relationships": [ { "original_name": "orders_has_customers", "suggested_name": "Placed By", "description": "..." } ] }schema_name(optional): Schema name to regenerate ontology before applyingsave_to_file(optional): Whether to save updated ontology (default: true)
Output: Updated ontology saved to tmp/ontology_{schema}_semantic_{timestamp}.ttl
What Gets Updated:
rdfs:label→ suggested business-friendly namedb:semanticName→ new semantic annotationrdfs:comment→ provided description (standard RDF property)Original
db:tableName/db:columnNamepreserved for SQL generation
Workflow Example:
# 1. Generate initial ontology
generate_ontology(schema_name="public")
# 2. Extract names for review
suggest_semantic_names(schema_name="public")
# 3. Apply LLM suggestions
apply_semantic_names(suggestions='{"classes": [{"original_name": "cust", "suggested_name": "Customer", "description": "Customer entity"}]}')8. load_my_ontology
Load a custom .ttl ontology file from an import folder to use as semantic context.
Purpose: Use pre-existing or manually curated ontologies instead of auto-generating from database schema.
Parameters:
import_folder(optional): Path to folder containing .ttl files (default:./import)
Behavior:
Scans the import folder for .ttl files
Selects the newest file by modification time
Parses and validates the ontology
Stores in server state for subsequent operations
Returns:
success: Boolean indicating if ontology was loadedfile_path: Path to the loaded fileclasses_count: Number of OWL classes foundproperties_count: Number of properties foundrelationships_count: Number of object properties foundontology_preview: First 2000 characters of the ontology
Example:
# Load from default import folder
load_my_ontology()
# Load from custom folder
load_my_ontology(import_folder="/path/to/my/ontologies")Data & Validation Tools
9. sample_table_data
Secure data sampling with comprehensive validation.
Parameters:
{
table_name: string, // Required, validated against SQL injection
schema_name?: string, // Optional schema specification
limit?: number // Max 1000, default 10
}10. validate_sql_syntax
Advanced SQL validation with comprehensive analysis.
Parameters:
sql_query(required): SQL query to validate
Returns:
is_valid: Boolean validation resultdatabase_dialect: Detected database dialectvalidation_results: Detailed component analysissuggestions: Optimization recommendationswarnings: Performance concernserrors: Specific syntax errorssecurity_analysis: Security findings
Features: Multi-database syntax checking, injection detection, performance analysis
11. execute_sql_query
Safe SQL execution with comprehensive safety protocols.
Features:
Fan-trap detection - Prevents data multiplication errors
Query pattern analysis - Identifies risky aggregation patterns
Result validation - Checks if results make business sense
Execution limits - Row limits and timeout protection
Critical Safety Patterns Included:
-- ✅ SAFE: UNION approach for multi-fact queries
WITH unified_facts AS (
SELECT customer_id, sales_amount, 0 as returns FROM sales
UNION ALL
SELECT customer_id, 0, return_amount FROM returns
)
SELECT customer_id, SUM(sales_amount), SUM(returns) FROM unified_facts GROUP BY customer_id;
-- ❌ DANGEROUS: Direct joins with aggregation (causes fan-trap)
SELECT customer_id, SUM(sales_amount), SUM(return_amount)
FROM sales s LEFT JOIN returns r ON s.customer_id = r.customer_id
GROUP BY customer_id; -- This multiplies sales_amount incorrectly!12. generate_chart
Generate interactive charts from SQL query results with support for stacked bar charts and multi-measure line charts. Uses Plotly for visualization with MCP-UI support for interactive rendering in Claude Desktop.
Parameters:
data_source(required): MUST BE VALID JSON - Array of objects (typically fromexecute_sql_query)⚠️ CRITICAL: Send as actual JSON array with double quotes, NOT a string representation
✅ Correct:
[{"country": "USA", "count": 5}, {"country": "UK", "count": 3}]❌ Wrong:
"[{'country': 'USA', 'count': 5}]"(string with single quotes)
chart_type(required): 'bar', 'line', 'scatter', or 'heatmap'x_column(required): Column name for X-axisy_column(optional): Column name(s) for Y-axisString: Single measure (all chart types)
List of strings: Multiple measures (line charts only - creates multi-line comparison)
⚠️ IMPORTANT: Must contain numeric values (integers or floats)
color_column(optional): Column for color groupingFor bar charts: creates grouped or stacked bars based on
chart_styleFor line/scatter: creates separate series with different colors
title(optional): Chart title (auto-generated if not provided)chart_style(optional): 'grouped' or 'stacked' for bar charts'grouped': Bars side-by-side for comparison
'stacked': Bars stacked on top (requires
color_columnfor two dimensions)
width(optional): Chart width in pixels (default: 800)height(optional): Chart height in pixels (default: 600)output_format(optional): 'image' (default) or 'interactive''image': Returns PNG image using kaleido (works with local MCP servers)
'interactive': Returns UIResource with embedded Plotly chart (requires remote HTTPS connector for MCP Apps)
Returns:
Interactive mode: UIResource with self-contained HTML/Plotly chart
Image mode: FastMCP Image object for direct display in Claude Desktop
Output: Chart saved to tmp/chart_{timestamp}.png (image mode)
Key Features:
Interactive Plotly charts with zoom, pan, hover tooltips via MCP-UI
Stacked bar charts with two dimensions for part-to-whole relationships
Multi-measure line charts for comparing multiple metrics on the same chart
PNG export using kaleido for static image output
Direct rendering in Claude Desktop via MCP-UI protocol
Examples:
# Interactive stacked bar chart (default)
result = execute_sql_query("""
SELECT region, product_type, SUM(revenue) as total
FROM sales GROUP BY region, product_type
""")
generate_chart(result['data'], 'bar', 'region', 'total', 'product_type', chart_style='stacked')
# Multi-measure line chart comparison
result = execute_sql_query("SELECT month, revenue, expenses, profit FROM monthly_data ORDER BY month")
generate_chart(result['data'], 'line', 'month', ['revenue', 'expenses', 'profit'])
# Static PNG image output
generate_chart(result['data'], 'bar', 'region', 'total', output_format='image')13. get_server_info
Comprehensive server status and configuration information.
Returns: Server version, available features, tool list, configuration details
🎯 Optimal Workflow for Claude Desktop
Recommended Analytical Session Startup
The server provides built-in comprehensive instructions that are automatically sent to Claude Desktop, guiding optimal tool usage and workflows. This eliminates confusion and ensures accurate Text-to-SQL generation with fan-trap prevention.
Recommended Starting Prompts:
"Connect to my PostgreSQL database and analyze the schema with ontology generation""I need to query my Snowflake data warehouse - help me understand the schema relationships first"Key Improvements in Recent Updates
FastMCP 2.12+ Integration:
Updated to latest FastMCP version with new resource API
Removed deprecated
@mcp.list_resources()and@mcp.read_resource()decoratorsImplemented new
@mcp.resource()decorator with URI templates
Chart Generation Enhancement:
Interactive charts via MCP-UI with Plotly rendering in Claude Desktop
Static PNG export using kaleido
Charts saved to
tmp/directory for reference
Workflow Guidance:
Added FastMCP Context parameter to all tools
Automatic next-tool suggestions after each operation
Comprehensive server instructions for optimal workflows
Built-in fan-trap prevention guidance
Fan-Trap Protection
The Fan-Trap Problem
Fan-traps occur when joining tables with 1:many relationships and using aggregation functions, causing data multiplication:
-- This query is WRONG and will inflate sales figures
SELECT c.customer_name, SUM(s.amount) as total_sales
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
LEFT JOIN shipments sh ON o.id = sh.order_id
GROUP BY c.customer_name;
-- If an order has multiple shipments, sales amount gets multiplied!Our tools provide automatic protection:
Relationship Analysis - Identifies all 1:many relationships
Pattern Detection - Flags dangerous query patterns
Safe Alternatives - Suggests UNION-based approaches
Result Validation - Checks if totals make sense
Safe Query Patterns
The server promotes these proven patterns:
UNION Approach (Recommended):
WITH unified_metrics AS (
SELECT entity_id, sales_amount, 0 as shipped_qty, 'SALES' as metric_type FROM sales
UNION ALL
SELECT entity_id, 0, shipped_quantity, 'SHIPMENT' as metric_type FROM shipments
)
SELECT entity_id, SUM(sales_amount), SUM(shipped_qty) FROM unified_metrics GROUP BY entity_id;Testing & Validation
Quick Connection Test
# Test PostgreSQL connection
python3 -c "
from src.config import config_manager
from src.database_manager import DatabaseManager
db_config = config_manager.get_database_config()
db_manager = DatabaseManager()
success = db_manager.connect_postgresql(
db_config.postgres_host, db_config.postgres_port,
db_config.postgres_database, db_config.postgres_username,
db_config.postgres_password
)
print(f'PostgreSQL connection: {\"✅ Success\" if success else \"❌ Failed\"}')
"
# Test Snowflake connection
python3 -c "
from src.config import config_manager
from src.database_manager import DatabaseManager
db_config = config_manager.get_database_config()
db_manager = DatabaseManager()
success = db_manager.connect_snowflake(
db_config.snowflake_account, db_config.snowflake_username,
db_config.snowflake_password, db_config.snowflake_warehouse,
db_config.snowflake_database, db_config.snowflake_schema,
db_config.snowflake_role
)
print(f'Snowflake connection: {\"✅ Success\" if success else \"❌ Failed\"}')
"Validate All Dependencies
# Check all required libraries are installed
python3 -c "
import sys
required_libs = [
'fastmcp', 'sqlalchemy', 'psycopg2', 'snowflake.sqlalchemy',
'snowflake.connector', 'pydantic', 'dotenv', 'rdflib', 'owlrl'
]
missing = []
for lib in required_libs:
try:
__import__(lib)
print(f'✅ {lib}')
except ImportError:
print(f'❌ {lib}')
missing.append(lib)
if missing:
print(f'\\nMissing libraries: {missing}')
print('Run: pip install -r requirements.txt')
else:
print('\\n🎉 All dependencies installed successfully!')
"🧪 Testing & Quality
The project includes a comprehensive test suite covering core functionality:
Current Test Status (Updated):
56 tests passing (61%) - Core functionality validated
24 tests failing (26%) - Known issues documented below
12 tests skipped (13%) - Integration tests require testcontainers setup
27% code coverage - Focus on critical paths
Test Improvements:
✅ Fixed (3 tests): Added missing utility functions (format_bytes, sanitize_for_logging, validate_uri)
Remaining Test Issues:
Server/MCP Tools Tests (20 failures):
Root Cause: Tests written for pre-FastMCP 2.12 architecture
Tests try to call tools as direct functions (e.g.,
connect_database())Current implementation uses
@mcp.tool()decorator with async functionsFix Required: Complete rewrite of tests to use FastMCP test utilities
Impact: Does NOT affect production functionality - all MCP tools work correctly
Database Manager Tests (2 failures):
Mock configuration issues with SQLAlchemy context managers
get_connection()context manager not properly mocked in testsFix Required: Update mock setup for
engine.connect()context manager
Security Tests (4 failures):
Encryption without master password edge cases
Identifier validation integration test mock issues
Fix Required: Enhanced mock configuration for security validators
What Works (Verified by Tests):
✅ Ontology generation (16/16 tests pass)
✅ Core security validation (13/17 tests pass)
✅ Database operations (16/18 tests pass)
✅ Utility functions (3/3 tests pass)
✅ All production functionality works correctly
Running Tests:
# Run all tests
uv run pytest
# Run with coverage report
uv run pytest --cov=src --cov-report=term-missing
# Run specific test categories
uv run pytest tests/test_ontology_generator.py # ✅ All pass (16/16)
uv run pytest tests/test_database_manager.py # 16/18 pass
uv run pytest tests/test_security.py # 13/17 pass
uv run pytest tests/test_server.py # 3/23 pass (needs FastMCP rewrite)
# Run only passing tests
uv run pytest -k "not TestMCPTools and not TestOntologyGenerator" tests/test_server.pyImportant Note:
The 24 failing tests are test infrastructure issues, not production bugs:
Server tests need to be rewritten for FastMCP 2.12+ architecture
Mock configurations need updates for SQLAlchemy context managers
All actual MCP tools and features work correctly in Claude Desktop
Users can confidently use all features documented in this README. The test failures do not indicate functional problems with the server.
Configuration Troubleshooting
Snowflake Connection Issues
Account Format Problems:
Check your Snowflake web UI URL
Account format:
ORGNAME-ACCOUNT
Role and Permissions:
Ensure user has access to specified role (default: PUBLIC)
Verify warehouse is running and accessible
Check database and schema permissions
PostgreSQL Connection Issues
Common Solutions:
Verify PostgreSQL service is running
Check firewall/network connectivity
Confirm credentials and database name
Test with psql command line first
License
This project is licensed under the MIT License - see the LICENSE file for details.
📋 Recent Changes
Version 0.4.1
Chart Generation Modernization (Feb 2026):
Plotly 6.x upgrade - Updated from Plotly 5.x to 6.5.2 for improved performance and compatibility
Removed matplotlib/seaborn - Simplified visualization stack to Plotly-only
Added kaleido 1.2.0 - For PNG export (compatible with Plotly 6.x)
MCP-UI integration - Interactive charts render directly in Claude Desktop via
mcp-ui-serverRemoved
chart_libraryparameter - No longer needed with single visualization libraryNew
output_formatparameter - Choose between 'interactive' (UIResource) or 'image' (PNG)Self-contained HTML charts - Interactive mode embeds Plotly data directly in HTML
Dependencies Updated:
plotly>=6.1.1(was>=5.24.0)kaleido>=1.2.0(new, replaces matplotlib for PNG)mcp-ui-server>=1.0.0(for interactive UI rendering)Removed:
matplotlib,seaborn
Version 0.4.0
R2RML Mapping Generation (Dec 2025):
Automatic R2RML generation - W3C-compliant R2RML mappings auto-generated with
analyze_schemaR2RMLGenerator class - New
src/r2rml_generator.pymodule for RDB-to-RDF mappingSQL query templates - Uses
rr:logicalTablewithrr:sqlQueryandrr:sqlVersion rr:SQL2008XSD datatype mapping - Automatic mapping from SQL types to XSD datatypes
Configurable base IRI -
R2RML_BASE_IRIenvironment variable (default:http://mycompany.com/)Output directory -
OUTPUT_DIRenvironment variable for generated files (default:tmp)
Per-Session State Isolation (Dec 2025):
Session isolation - Each MCP session gets isolated database connections and file tracking
SessionData class - Per-session storage for db_manager, schema_file, ontology_file, r2rml_file
Robust session ID - Fallback mechanism for HTTP transport compatibility (
ctx.session_id→id(ctx.session)→ default)Fixed FastMCP state bug -
ctx.session.statedoesn't exist; implemented custom session management
Dependency Updates:
FastMCP upgraded to 2.13.2+
Updated Pydantic, rdflib, and other dependencies to latest versions
Version 0.3.5
New Semantic Name Resolution Tools (Nov 2025):
suggest_semantic_names- Extract and analyze ontology names to identify abbreviations and cryptic identifiersapply_semantic_names- Apply LLM-suggested business-friendly names to ontology withdb:semanticNameanddb:businessDescriptionannotationsload_my_ontology- Load custom .ttl ontology files from import folder for use as semantic context
Enhancements:
Added
db:semanticNameanddb:businessDescriptionannotations for enhanced business contextAutomatic detection of cryptic naming patterns (abbreviations, suffixes like
_dt,_cd,_no)Server state management for loaded ontologies
Updated
execute_sql_queryto handle string boolean parameters from LLMsUpdated FastMCP dependency to 2.13.1
Version 0.3.2
Python 3.13 Upgrade (Oct 2025):
Updated project to require Python 3.13+
Configured
uvfor Python 3.13 support via.python-versionfileUpdated
pyproject.tomlto reflect Python 3.13 requirementsUpdated Black and mypy configurations for Python 3.13
Modernized README with
uv-based workflow instructions
Version 0.3.1
Ontology Generation Fix (Oct 2025):
Fixed ontology modeling - tables are now proper top-level OWL classes
Removed incorrect
owl:Restrictionsubclass relationshipsPK constraints preserved as metadata annotations (
db:isPrimaryKey,db:isNullable)Follows proper OWL best practices for domain modeling
Schema Analysis Enhancement (Oct 2025):
analyze_schemanow exports results to JSON files in tmp/ folderFormat:
tmp/schema_{schema_name}_{timestamp}.jsonEnables schema versioning, reuse, and offline analysis
File path included in response for easy access
Version 0.3.0
FastMCP 2.12+ Upgrade (Oct 2025):
Upgraded to FastMCP 2.12+ with new resource API
Replaced deprecated resource decorators
Fixed resource API deprecation warnings
Chart Generation Enhancement (Oct 2025):
Stacked bar charts with two dimensions (x_column + color_column)
Multi-measure line charts for comparing multiple metrics (y_column accepts list)
Return Image objects directly instead of resource URIs
Removed in-memory image store complexity
Simplified error handling with exceptions
Better Claude Desktop integration
Workflow Guidance Enhancement (Oct 2025):
Added FastMCP Context parameter to all tools
Automatic next-tool suggestions
Comprehensive MCP server instructions
Improved client workflow guidance
Test & Security Improvements (Oct 2025):
43% reduction in test failures (18 tests fixed)
Enhanced SQL injection detection (comment-based attacks)
Improved identifier sanitization
Better ontology generation with enrichment methods
Contributing
We welcome contributions! Key areas for improvement:
Additional Database Support (MySQL, Oracle, etc.)
Enhanced Ontology Patterns (domain-specific templates)
Advanced Query Safety (more sophisticated fan-trap detection)
Performance Optimization (caching, connection pooling)
Test Coverage (increase from current 70% pass rate)
Development Process
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Test with both PostgreSQL and Snowflake
Ensure all dependencies install correctly
Run code quality checks (
pytest,black,flake8)Submit Pull Request
Development Setup
# Install development dependencies
uv sync --dev
# Run tests
pytest
# Format code
black src/ tests/
# Run linting
flake8 src/ tests/
# Type checking
mypy src/Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
The AI that understands raw data: Schema over your tables and databases, as MCP tools.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceOrionBelt Analytics is an MCP server that analyzes relational database schemas and generates RDF/OWL ontologies with embedded SQL mappings. It provides relationship-aware Text-to-SQL with automatic fan-trap prevention, GraphRAG for intelligent schema discovery, and interactive charting -- all accessible through any MCP-compatible AI client.46 PyPI59Business Source 1.1
- AlicenseNot gradedqualityDmaintenanceEnables extraction and querying of database schema metadata from PostgreSQL, Snowflake, SQL Server, BigQuery, and Oracle databases, saving results locally for analysis.34 PyPIMIT
- FlicenseAqualityDmaintenanceEnables read-only exploration and querying of PostgreSQL or MySQL databases via MCP, with schema discovery, safe SQL validation, natural language to SQL conversion, and CSV export.112-
- AlicenseNot gradedqualityDmaintenanceMCP server providing read-only Snowflake metadata tools (schemas, tables, queries, lineage) for agentic data pipeline generation, enabling natural-language-to-pipeline workflows with dbt, Airflow, and Great Expectations.1MIT