dbhub.toml configuration. They appear as first-class MCP tools alongside execute_sql and search_objects, making common queries easily accessible to AI agents.
Why Use Custom Tools?
Custom tools provide several benefits:- Reusability - Define once, use everywhere
- Abstraction - Hide complex SQL behind simple tool names
- Parameterization - Safe, type-checked parameter substitution
- Discoverability - Tools appear in MCP client tool lists with descriptions
- Team standardization - Share common queries across team members
- Business logic encapsulation - Encode domain knowledge in tool definitions
Configuration Syntax
Custom tools are defined in the[[tools]] section of dbhub.toml:
Parameter Types
Custom tools support the following parameter types:Text values. Use for names, IDs, search terms, etc.
Whole numbers. Use for IDs, counts, limits, etc.
Decimal numbers. Use for prices, percentages, etc.
True/false values. Use for flags, toggles, etc.
Lists of values. Use for bulk operations.
Parameter Placeholders
SQL parameter placeholders vary by database type:- PostgreSQL:
$1,$2,$3, etc. - MySQL/MariaDB:
?,?,?, etc. (positional) - SQL Server:
@p1,@p2,@p3, etc. - SQLite:
?,?,?, etc. (positional)
[[tools.parameters]] array.
Examples
Simple Query (No Parameters)
List all current department managers:Query with Required Parameter
Get user details by email:Query with Required + Optional Parameters
Search employees by salary range:Query with Enum Parameter
Filter products by category:Write Operation (DELETE)
Delete employee salary records:Write Operation (UPDATE)
Update employee department:Complex Aggregation Report
Generate monthly sales report:Response Format
Custom tools return the same format asexecute_sql:
Error Handling
Parameter Validation Errors
Occurs when required parameters are missing or have invalid types:Readonly Violations
Occurs when attempting write operations withreadonly = true:
SQL Execution Errors
Occurs when the database returns an error:Configuration Validation
DBHub validates your custom tool configuration on startup:- Unique names - Tool names must be unique per source
- Valid sources - Referenced sources must exist
- Required fields - Custom tools must have
name,description,source, andstatement - Parameter types - Parameter types must be valid (string/integer/float/boolean/array)
- No builtin conflicts - Custom tools cannot use reserved names (
execute_sql,search_objects)
Implementation Details
- Handler creation:
src/tools/custom-tool-handler.ts - Schema building:
buildZodSchemaFromParameters()converts TOML config to Zod schemas - Parameter mapping:
src/utils/parameter-mapper.tsmaps named arguments to positional parameters - Config loading:
src/config/toml-loader.tsvalidates and loads tool definitions - Tool registration: Tools are registered alongside builtin tools during server startup
Best Practices
- Use descriptive names - Tool names should clearly indicate what they do
- Write clear descriptions - AI agents use descriptions to select appropriate tools
- Set readonly = true - For queries to prevent accidental data modification
- Limit result sets - Use
max_rowsto prevent overwhelming responses - Document parameters - Clear descriptions help AI agents provide correct values
- Use enum constraints -
allowed_valuesprevents invalid parameter values - Handle nulls explicitly - For optional parameters, use
IS NULLchecks in SQL - Test in development - Verify tool behavior before deploying to production
- Version your config - Keep
dbhub.tomlin version control - Share across teams - Custom tools become team knowledge assets
Common Use Cases
Business Intelligence
- Monthly/quarterly reports
- Sales analytics
- User engagement metrics
- Performance dashboards
Data Management
- Bulk updates
- Data cleanup operations
- Audit trail queries
- Archive old records
Application Operations
- User lookup by various fields
- Feature flag queries
- Configuration retrieval
- Health check queries
Development Workflows
- Test data generation
- Schema verification
- Data migration validation
- Integration test helpers