ultrafast-mcp-database

techgopal/ultrafast-mcp-database

3.2

If you are the rightful owner of ultrafast-mcp-database and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

UltraFast MCP Database is a high-performance, multi-database Model Context Protocol server and client implementation in Rust, designed for seamless integration with various databases through a unified interface.

Tools
  1. execute_query

    Execute SQL/NoSQL queries with parameters.

  2. execute_query_named

    Execute queries with named parameters.

  3. begin_transaction

    Start database transactions.

  4. commit_transaction

    Commit transactions.

  5. rollback_transaction

    Rollback transactions.

  6. get_schema

    Retrieve database schema information.

  7. get_table_info

    Get specific table/collection details.

  8. ping

    Test database connectivity.

  9. get_stats

    Retrieve database statistics.

UltraFast MCP Database

Rust License: MIT MCP Version

A high-performance, multi-database MCP (Model Context Protocol) server and client implementation in Rust. Connect to any database through a unified interface with blazing-fast performance, enterprise-grade security, and production-ready reliability.

šŸš€ Features

Multi-Database Support

  • SQL Databases: PostgreSQL, MySQL, SQLite
  • NoSQL Databases: MongoDB, Redis, SurrealDB
  • Unified Interface: Same API across all database types

Performance & Reliability

  • High Performance: Built with Rust and Tokio for maximum concurrency
  • Connection Pooling: Efficient database connection management
  • Query Caching: Optional intelligent query caching
  • Prepared Statements: SQL injection protection with performance benefits

Security First

  • SQL Injection Protection: Built-in query validation and sanitization
  • Input Validation: Comprehensive parameter validation
  • Rate Limiting: Configurable request throttling
  • SSL/TLS Support: Encrypted connections for SQL databases
  • Authentication: Flexible authentication mechanisms

Developer Experience

  • Simple Configuration: TOML-based with sensible defaults
  • Environment Variables: Easy deployment configuration
  • Interactive CLI: Built-in client with interactive mode
  • Comprehensive Logging: Structured logging with configurable levels
  • Health Checks: Built-in monitoring and diagnostics

Production Ready

  • MCP 2025-06-18 Compliant: Latest protocol specification
  • Transport Options: STDIO and HTTP with streaming support
  • Transaction Support: Full ACID transaction capabilities
  • Monitoring: Built-in metrics and performance tracking
  • Graceful Shutdown: Proper resource cleanup

šŸ“¦ Installation

Prerequisites

  • Rust 1.75+ and Cargo
  • Database drivers (optional, feature-based)

Quick Install

# Clone the repository
git clone https://github.com/techgopal/ultrafast-mcp-database.git
cd ultrafast-mcp-database

# Build with all database support
cargo build --release --features all-databases

# Or build with specific database support
cargo build --release --features postgres,mysql,sqlite

Binary Installation

The build creates three binaries in target/release/:

  • db-server - MCP database server
  • db-client - Database client CLI
  • mcp-config - Configuration management tool

⚔ Quick Start

1. Generate Configuration

# Generate a simple SQLite configuration
./target/release/mcp-config generate sqlite --output config.toml

# Or generate PostgreSQL configuration
./target/release/mcp-config generate postgres --output config.toml

2. Start the Server

# Start with STDIO transport (for MCP integration)
./target/release/db-server --config config.toml

# Start with HTTP transport
./target/release/db-server --config config.toml --transport http --port 8080

3. Use the Client

# Execute a query
./target/release/db-client query "SELECT * FROM users LIMIT 10"

# Interactive mode
./target/release/db-client interactive

# Get database schema
./target/release/db-client schema

āš™ļø Configuration

Simple Configuration (Recommended)

# config.toml
database_type = "postgres"
url = "postgresql://user:password@localhost:5432/mydb"
pool_size = 20
log_level = "info"
transport = "http"
port = 8080

Environment Variables

export MCP_DB_TYPE=postgres
export MCP_DB_URL=postgresql://user:password@localhost:5432/mydb
export MCP_POOL_SIZE=20
export MCP_LOG_LEVEL=info

Database-Specific Examples

PostgreSQL
database_type = "postgres"
url = "postgresql://user:password@localhost:5432/mydb"
pool_size = 20
enable_ssl = true
MySQL
database_type = "mysql"
url = "mysql://user:password@localhost:3306/mydb"
pool_size = 15
enable_ssl = true
SQLite
database_type = "sqlite"
url = "sqlite:./data/database.db"
pool_size = 5
MongoDB
database_type = "mongodb"
url = "mongodb://localhost:27017/mydb"
pool_size = 10
Redis
database_type = "redis"
url = "redis://localhost:6379"
pool_size = 8
SurrealDB
database_type = "surrealdb"
url = "surrealdb://localhost:8000/namespace/database"
pool_size = 10

šŸ› ļø Usage

Server Commands

# Basic server start
./target/release/db-server --config config.toml

# With command line overrides
./target/release/db-server \
  --database-type postgres \
  --database-url "postgresql://user:pass@localhost:5432/db" \
  --transport http \
  --port 8080

# Validate configuration
./target/release/db-server validate config.toml

# Test database connection
./target/release/db-server test-connection --url "postgresql://..." --database-type postgres

Client Commands

# Execute SQL query
./target/release/db-client query "SELECT * FROM users WHERE active = true"

# Query with parameters
./target/release/db-client query "SELECT * FROM users WHERE age > ?" --params '[25]'

# Named parameters
./target/release/db-client named-query \
  "SELECT * FROM users WHERE name = :name AND age > :min_age" \
  --params '{"name": "John", "min_age": 18}'

# Transaction management
./target/release/db-client transaction begin
./target/release/db-client transaction commit --tx-id <transaction-id>

# Database operations
./target/release/db-client schema
./target/release/db-client table users
./target/release/db-client ping
./target/release/db-client stats

Interactive Mode

./target/release/db-client interactive

Interactive session example:

> query SELECT COUNT(*) FROM users
āœ… Query executed successfully. Affected rows: 0, Execution time: 2ms
Results: [{"count": 150}]

> schema
āœ… Database schema retrieved successfully
Database: mydb (PostgreSQL)
Tables: users, orders, products

> table users
āœ… Table information retrieved successfully
Table: users
Columns: id, name, email, created_at
Row count: 150

> ping
āœ… Database connection successful

šŸ”§ Advanced Configuration

Full Configuration

name = "ultrafast-mcp-database"
version = "0.1.0"
description = "High-performance database MCP server"
transport = "http"
port = 8080
host = "0.0.0.0"

[database]
database_type = "postgres"
url = "postgresql://user:password@localhost:5432/mydb"

[database.pool]
max_connections = 20
min_connections = 5
max_lifetime_seconds = 3600
idle_timeout_seconds = 600
acquire_timeout_seconds = 30

[database.limits]
max_execution_time_seconds = 60
max_rows = 50000
max_query_length = 10000000
max_concurrent_queries = 20

[database.timeouts]
connection_timeout_seconds = 10
query_timeout_seconds = 60
transaction_timeout_seconds = 600

[database.ssl]
enabled = true
mode = "prefer"
verify_server_cert = true

[security]
enable_auth = false
enable_query_validation = true
enable_sql_injection_protection = true
allowed_operations = ["SELECT", "INSERT", "UPDATE", "DELETE"]
forbidden_keywords = ["DROP", "TRUNCATE", "ALTER", "CREATE"]

[logging]
level = "info"
log_queries = false
log_slow_queries = true
slow_query_threshold_ms = 1000
json_format = false

[performance]
enable_query_cache = true
query_cache_size = 1000
query_cache_ttl_seconds = 300
enable_connection_pooling = true
enable_prepared_statements = true
max_batch_size = 1000

Security Configuration

[security]
enable_auth = true
enable_authz = true
enable_query_validation = true
enable_sql_injection_protection = true
allowed_operations = ["SELECT", "INSERT", "UPDATE", "DELETE"]
forbidden_keywords = ["DROP", "TRUNCATE", "ALTER", "CREATE", "EXEC"]

[security.rate_limiting]
enabled = true
requests_per_minute = 1000
burst_limit = 100

šŸ”Œ MCP Integration

Tool Interface

The server exposes the following MCP tools:

  • execute_query - Execute SQL/NoSQL queries with parameters
  • execute_query_named - Execute queries with named parameters
  • begin_transaction - Start database transactions
  • commit_transaction - Commit transactions
  • rollback_transaction - Rollback transactions
  • get_schema - Retrieve database schema information
  • get_table_info - Get specific table/collection details
  • ping - Test database connectivity
  • get_stats - Retrieve database statistics

Example MCP Usage

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "execute_query",
    "arguments": {
      "query": "SELECT * FROM users WHERE active = ?",
      "parameters": [true]
    }
  }
}

šŸ—ļø Development

Building with Features

# Build with specific database support
cargo build --features postgres,mysql,sqlite

# Build with all databases
cargo build --features all-databases

# Build with connection pooling
cargo build --features postgres,pooling

# Development build with all features
cargo build --features all-databases,pooling --debug

Running Tests

# Run all tests
cargo test

# Run with specific database
cargo test --features postgres

# Run integration tests
cargo test --test integration_tests

Code Quality

# Format code
cargo fmt

# Lint code
cargo clippy

# Check for security issues
cargo audit

šŸ“Š Performance

Benchmarks

  • Query Throughput: 10,000+ queries/second (PostgreSQL)
  • Connection Pool: 1000+ concurrent connections
  • Memory Usage: <50MB base memory footprint
  • Startup Time: <100ms cold start

Optimization Tips

  1. Use Connection Pooling: Configure appropriate pool sizes
  2. Enable Query Caching: For read-heavy workloads
  3. Use Prepared Statements: For repeated queries
  4. Configure Timeouts: Based on your workload
  5. Monitor Performance: Use built-in metrics

šŸ” Monitoring & Debugging

Logging

[logging]
level = "debug"
log_queries = true
log_slow_queries = true
slow_query_threshold_ms = 100
json_format = true

Health Checks

# Check server health
curl http://localhost:8080/health

# Get server statistics
./target/release/db-client stats

# Test database connectivity
./target/release/db-client ping

Metrics

The server provides built-in metrics:

  • Request count and latency
  • Database connection pool status
  • Query execution statistics
  • Error rates and types
  • Memory and CPU usage

šŸš€ Deployment

Docker

FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build --release --features all-databases

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/db-server /usr/local/bin/
COPY --from=builder /app/target/release/db-client /usr/local/bin/
COPY --from=builder /app/target/release/mcp-config /usr/local/bin/

EXPOSE 8080
CMD ["db-server", "--config", "/app/config.toml"]

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ultrafast-mcp-database
spec:
  replicas: 3
  selector:
    matchLabels:
      app: ultrafast-mcp-database
  template:
    metadata:
      labels:
        app: ultrafast-mcp-database
    spec:
      containers:
      - name: database-server
        image: ultrafast-mcp-database:latest
        ports:
        - containerPort: 8080
        env:
        - name: MCP_DB_TYPE
          value: "postgres"
        - name: MCP_DB_URL
          valueFrom:
            secretKeyRef:
              name: database-secret
              key: url

šŸ¤ Contributing

We welcome contributions! Please see our for details.

Development Setup

# Clone the repository
git clone https://github.com/techgopal/ultrafast-mcp-database.git
cd ultrafast-mcp-database

# Install development dependencies
cargo install cargo-watch
cargo install cargo-audit

# Run development server
cargo watch -x run --bin db-server -- --config examples/simple-config-sqlite.toml

šŸ“„ License

This project is licensed under the MIT License - see the file for details.

šŸ™ Acknowledgments

  • Built with UltraFast MCP
  • Database drivers from the Rust ecosystem
  • MCP specification from the Model Context Protocol community

šŸ“ž Support


Made with ā¤ļø in Rust

ultrafast-mcp-database