Skip to main content
Glama
OpenCode MySQL Connector

OpenCode MySQL Connector

by siimleetberg
README.md
# MySQL MCP Connector

A MySQL MCP (Model Context Protocol) server for OpenCode, Claude Code and Claude Desktop. Provides tools to query and explore MySQL databases via stdio transport.

## Environment Variables

| Variable | Required | Default |
|---|---|---|
| `MYSQL_HOST` | Yes | — |
| `MYSQL_PORT` | No | `3306` |
| `MYSQL_USER` | Yes | — |
| `MYSQL_PASSWORD` | Yes | — |
| `MYSQL_DATABASE` | Yes | — |

## Tools

| Tool | Description |
|---|---|
| `execute_query` | Execute a MySQL SQL query (SELECT, INSERT, UPDATE, DELETE, DDL). Supports parameterized queries. |
| `list_tables` | List tables in a database with optional row counts and a `LIKE` name filter. |
| `describe_table` | Get table structure: columns, types, nullability, keys, and defaults. |
| `explain_query` | Get the EXPLAIN execution plan for a SQL query. |
| `get_schema` | Get the DDL (CREATE TABLE) for all tables in a database. |
| `switch_schema` | Switch the active database used by subsequent tools that do not specify one. |
| `check_connection` | Verify the connector can reach the MySQL server. |

## Prompts

| Prompt | Description |
|---|---|
| `show_table_context` | Get a ready-to-use table schema context for a given table name. |

## Setup

```bash
npm install
npm run build
```

## Usage

```bash
MYSQL_HOST=localhost \
MYSQL_USER=root \
MYSQL_PASSWORD=secret \
MYSQL_DATABASE=mysqldatabase \
MYSQL_PORT=3306 \
npm start
```

## Claude Code

Register the server (use `-s user` for all projects or `-s project` to write a shared `.mcp.json`):

```bash
claude mcp add mysql -s user \
  -e MYSQL_HOST=localhost \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=secret \
  -e MYSQL_DATABASE=mysqldatabase \
  -e MYSQL_PORT=3306 \
  -- node /absolute/path/to/opencode_mysql_connector/dist/index.js
```

Equivalent `.mcp.json` (project scope; `${VAR}` is expanded from your shell environment):

```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/absolute/path/to/opencode_mysql_connector/dist/index.js"],
      "env": {
        "MYSQL_HOST": "${MYSQL_HOST}",
        "MYSQL_USER": "${MYSQL_USER}",
        "MYSQL_PASSWORD": "${MYSQL_PASSWORD}",
        "MYSQL_DATABASE": "${MYSQL_DATABASE}",
        "MYSQL_PORT": "${MYSQL_PORT:-3306}"
      }
    }
  }
}
```

Verify with `claude mcp list` or `/mcp` inside a session. Tools appear as `mcp__mysql__<tool>`; the prompt runs as `/mcp__mysql__show_table_context <table>`.

## Claude Desktop

Add to `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows: `%APPDATA%\Claude\`), then restart Claude Desktop:

```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/absolute/path/to/opencode_mysql_connector/dist/index.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "secret",
        "MYSQL_DATABASE": "mysqldatabase",
        "MYSQL_PORT": "3306"
      }
    }
  }
}
```

Claude Desktop does not inherit your shell `PATH`; if `node` is not found, use its absolute path (`which node`).

## License

ISC

TDQS

C2.1/5.0

Scored across 7 tools

Disambiguation4/5

Tool names are sufficiently distinct, but the absence of descriptions increases the risk of confusion between 'get_schema' and 'describe_table'.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern in snake_case, making them predictable and easy to understand.

Tool Count5/5

7 tools is well-scoped for a MySQL connector, covering query execution, metadata retrieval, and schema management without being excessive.

Completeness4/5

The tool set covers core database operations, though missing explicit data manipulation tools (INSERT/UPDATE/DELETE) which are presumably handled by execute_query.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues