mcp-dbtools-0.1.1 is not a library.
MCP Database Tools
A Model Context Protocol (MCP) server that provides secure database access through MCP Server and other MCP-compatible clients.
๐ Features
- YAML Configuration: Load database configurations from
~/.mcp-dbtools/config.yml - Environment Variable Support: Use
${VAR_NAME}syntax for secure credential management - Multiple Server Support: Configure and switch between different database connections
- SQL Execution: Execute SQL queries safely through the MCP protocol
- Fallback Support: Automatic fallback to environment variables if YAML config fails
- Comment-Safe Parsing: Environment variables in YAML comments are ignored
๐ Prerequisites
- Rust 1.70 or later
- A supported SQL database
- MCP Server (for MCP integration)
๐ ๏ธ Installation
-
Clone the repository:
-
Build the project:
-
Create configuration directory:
โ๏ธ Configuration
YAML Configuration File
Create ~/.mcp-dbtools/config.yml:
# Configuration for MCP DB Tools
# Use ${VAR_NAME} to load sensitive values from environment variables.
servers:
# Local development database
test_db:
adapter: "postgres"
enabled: true
host: "localhost"
port: 5432
username: "postgres"
password: "postgres" # WARNING: Use env vars for production
dbname: "pocket_db"
read_only: false
# Production database
prod_db:
adapter: "mysql"
enabled: true
host: "prod.example.com"
port: 3306
username: "produser"
password: "${PROD_DB_PASSWORD}"
dbname: "production_db"
read_only: true
Environment Variables
Set required environment variables:
๐โโ๏ธ Usage
Command Line
# Run with specific server configuration
# Run with default server (test_db)
# Use release build
MCP Server Integration
Add to your MCP Server settings file:
macOS: ~/Library/Application Support/MCP Server/mcp_server_config.json
Windows: %APPDATA%\MCP Server\mcp_server_config.json
Or with pre-built binary:
๐งช Testing
Test Database Connection
# Test database schema and data
# Explore database content
Test MCP Server
# Test server with YAML config
๐ง Configuration Options
| Field | Type | Required | Description |
|---|---|---|---|
adapter |
string | Yes | Database type (e.g., "postgres", "mysql") |
enabled |
boolean | No | Enable/disable this server config |
host |
string | Yes | Database hostname |
port |
number | Yes | Database port |
username |
string | Yes | Database username |
password |
string | No | Database password (use env vars!) |
dbname |
string | Yes | Database name |
read_only |
boolean | No | Restrict to read-only operations |
๐ Security Best Practices
- Never hardcode sensitive data in YAML files
- Use environment variables for passwords:
password: "${DB_PASSWORD}" - Set appropriate file permissions on config files:
- Use read-only mode for production databases when possible
๐ Available SQL Operations
Through MCP Server, you can:
- Query tables: "Show me all records from the users table"
- Describe schema: "What columns does the products table have?"
- Run aggregations: "Calculate total sales by month"
- Join tables: "Join users and orders tables"
- Filter data: "Find all orders from last week"
๐ Troubleshooting
Common Issues
-
"Failed to load YAML config"
- Check if
~/.mcp-dbtools/config.ymlexists - Verify YAML syntax is correct
- Ensure environment variables are set
- Check if
-
"Environment variable not found"
- Set required environment variables before running
- Check variable names match exactly (case-sensitive)
-
"Failed to connect to database"
- Verify database is running
- Check host, port, username, and password
- Ensure database exists
-
"Server 'xyz' not found in config"
- Check server name spelling in YAML file
- Verify the server section exists under
servers:
Debug Mode
Run with verbose output:
RUST_LOG=debug
๐๏ธ Development
Project Structure
mcp-dbtools/
โโโ src/
โ โโโ main.rs # MCP server entry point
โ โโโ config.rs # Configuration management
โ โโโ test_db.rs # Database testing utility
โ โโโ explore_data.rs # Data exploration utility
โโโ mcp-rust-sdk/ # MCP SDK dependency
โโโ ~/.mcp-dbtools/ # Configuration directory
โ โโโ config.yml # Database configurations
โโโ README.md
Building
# Development build
# Release build
# Run tests
# Check code quality
๐ License
[Add your license information here]
๐ค Contributing
[Add contribution guidelines here]
๐ Support
[Add support contact information here]