Enables SQL query execution on MySQL databases with comprehensive security features, allowing SELECT queries with parameterized statements and query timeout protection
Provides SQL query execution capabilities for SQLite databases, supporting both file-based and in-memory databases with secure SELECT query operations
tbls MCP Server
⚠️ EXPERIMENTAL SOFTWARE This application is experimental software with insufficient testing coverage (~66% currently). It is not suitable for production use. We recommend experimental use only for development and testing purposes. If you plan to use it in production, please conduct thorough testing beforehand.
A Model Context Protocol (MCP) server that provides access to database schema information generated by tbls and enables SQL query execution on MySQL and SQLite databases.
Features
- JSON Schema Support: Primary support for tbls-generated JSON schema files with optimal performance
- JSON-Only Support: Uses JSON schema format from tbls for optimal performance
- Multiple Resource Types: Access schemas, tables, and index information through MCP resources
- SQL Query Execution: Execute SELECT queries on MySQL and SQLite databases with comprehensive security
- Type Safety: Full TypeScript implementation with zod validation
- Error Handling: Robust error handling using neverthrow Result types
- MCP Compatible: Works with Claude Desktop, Cline, and other MCP clients
- Flexible Configuration: Support for both CLI arguments and configuration files
MCP Server Configuration
To use this server with MCP clients, add the following configuration:
Claude Desktop
Add to your Claude Desktop configuration file (claude_desktop_config.json
):
Cline (VS Code Extension)
Add to your Cline MCP settings:
Configuration File Method
Alternatively, create a .tbls-mcp-server.json
configuration file and use:
Installation
Prerequisites
- Node.js 18 or higher
- tbls installed and configured
- Database access (MySQL or SQLite) - optional for SQL query features
Via npx (Recommended for MCP)
Clone and Run Locally
Local Development Installation
Usage
Basic Usage (Schema Information Only)
With Database Connection (Full Features)
Using Configuration File
JSON Schema Sample
Example of a tbls-generated JSON schema file structure:
Examples
Setting up with tbls
First, generate schema documentation using tbls:
Directory Structure
Expected tbls output structure:
Note:
- Use
tbls doc --format=json
to generate the JSON schema file - The default output file is
schema.json
in the specified directory - The
--schema-source
option can point to either a JSON file or directory containing JSON files
Using with Claude Desktop
- Configure Claude Desktop:
- Restart Claude Desktop and the tbls server will be available
- Query your database schema:
- "Show me all tables in the database"
- "What columns does the users table have?"
- "Show me the relationship between users and posts"
- "Execute: SELECT COUNT(*) FROM users WHERE active = true"
Common SQL Queries
Schema exploration:
Data analysis:
MCP Resources
The server exposes tbls-generated schema information through the following MCP resources:
URI Pattern | Description | Discovery Required |
---|---|---|
schema://list | Complete list of all available database schemas with metadata including schema names, table counts, and version information. URI format: schema://list | No |
schema://{schemaName}/tables | Comprehensive list of all tables within the {schemaName} schema, including table metadata, row counts, and basic structure information. URI format: schema://[schema_name]/tables (example: schema://default/tables, schema://public/tables) | Yes |
table://{schemaName}/{tableName} | Complete detailed information about the {tableName} table including column definitions with data types, constraints, indexes, foreign key relationships, and table statistics. URI format: table://[schema_name]/[table_name] (example: table://default/users, table://public/orders) | Yes |
table://{schemaName}/{tableName}/indexes | Detailed index information for the {tableName} table including index names, types (primary, unique, regular), column compositions, and performance statistics. URI format: table://[schema_name]/[table_name]/indexes (example: table://default/users/indexes, table://public/orders/indexes) | Yes |
MCP Tools
The server provides SQL query execution capabilities when a database connection is configured:
SQL Query Tool (execute-sql
)
Purpose: Execute SELECT queries on connected MySQL or SQLite databases with comprehensive security features.
Security Features:
- ✅ SELECT queries only - INSERT, UPDATE, DELETE, DROP, etc. are blocked
- ✅ Parameterized queries prevent SQL injection attacks
- ✅ Query timeout protection prevents long-running queries
- ✅ Multiple statement prevention blocks compound SQL injection
- ✅ Input sanitization removes dangerous patterns
Supported Databases:
- MySQL (via connection string or individual parameters)
- SQLite (file path or : database)
Parameters:
query
(required): SQL SELECT query to executeparameters
(optional): Array of parameters for prepared statementstimeout
(optional): Query timeout in milliseconds (1000-300000, default: 30000)
Usage Examples:
Response Format:
Configuration
Command Line Arguments
--schema-source <path>
: Path to tbls JSON schema file or directory (required)--database-url <url>
: Database connection string (optional)--log-level <level>
: Set logging level (debug, info, warn, error, default: info)--config <path>
: Path to configuration file--help
: Show help information--version
: Show version information
Environment Variables
TBLS_SCHEMA_SOURCE
: Path to tbls JSON schema file or directoryDATABASE_URL
: Database connection string (optional)LOG_LEVEL
: Logging level (debug, info, warn, error)
Configuration File
Create a .tbls-mcp-server.json
file in your project root:
Database Configuration Options
MySQL:
SQLite:
Complete Configuration Examples
Production Setup with JSON Schema:
Development Setup with Local Files:
Troubleshooting
Common Issues
Server fails to start:
- Verify Node.js version (18+ required)
- Check that the schema source file exists or directory contains tbls-generated files
- For JSON: Ensure the JSON file is valid and contains proper schema structure
- For directories: Ensure the directory contains proper .json files
- Ensure database connection string is valid (if using database features)
No resources available:
- Confirm tbls has generated JSON schema file in the specified location
- Check file permissions on the schema file/directory
- Enable debug logging:
--log-level debug
Database connection issues:
- Test database connectivity outside of the MCP server
- Verify connection string format
- Check firewall and network access
- Ensure database user has appropriate permissions (SELECT at minimum)
SQL queries fail:
- Only SELECT statements are allowed
- Use parameterized queries with
?
placeholders - Check query timeout settings
- Review query syntax for your database type
Claude Desktop integration issues:
- Restart Claude Desktop after configuration changes
- Check configuration file syntax (valid JSON)
- Verify file paths are absolute and accessible
- Check Claude Desktop logs for error messages
Debug Mode
Enable debug logging to troubleshoot issues:
This will output detailed information about:
- Configuration loading and schema source resolution
- Resource discovery (JSON file vs directory detection)
- Database connections
- SQL query execution
- Error details and diagnostics
Support
For issues and questions:
- Check the GitHub Issues
- Review tbls documentation
- Consult MCP specification
Development
Prerequisites
- Node.js 18+
- npm or yarn
Setup
Development Commands
Testing
The project uses Jest for testing with a focus on Test-Driven Development (TDD):
Architecture
The server is built using:
- TypeScript: Type-safe implementation
- @modelcontextprotocol/sdk: Official MCP SDK
- neverthrow: Result types for error handling
- zod: Schema validation
- mysql2: MySQL database connectivity
- sqlite3: SQLite database connectivity
Security
- Only SELECT statements are permitted for SQL execution
- Input validation using zod schemas
- SQL injection prevention through parameterized queries
- Connection string validation and sanitization
Contributing
- Fork the repository
- Create a feature branch
- Write tests for your changes
- Implement your changes
- Ensure all tests pass
- Submit a pull request
License
ISC License
Related Projects
- tbls - Schema documentation tool
- Model Context Protocol - Protocol specification
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Provides access to database schema information generated by tbls and enables secure SQL query execution on MySQL and SQLite databases. Allows users to explore database structures, table relationships, and execute SELECT queries through natural language interactions.