Token Efficiency
Progressive Disclosure with search_objects
Thesearch_objects tool offers three detail levels to minimize token usage:
names instead of full can reduce response size by 80-90% for large schemas.
Limit Result Sets
Always use thelimit parameter to control result size:
Multi-Database Organization
Named Sources in TOML
Organize databases with descriptive IDs and descriptions:Consistent source_id Usage
When tools are registered per-source, use the source-specific tool names:Lazy Connections for Remote Databases
Uselazy = true for databases that aren’t always needed:
- Faster startup times
- Reduced connection overhead for rarely-used databases
- Delayed SSH tunnel establishment until needed
Read-Only Mode
When to Enable Read-Only
Configure per-tool readonly mode for:- Production databases - Prevent accidental modifications
- Shared staging environments - Protect shared resources
- Analytics/reporting databases - Enforce query-only access
- Exploratory data analysis - Safe browsing without risk
Allowed Read-Only Operations
Fromsrc/utils/allowed-keywords.ts:9-15:
- PostgreSQL:
SELECT,WITH,EXPLAIN,ANALYZE,SHOW - MySQL/MariaDB:
SELECT,WITH,EXPLAIN,ANALYZE,SHOW,DESCRIBE,DESC - SQLite:
SELECT,WITH,EXPLAIN,ANALYZE,PRAGMA - SQL Server:
SELECT,WITH,EXPLAIN,SHOWPLAN
Query Limiting
Setting Appropriate max_rows Values
- Production queries: 100-1,000 rows (quick results)
- Analytics/exploration: 1,000-10,000 rows (detailed analysis)
- Reporting: 10,000+ rows (full datasets)
- Testing: 10-100 rows (fast iteration)
How Limits Are Applied
Fromsrc/utils/sql-row-limiter.ts:126-144:
- Existing
LIMITclauses are respected (uses minimum of existing and configured) - Parameterized
LIMITclauses trigger subquery wrapping for safety - Only applies to
SELECTqueries
Custom Tools for Common Queries
Encapsulating Business Logic
Define reusable tools for frequently-used queries:- Consistent query patterns across team
- Type-safe parameters
- Built-in documentation via descriptions
- Centralized query optimization
SSH Tunnel Best Practices
When to Use SSH Tunnels
- Databases behind firewalls - Production databases in private networks
- Bastion host architectures - Security requirement for database access
- Multi-hop access - Jump through multiple security layers
- Encrypted connections - Additional security layer for sensitive data
Key Management
Prefer key-based authentication over passwords:SSH Keepalive Configuration
Prevent idle disconnections for long-running operations:interval = 0).
ProxyJump for Multi-Hop Connections
Connect through multiple jump hosts:src/utils/ssh-tunnel.ts:70-138, connections are established sequentially through each jump host.
Connection Pooling and Timeouts
Connection Timeouts
Set appropriate connection timeouts for remote databases:- Local databases: 5-10 seconds
- Remote databases: 20-30 seconds
- SSH tunnel connections: 30-60 seconds
Query Timeouts
Prevent runaway queries:Configuration Best Practices
TOML Over Environment Variables
Use TOML for multi-database setups:Credential Management
Never commit secrets:- Keep
dbhub.toml.examplein version control - Copy to
dbhub.tomllocally and add credentials - Use cloud secret managers for production
Testing with Workbench
Test Queries Before Using in MCP Client
The built-in workbench (--transport http --port 8080) allows:
- Query validation - Test SQL syntax before sending to Claude
- Performance testing - Measure query execution time
- Result inspection - Verify output format
- Tool testing - Execute custom tools interactively
Request Tracing
Workbench includes request traces for debugging:- View all executed queries
- See execution times
- Inspect parameters and results
- Debug source routing in multi-database setups
Schema Search Path (PostgreSQL)
Custom Schema Configuration
When working with non-public schemas:src/types/config.ts:54:
- First schema in the list becomes the default for schema discovery
- Subsequent schemas are included in the search path
- Affects
search_objectsresults and unqualified table references
Performance Tips
1. Use Specific Filters
2. Leverage Detail Levels
3. Set Realistic Limits
Security Checklist
- Use
readonly = truefor production databases - Set appropriate
max_rowslimits - Use SSH tunnels for remote database access
- Prefer key-based SSH authentication
- Enable SSL/TLS (
sslmode=require) for network databases - Never commit
.envor credential-containing TOML files - Use
lazy = truefor infrequently-accessed databases - Set connection and query timeouts
- Test queries in workbench before production use
- Document custom tools with clear descriptions