Metadata-Version: 2.1
Name: jj-mcp-mysql
Version: 0.1.0
Summary: Read-only MySQL MCP server with multi-connection profiles
Keywords: mcp,model-context-protocol,mysql,database,sql,read-only
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: mysql-connector-python>=8.0

# mcp-mysql

<!-- mcp-name: io.github.ranjian/mcp-mysql -->

A small, dependency-light [Model Context Protocol](https://modelcontextprotocol.io) server that gives MCP clients (Trae, Cursor, Claude Desktop, ...) read-only access to one or more MySQL databases through a single `db_profiles.json` file.

- Multiple connections in one server (production / test / reporting ...), each with its own credentials
- Per-database notes and usage rules returned to the model before it writes SQL
- Two tools only: `list_connections` and `execute_sql`
- Any SQL client can be used, but the server is designed for read-only accounts

## Install

```bash
pipx install jj-mcp-mysql
# or
pip install jj-mcp-mysql
```

The distribution is named `jj-mcp-mysql`; the installed command is `mcp-mysql`.

## Configure

Copy the sample profile file and fill in your connections:

```bash
cp db_profiles.sample db_profiles.json
```

```json
{
  "default_connection": "my_conn",
  "connections": {
    "my_conn": {
      "description": "Test database",
      "usage": "Read-only account. Only SELECT is allowed.",
      "host": "127.0.0.1",
      "port": 3306,
      "user": "readonly",
      "password": "change-me",
      "charset": "utf8mb4",
      "databases": ["your_database"],
      "default_database": "your_database"
    }
  }
}
```

Keys starting with `_` are treated as samples and are skipped.

## Run

```bash
export MCP_DB_PROFILES_FILE=/absolute/path/to/db_profiles.json
mcp-mysql
```

If `MCP_DB_PROFILES_FILE` is not set, the server looks for `db_profiles.json` in the current working directory.

### MCP client configuration

```json
{
  "mcpServers": {
    "mcp-mysql": {
      "command": "mcp-mysql",
      "env": {
        "MCP_DB_PROFILES_FILE": "/absolute/path/to/db_profiles.json"
      }
    }
  }
}
```

## Tools

| Tool | Purpose |
| --- | --- |
| `list_connections` | List connections, their usage notes and available databases |
| `execute_sql` | Run SQL on a chosen connection and database; omit `connection` / `database` to use the defaults |

The server injects usage notes into the MCP `instructions`, so the model knows which connection and database to pick. SELECT statements are expected to carry an explicit `LIMIT` (100 rows by default in prompts).

## Security notes

- Use a **read-only** MySQL account; the server does not block writes on its own.
- `db_profiles.json` contains credentials and is git-ignored. Never commit it.
- Prefer environment variables or a file outside the repository for production credentials.

## Development

```bash
python -m venv .venv
.venv/Scripts/pip install -e .
python -m mcp_mysql
```

## Release

```bash
python -m build
twine upload dist/*
mcp-publisher validate
mcp-publisher publish
```

`mcp-publisher` publishes `server.json` to the official MCP Registry. Update `name`, `repository` and version fields before publishing.
