CLAUDE.md · benborla/mcp-server-mysql
CLAUDE.md from benborla/mcp-server-mysql: 250 lines covering Project Overview, Build and Development Commands, Architecture, Project Structure and more.
Template by benborla
Chalk Labs
Need help deploying CLAUDE.md · benborla/mcp-server-mysql?
Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.
Install
Works with Claude Code. Read the repository before you give any tool access to your data.
curl -fsSL https://raw.githubusercontent.com/benborla/mcp-server-mysql/main/CLAUDE.md -o CLAUDE.md
Read it and adapt it to your project before use.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: database-access, code-generation
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
What's in it
A CLAUDE.md file: project memory Claude Code loads at the start of every session.
- For
- Claude Code
- Length
- 250 lines
- File
CLAUDE.md
Sections
- Project Overview
- Build and Development Commands
- Architecture
- Project Structure
- Important Development Notes
- Common Development Tasks
First lines (shown under the repo's MIT license)
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
This is a Model Context Protocol (MCP) server that provides MySQL database access to LLMs like Claude, with enhanced write operation support and Claude Code optimizations.
**Key Technologies:**
- TypeScript with ES Modules (NodeNext)
- MCP SDK (@modelcontextprotocol/sdk v1.15.1)
- mysql2 for database connectivity
- Vitest for testing
- Express for remote MCP mode (optional)
## Build and Development Commands
### Building
```bash
# Build TypeScript to dist/
pnpm build
# Watch mode (auto-rebuild on changes)
pnpm watch
```
### Running
```bash
# Run built version
pnpm start
# Development mode with ts-node
pnpm dev
# Run directly with environment variables
pnpm exec
```
### Testing
```bash
# Setup test database (creates mcp_test DB and seeds data)
pnpm run setup:test:db
# Run all tests (includes pretest hook that runs setup:test:db)
pnpm test
# Run specific test suites
pnpm test:unit # Unit tests only
pnpm test:integration # Integration tests only
pnpm test:e2e # End-to-end tests only
pnpm test:socket # Socket connection tests
# Watch mode for development
pnpm test:watch
# Coverage report
pnpm test:coverage
```
**Test Environment Requirements:**
- MySQL server running locally or remotely
- Test database user: `mcp_test` with password `mcp_test_password`
- Test database: `mcp_test`
- Configuration via `.env.test` file
### Linting
```bash
pnpm lint
```
## Architecture
### Core Entry Point
- `index.ts` - Main server file that exports `createMcpServer()` function
- Supports both stdio and HTTP transport modes
- Handles MCP protocol setup and request routing
- Configures shutdown handlers for graceful cleanup
### Key Modules
**Configuration (`src/config/index.ts`)**
- Loads environment variables via dotenv
- Exports connection config, permission flags, and mode detection
- Key exports:
- `mcpConfig` - MySQL connection configuration
- `isMultiDbMode` - Boolean indicating multi-database mode
- `ALLOW_*_OPERATION` - Global write permission flags
- `SCHEMA_*_PERMISSIONS` - Schema-specific permission maps
- `MYSQL_DISABLE_READ_ONLY_TRANSACTIONS` - Control transaction mode
**Database Layer (`src/db/index.ts`)**
- Connection pooling via `getPool()` and lazy-loaded `poolPromise`
- Three query execution methods:
- `executeQuery<T>()` - Basic query execution
- `executeReadOnlyQuery<T>()` - Enforces read-only transaction mode (unless disabled)
- `executeWriteQuery<T>()` - Handles INSERT/UPDATE/DELETE/DDL with transactions
- Permission checking integrated into query execution
- Schema extraction from queries for permission enforcement
**Permissions (`src/db/permissions.ts`)**
- Schema-specific permission checking functions:
- `isInsertAllowedForSchema(schema)`
- `isUpdateAllowedForSchema(schema)`
- `isDeleteAllowedForSchema(schema)`
- `isDDLAllowedForSchema(schema)`
- Falls back to global permissions if no schema-specific rule exists
**Utilities (`src/db/utils.ts`)**
- `getQueryTypes()` - Parses SQL to identify operation types (SELECT, INSERT, etc.)
- `extractSchemaFromQuery()` - Extracts database schema from qualified table names or USE statements
### MCP Protocol Implementation
**Resources** (Database introspection):
- `ListResourcesRequest` - Returns all tables across accessible schemas
- `ReadResourceRequest` - Returns column metadata for specific tables
- URIs: `mysql://tables` and `mysql://tables/{tableName}`
**Tools** (Query execution):
- `mysql_query` - Single tool that executes SQL queries
- Input: `{ sql: string }`
- Output: JSON result set with execution time
- Enforces permissions based on query type and target schema
### Multi-Database Mode
When `MYSQL_DB` environment variable is empty or unset:
- Server operates in multi-DB mode
- Queries must use fully qualified table names (`database.table`) or `USE` statements
- Schema-specific permissions apply per database
- Write operations disabled by default unless `MULTI_DB_WRITE_MODE=true`
### Permission System
**Two-Level Hierarchy:**
1. Global flags: `ALLOW_INSERT_OPERATION`, `ALLOW_UPDATE_OPERATION`, `ALLOW_DELETE_OPERATION`, `ALLOW_DDL_OPERATION`
2. Schema-specific overrides: `SCHEMA_*_PERMISSIONS` environment variables
**Format:** `SCHEMA_INSERT_PERMISSIONS=development:true,test:true,production:false`
**Transaction Safety:**
- Read operations use `SET SESSION TRANSACTION READ ONLY` by default
- Can be disabled with `MYSQL_DISABLE_READ_ONLY_TRANSACTIONS=true` for DDL support
- Write operations use explicit transactions with commit/rollbackSignals
- Stars
- 2,179
- Forks
- 259
- Open issues
- 46
- Last commit (this folder)
- Nov 5, 2025 (0 years ago)
- Last release
- Jun 19, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/benborla/mcp-server-mysql
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from benborla
Done for you
Rather not set it up yourself?
Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.
See how we build AI agents →Read the case studies
Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.
- launches shipped
- 50+
- launches shipped
- media placements
- 500+
- media placements
- founders on every account
- 2
- founders on every account
Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block
Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.
Get CLAUDE.md · benborla/mcp-server-mysql running in your business
Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.
Cite this page
CLAUDE.md · benborla/mcp-server-mysql. Agent Mart. https://agentmart.dev/templates/benborla-mcp-server-mysql-claude-md (last updated 2026-10-24)