# Mysql Mcp

> Secure MySQL MCP Server with Clean Architecture. Enables AI assistants (Cursor, Copilot, Cline) to safely interact with MySQL/MariaDB databases, featuring RBAC, audit logging, and intelligent query validation.

- **Type:** MCP server
- **Install:** `agentstack add mcp-az-coder-123-mysql-mcp`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [az-coder-123](https://agentstack.voostack.com/s/az-coder-123)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [az-coder-123](https://github.com/az-coder-123)
- **Source:** https://github.com/az-coder-123/mysql-mcp

## Install

```sh
agentstack add mcp-az-coder-123-mysql-mcp
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# MySQL MCP Server

A secure and professional MySQL Model Context Protocol (MCP) server with clean architecture, designed for seamless integration with GitHub Copilot, Cline, and other AI coding assistants in VS Code.

## Features

- **Clean Architecture**: Follows Single Responsibility Principle for maintainability and scalability
- **Security First**: Built-in permission system, audit logging, and query validation
- **Connection Pooling**: Efficient MySQL connection management with connection pooling
- **Schema Inspection**: Tools for exploring database structure
- **Query Execution**: Secure SQL query execution with timeout controls
- **Audit Logging**: Comprehensive logging of all database operations

## Quick Start

### Installation

```bash
npm install
```

### Configuration

Copy the example configuration and update credentials:

```bash
cp .env.example .env
```

Then edit `.env` in the project root:

```env
# MySQL Connection
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database

# Security Settings
SECURITY_ENABLED=true
ALLOWED_OPERATIONS=SELECT,SHOW,DESCRIBE,EXPLAIN
MAX_QUERY_EXECUTION_TIME=30000

# Audit Settings
AUDIT_ENABLED=true
AUDIT_LOG_LEVEL=info
```

### Build

```bash
npm run build
```

### Run

```bash
npm start
```

## Integration with VS Code

### GitHub Copilot

Recommended for this repository: use the workspace MCP file at `.vscode/mcp.json`.

It is already included in this project and should look like:

```json
{
  "servers": {
    "mysql-local": {
      "type": "stdio",
      "command": "node",
      "args": ["${workspaceFolder}/dist/index.js"],
      "env": {
        "MYSQL_HOST": "${env:MYSQL_HOST}",
        "MYSQL_PORT": "${env:MYSQL_PORT}",
        "MYSQL_USER": "${env:MYSQL_USER}",
        "MYSQL_PASSWORD": "${env:MYSQL_PASSWORD}",
        "MYSQL_DATABASE": "${env:MYSQL_DATABASE}"
      }
    }
  }
}
```

Alternative: add to VS Code user settings (`settings.json`):

```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-mcp/dist/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}
```

### Cline

Configure in Cline settings:

```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-mcp/dist/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}
```

## Available Tools

### Query Tools

#### execute_query
Execute SQL queries against the database.

**Parameters:**
- `sql` (required): SQL query to execute
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking
- `timeout` (optional): Query timeout in milliseconds

### Schema Tools

#### list_databases
List all available databases.

**Parameters:**
- `userId` (optional): User ID for permission checking

#### list_tables
List all tables in a database.

**Parameters:**
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

#### describe_table
Get the structure of a table.

**Parameters:**
- `table` (required): Table name
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

### Admin Tools

#### get_server_status
Get MySQL server status variables.

**Parameters:**
- `userId` (optional): User ID for permission checking

#### get_process_list
Get list of running MySQL processes.

**Parameters:**
- `userId` (optional): User ID for permission checking

#### kill_query
Kill a running MySQL process.

**Parameters:**
- `processId` (required): Process ID to kill
- `userId` (optional): User ID for permission checking

#### get_table_indexes
Get index information for a table.

**Parameters:**
- `table` (required): Table name
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

#### get_table_constraints
Get constraint information for a table.

**Parameters:**
- `table` (required): Table name
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

#### analyze_table
Analyze table statistics.

**Parameters:**
- `table` (required): Table name
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

#### optimize_table
Optimize a table.

**Parameters:**
- `table` (required): Table name
- `database` (optional): Database name
- `userId` (optional): User ID for permission checking

### RBAC Tools

All RBAC tools require authentication and API key permission `rbac_admin`.

#### Role and Permission Management
- `create_role(name, desc)`
- `delete_role(id)`
- `list_roles()`
- `create_permission(name, desc)`
- `list_permissions()`
- `assign_permission_to_role(roleId, permId)`
- `revoke_permission_from_role(roleId, permId)`

#### User Role Assignment
- `assign_role_to_user(userId, roleId)`
- `revoke_role_from_user(userId, roleId)`
- `list_user_roles(userId)`

#### Authorization Checks
- `check_user_permission(userId, permissionName)`
- `current_user_permissions()`
- `can_access(userId, resource, action, attributes?)`

#### RBAC Audit
- `audit_log(event, actor, target, details)`
- `query_audit_logs(filter)`

#### RBAC Database Operations
- `db_migrate_rbac()`
- `db_seed_rbac_defaults()`
- `db_check_integrity()`

## Available Resources

### mysql://status
Current database connection status and pool information.

### mysql://config
Server configuration (sanitized, no sensitive data).

### mysql://audit/statistics
Statistics about database operations.

### mysql://audit/logs
Recent database operation logs.

## Architecture

```
src/
├── config/           # Configuration management
├── mysql/            # MySQL connection management
├── security/         # Permission and audit logging
├── tools/            # MCP tools implementation
├── resources/        # MCP resources
├── types/            # TypeScript type definitions
└── index.ts          # Main entry point
```

### Key Components

1. **ConfigManager**: Handles configuration loading and validation
2. **MySQLConnectionManager**: Manages connection pooling and query execution
3. **PermissionManager**: Handles permission checking and access control
4. **AuditLogger**: Logs all database operations for security
5. **QueryTool**: Executes SQL queries with security validation
6. **SchemaTool**: Inspects database schema
7. **DatabaseResource**: Provides MCP resources

## Security

- Permission-based access control
- Query timeout enforcement
- Operation whitelisting/blacklisting
- Audit logging of all operations
- Rate limiting support

See [docs/security.md](docs/security.md) for detailed security documentation.

## Documentation

- [Getting Started](docs/getting-started.md)
- [Configuration](docs/configuration.md)
- [Security](docs/security.md)
- [Tools Reference](docs/tools.md)
- [Resources Reference](docs/resources.md)
- [Integration Guide](docs/integration.md)

## Development

```bash
# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Lint
npm run lint

# Format
npm run format
```

## Requirements

- Node.js >= 18.0.0
- MySQL 5.7+ or MariaDB 10.3+

## License

MIT License - see [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

## Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [az-coder-123](https://github.com/az-coder-123)
- **Source:** [az-coder-123/mysql-mcp](https://github.com/az-coder-123/mysql-mcp)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/mcp-az-coder-123-mysql-mcp
- Seller: https://agentstack.voostack.com/s/az-coder-123
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
