Enables secure database operations including query execution, CRUD operations, schema inspection, and connection management for MySQL databases through parameterized statements with SQL injection prevention.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Bun Database MCP Servershow me the schema for the employees table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
๐ Bun Database MCP Server
A high-performance Model Context Protocol (MCP) server built with Bun and TypeScript, providing secure database operations for MySQL databases. This server enables AI assistants to safely interact with MySQL databases through a standardized protocol.
๐น Video Tutorials
Watch these comprehensive tutorials to understand MCP development:

โจ Features
๐ Database Connection Management - Connect, disconnect, and check connection status
๐ Safe Query Execution - Execute SELECT queries with parameterized statements
๐ CRUD Operations - Create, Read, Update, and Delete records securely
๐ Schema Inspection - Read database schema and table structures
๐ค MCP Prompts - Pre-built prompts for common database operations
๐ MCP Resources - Access database documentation and schema information
๐ก๏ธ SQL Injection Prevention - Built-in validation and sanitization
โก Built with Bun - Lightning-fast runtime and package management
๐ Environment-based Configuration - Secure credential management
๐ Prerequisites
Bun v1.0 or higher
MySQL 5.7+ or MySQL 8.0+
Node.js 18+ (for compatibility)
๐ ๏ธ Installation
Clone the repository:
Install dependencies:
Configure environment variables:
Edit .env with your database credentials:
Initialize the database with sample data:
The repository includes an simple_import_employees.sql file with sample employee data. Import it using one of these methods.
Option 1: Using mysql command-line client:
Option 2: From within MySQL client:
Then run:
Option 3: Using mysqldump (for backup/restore):
๐ Usage
Transport Options
The MCP server supports three different transport protocols:
1. STDIO Transport (Default)
Standard input/output communication for MCP clients like Claude Desktop:
2. SSE Transport (Server-Sent Events)
HTTP-based transport using Server-Sent Events for real-time streaming:
Endpoints:
GET http://localhost:3000/mcp- Establish SSE streamPOST http://localhost:3000/messages- Send JSON-RPC requests
Session Management: Via
sessionIdquery parameter
3. HTTP Transport (StreamableHTTP with OAuth)
Modern HTTP transport with OAuth authentication supporting both JSON and SSE responses:
MCP Endpoint:
GET/POST http://localhost:3000/mcpAuth Server:
http://localhost:3001(OAuth provider with demo flows)Session Management: Via
Mcp-Session-IdheaderAuthentication: Bearer token required in
AuthorizationheaderResponse Formats:
JSON:
Accept: application/json, text/event-streamSSE:
Accept: text/event-stream, application/json
Authentication Flow:
OAuth server runs on port 3001 with demo authentication flows
Supports both in-memory demo provider and Google OAuth
MCP server validates Bearer tokens for protected resources
Set
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETenvironment variables for Google OAuth
Starting the Server
Run with default STDIO transport:
Run with specific transport:
For development with auto-reload:
Available Tools
The server provides six powerful tools for database operations:
1. connection - Manage Database Connection
2. query - Execute SELECT Queries
3. create - Insert Records
4. update - Update Records
5. delete - Delete Records
6. readSchema - Inspect Database Schema
Available Prompts
The server provides pre-built prompts for common database operations:
1. query-employees - Natural Language Queries
Query the employees table using natural language instructions.
Arguments:
instructions- e.g., "count female employees", "show 10 recent hires"
2. insert-employee - Add New Employee
Insert a new employee with all related information (department, title, salary).
Arguments:
employee_info- Employee details in natural language
3. delete-employee - Remove Employee
Delete an employee and all related records from the database.
Arguments:
employee_identifier- Employee number or name
4. manage-departments - Department Operations
Insert a new department or delete an existing department.
Arguments:
instructions- e.g., "add Marketing department", "delete department d005"
Available Resources
The server exposes the following MCP resources:
bun-db-mcp://general-database - Database Schema Documentation
Type:
text/markdownDescription: Complete documentation of the employee database schema including:
Table structures and columns
Entity relationships
Key design patterns
Common query patterns
Mermaid ER diagram
๐งช Testing
Run the test suite:
Run specific test files:
Watch mode for development:
๐ง Configuration
MCP Client Configuration
STDIO Transport (Claude Desktop)
To use with Claude Desktop or other MCP clients, add to your configuration:
HTTP/SSE Transport (Web Clients)
For HTTP-based transports, use curl or web clients:
SSE Transport Example:
HTTP Transport with OAuth Example:
Environment Variables
Variable | Description | Default |
| MySQL host address |
|
| MySQL port |
|
| Database user |
|
| Database password | - |
| Database name |
|
| Google OAuth client ID (optional) | - |
| Google OAuth client secret (optional) | - |
๐๏ธ Project Structure
๐ Security Features
OAuth Authentication - Bearer token authentication for HTTP transport
Protected Resources - Access control for sensitive database operations
Parameterized Queries - All queries use prepared statements to prevent SQL injection
Input Validation - Table and column names are validated against strict patterns
Identifier Escaping - Database identifiers are properly escaped
SELECT-only Queries - Query tool restricted to SELECT statements only
Environment Variables - Sensitive credentials stored in environment files
CORS Protection - Configurable cross-origin resource sharing policies
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Fork the repository
Create your feature branch (
git checkout -b feature/AmazingFeature)Commit your changes (
git commit -m 'Add some AmazingFeature')Push to the branch (
git push origin feature/AmazingFeature)Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Built with Bun - The fast all-in-one JavaScript runtime
Uses MCP SDK for protocol implementation
Database connectivity via mysql2
๐ Performance
Thanks to Bun's optimized runtime:
๐ Fast Startup - Server starts in milliseconds
โก Low Memory - Efficient memory usage
๐ฅ High Throughput - Handle multiple database operations efficiently
๐ Troubleshooting
Common Issues
Connection Refused
Verify MySQL is running
Check host and port in
.envEnsure user has proper permissions
Authentication Failed
Verify credentials in
.envCheck MySQL user permissions
Ensure database exists
Module Not Found
Run
bun installto install dependenciesVerify Bun version with
bun --version
๐ Support
For issues and questions:
Open an issue on GitHub Issues
Check existing issues for solutions
Provide detailed error messages and steps to reproduce
Built with โค๏ธ using Bun and TypeScript