Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
eslint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- name: Clear npm cache
run: npm cache clean --force

- name: Install dependencies
run: npm install

- name: Run ESLint
run: npm run lint:eslint

markdownlint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- name: Clear npm cache
run: npm cache clean --force

- name: Install dependencies
run: npm install

- name: Run markdownlint
run: npm run lint:markdown
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules/
.env
3 changes: 3 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MD013: false
MD024: false
MD020: false
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## Planned Features

### Planned Features
- Query Features
- Prepared statement support
- Query parameter validation
Expand Down Expand Up @@ -37,32 +37,38 @@
## [1.0.14] - 2024-07-01

### Added

- Added better support for test environments with automatic database selection
- Implemented comprehensive debug logging for database configuration in test mode
- Added fail-safe process termination handling for test environments

### Changed

- Improved test environment detection with support for Vitest test runner
- Enhanced MySQL connection configuration to use consistent defaults across environments
- Updated error handling in database setup scripts to be more resilient

### Fixed

- Fixed "No database selected" error in integration tests by ensuring database name is always set
- Fixed authentication issues in test environments by providing consistent default credentials
- Prevented premature test termination by implementing conditional process.exit handling
- Improved error handling in test database setup to continue tests even when setup encounters issues

### Security

- Made authentication more consistent across development and test environments
- Added safeguards to prevent exposing actual password values in debug logs

### Documentation

- Added detailed inline comments for test-specific configurations
- Improved error messages to provide better debugging information

## [1.0.13] - 2024-05-26

### Added

- Complete write operations support through Smithery configuration
- Added environment variables for database write operations (`ALLOW_INSERT_OPERATION`, `ALLOW_UPDATE_OPERATION`, `ALLOW_DELETE_OPERATION`)
- New configuration options in Smithery schema for controlling write permissions
Expand All @@ -71,6 +77,7 @@
- Enhanced error handling for unauthorized write operations

### Changed

- Updated Smithery configuration to include write operation settings
- Improved Smithery integration with clear security defaults
- Enhanced documentation with detailed configuration examples
Expand All @@ -79,18 +86,21 @@
- Improved transaction handling for write operations

### Fixed

- Fixed error handling for database connection failures
- Improved error messages for unauthorized operations
- Better handling of MySQL 8.0+ authentication methods
- Fixed SSL/TLS configuration options in Smithery

### Security

- All write operations (INSERT, UPDATE, DELETE) disabled by default
- Added clear documentation about security implications of enabling write operations
- Improved transaction isolation for write operations
- Enhanced error reporting that doesn't expose sensitive information

### Documentation

- Updated README with comprehensive Smithery configuration instructions
- Added detailed examples for enabling specific write operations
- Improved troubleshooting section with common issues and solutions
Expand All @@ -100,38 +110,46 @@
## [1.0.10] - 2024-03-13

### Changed

- Version bump to fix npm publishing issue
- Updated installation instructions in README to reference specific version

## [1.0.9] - 2024-03-13

### Added

- GitHub Actions CI workflow for automated lint, build, and test with MySQL service

### Changed

- Removed `@types/mysql2` dependency and related type references
- Updated test files to use `any` type instead of mysql2 specific types
- Fixed integration tests to properly handle MySQL connection and queries

### Fixed

- Fixed GitHub Actions workflow to install pnpm before using it for caching
- Fixed failing unit tests by removing problematic executeReadOnlyQuery tests

## [1.0.8] - 2024-03-12

### Changed

- Upgraded from `mysql` to `mysql2` package (^3.13.0) for better MySQL 8.0+ compatibility
- Refactored database connection code to use mysql2's Promise-based API
- Added support for MySQL 8.0+ authentication with `caching_sha2_password` plugin

### Removed

- Removed deprecated `mysql` package dependency
- Removed unused `@types/mysql2` devDependency

### Fixed

- Fixed authentication issues with MySQL 8.0+ servers
- Improved connection handling with Promise-based API
- Enhanced error handling for database operations

## [1.0.7] - Previous version
- Initial release with basic MySQL functionality

- Initial release with basic MySQL functionality
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
# MIT License

Copyright (c) 2024 Ben Borla

Expand Down
23 changes: 20 additions & 3 deletions PROJECT_SETUP_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This guide explains how to set up database connections for projects using Claude Code with MCP servers, SSH tunnels, and automatic hooks.

## Table of Contents

- [Overview](#overview)
- [Prerequisites](#prerequisites)
- [Step-by-Step Setup](#step-by-step-setup)
Expand All @@ -14,6 +15,7 @@ This guide explains how to set up database connections for projects using Claude
## Overview

Each project requires three main components for database access through Claude Code:

1. **SSH Tunnel Scripts** - Establish secure connection to remote database
2. **MCP Configuration** - Configure database access through MCP server
3. **Hooks** - Automatically start/stop tunnels with Claude
Expand Down Expand Up @@ -47,6 +49,7 @@ Each project requires three main components for database access through Claude C
Create two scripts in your project directory:

#### `start-tunnel-[project].sh`

```bash
#!/bin/bash

Expand Down Expand Up @@ -85,6 +88,7 @@ fi
```

#### `stop-tunnel-[project].sh`

```bash
#!/bin/bash

Expand All @@ -104,6 +108,7 @@ fi
```

Make scripts executable:

```bash
chmod +x start-tunnel-*.sh stop-tunnel-*.sh
```
Expand Down Expand Up @@ -172,7 +177,8 @@ Choose a unique local port for each project to avoid conflicts:
## File Structure

Your project should have this structure:
```

```bash
/path/to/your/project/
├── .mcp.json # MCP configuration
├── start-tunnel-[project].sh # Start SSH tunnel script
Expand Down Expand Up @@ -246,6 +252,7 @@ SSH_USER="myuser"
## Testing Your Setup

### 1. Test SSH Tunnel

```bash
# Start tunnel manually
./start-tunnel-[project].sh
Expand All @@ -258,12 +265,14 @@ lsof -i :33XX
```

### 2. Test Database Connection

```bash
# Test connection through tunnel
mysql -h 127.0.0.1 -P 33XX -u db_user -p"password" -D database_name -e "SELECT 'Connection OK' as status;"
```

### 3. Test Claude Integration

```bash
# Navigate to project
cd /path/to/your/project
Expand All @@ -279,7 +288,9 @@ claude
```

### 4. Test MCP Server Operations

Once in Claude, test database operations:

```sql
# Through MCP server
CREATE TABLE test_table (
Expand All @@ -299,26 +310,31 @@ DROP TABLE test_table;
### Common Issues and Solutions

#### 1. SSH Tunnel Fails to Start

- **Check SSH key**: Ensure `~/.ssh/id_rsa` exists and has correct permissions (600)
- **Test SSH manually**: `ssh -p 1022 [email protected]`
- **Check port availability**: `lsof -i :33XX`

#### 2. Database Connection Fails

- **Verify tunnel is running**: `lsof -i :33XX`
- **Check credentials**: Test with mysql client directly
- **Verify database exists**: `SHOW DATABASES;`

#### 3. MCP Server Fails to Connect

- **Check MCP server is built**: `ls /Users/dimitarklaturov/Dropbox/github/mcp-server-mysql/dist/`
- **Verify Node.js version**: `node --version` (should be 18+ or 20+)
- **Check logs**: `claude --debug`

#### 4. Hooks Not Working

- **Check script permissions**: `ls -la *.sh` (should be executable)
- **Verify script paths**: Use relative paths (`./script.sh`) in .mcp.json
- **Test scripts manually**: Run start/stop scripts directly

#### 5. Port Conflicts

- **Kill existing process**: `kill $(lsof -ti:33XX)`
- **Use different port**: Update both scripts and .mcp.json

Expand Down Expand Up @@ -373,6 +389,7 @@ For each new project:
## Support

For issues with:

- **MCP Server**: Check `/Users/dimitarklaturov/Dropbox/github/mcp-server-mysql`
- **Claude Code**: Run `claude --help` or visit https://docs.anthropic.com/en/docs/claude-code
- **SSH Tunnels**: Check server connectivity and SSH key configuration
- **Claude Code**: Run `claude --help` or visit [https://docs.anthropic.com/en/docs/claude-code](https://docs.anthropic.com/en/docs/claude-code)
- **SSH Tunnels**: Check server connectivity and SSH key configuration
8 changes: 7 additions & 1 deletion README-MULTI-DB.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ To enable multi-DB mode, simply leave the `MYSQL_DB` environment variable empty:
2. **Query Any Database**: You can execute queries against any database to which the MySQL user has access.

3. **Schema Qualification Required**: When working in multi-DB mode, you should use fully qualified table names with schema/database prefixes:

```sql
-- Use fully qualified table names
SELECT * FROM database_name.table_name;
Expand All @@ -46,6 +47,7 @@ To enable multi-DB mode, simply leave the `MYSQL_DB` environment variable empty:
4. **Automatic Read-Only Mode**: For safety, multi-DB mode enforces read-only operations by default. This can be customized using schema-specific permissions (see below).

5. **Database Exploration**: You can explore databases using commands like:

```sql
-- List all databases
SHOW DATABASES;
Expand All @@ -72,14 +74,15 @@ This new feature allows fine-grained control over which operations are allowed o

Set the following environment variables with a comma-separated list of schema:permission pairs:

```
```txt
SCHEMA_INSERT_PERMISSIONS=production:false,development:true,test:true
SCHEMA_UPDATE_PERMISSIONS=production:false,development:true,test:true
SCHEMA_DELETE_PERMISSIONS=production:false,development:false,test:true
SCHEMA_DDL_PERMISSIONS=production:false,development:false,test:true
```

This configuration:

- Allows INSERT and UPDATE on development and test databases, but not production
- Allows DELETE and DDL operations only on the test database
- Blocks all write operations on the production database
Expand Down Expand Up @@ -127,16 +130,19 @@ Here's a complete example configuration with schema-specific permissions:
## Environment Variables Summary

### Multi-DB Mode

- `MYSQL_DB`: Leave empty to enable multi-DB mode
- `MULTI_DB_WRITE_MODE`: Set to "true" to allow write operations in multi-DB mode without schema-specific permissions (not recommended for security)

### Schema-Specific Permissions

- `SCHEMA_INSERT_PERMISSIONS`: Control INSERT permissions per schema
- `SCHEMA_UPDATE_PERMISSIONS`: Control UPDATE permissions per schema
- `SCHEMA_DELETE_PERMISSIONS`: Control DELETE permissions per schema
- `SCHEMA_DDL_PERMISSIONS`: Control DDL permissions per schema (CREATE, ALTER, DROP, TRUNCATE)

### Global Permission Defaults

- `ALLOW_INSERT_OPERATION`: Global default for INSERT permissions
- `ALLOW_UPDATE_OPERATION`: Global default for UPDATE permissions
- `ALLOW_DELETE_OPERATION`: Global default for DELETE permissions
Expand Down
Loading