mcp-sequel 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ check-lock:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: astral-sh/setup-uv@v5
13
+ - name: Verify uv.lock is up to date
14
+ run: uv lock --check
15
+
16
+ test:
17
+ needs: check-lock
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: astral-sh/setup-uv@v5
25
+ with:
26
+ enable-cache: true
27
+ - name: Run tests
28
+ run: uv run --python ${{ matrix.python-version }} pytest
@@ -0,0 +1,43 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write
13
+ contents: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 2
18
+ - name: Check version changed
19
+ id: version
20
+ run: |
21
+ VERSION=$(grep '^version' pyproject.toml | cut -d'"' -f2)
22
+ PREV=$(git diff HEAD~1 pyproject.toml | grep '^\-version' | cut -d'"' -f2)
23
+ if [ -z "$PREV" ]; then
24
+ echo "changed=false" >> $GITHUB_OUTPUT
25
+ else
26
+ echo "changed=true" >> $GITHUB_OUTPUT
27
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
28
+ fi
29
+ - uses: astral-sh/setup-uv@v5
30
+ if: steps.version.outputs.changed == 'true'
31
+ - name: Build
32
+ if: steps.version.outputs.changed == 'true'
33
+ run: uv build
34
+ - name: Publish to PyPI
35
+ if: steps.version.outputs.changed == 'true'
36
+ uses: pypa/gh-action-pypi-publish@release/v1
37
+ - name: Tag release
38
+ if: steps.version.outputs.changed == 'true'
39
+ run: |
40
+ git config user.name "github-actions[bot]"
41
+ git config user.email "github-actions[bot]@users.noreply.github.com"
42
+ git tag "v${{ steps.version.outputs.version }}"
43
+ git push origin "v${{ steps.version.outputs.version }}"
@@ -0,0 +1,33 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+ *.egg-info/
6
+ *.egg
7
+ dist/
8
+ build/
9
+ .eggs/
10
+
11
+ # Virtualenvs
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Testing
17
+ .pytest_cache/
18
+ .coverage
19
+ htmlcov/
20
+
21
+ # Type checkers
22
+ .mypy_cache/
23
+ .ruff_cache/
24
+
25
+ # Tools
26
+ .pdm-python
27
+ .env
28
+ .envrc
29
+
30
+ # IDE
31
+ .idea/
32
+ .vscode/
33
+ .qlty/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eugene Kosyakov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-sequel
3
+ Version: 0.1.1
4
+ Summary: MCP server for Claude that connects to MySQL, MariaDB, and SQLite databases
5
+ Project-URL: Homepage, https://github.com/eukos/mcp-sequel
6
+ Author-email: Eugene Kosyakov <eukos@yandex.by>
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: ai,claude,llm,mariadb,mcp,mysql,sqlite
10
+ Classifier: Development Status :: 4 - Beta
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: mcp[cli]>=1.0
13
+ Requires-Dist: mysql-connector-python>=8.0
14
+ Requires-Dist: paramiko<3.0,>=2.0
15
+ Requires-Dist: pydantic>=2.0
16
+ Requires-Dist: sqlglot>=20.0
17
+ Requires-Dist: sshtunnel>=0.4
18
+ Description-Content-Type: text/markdown
19
+
20
+ # mcp-sequel
21
+
22
+ MCP server for Claude that connects to MySQL, MariaDB, and SQLite databases. Query your databases using natural language. Supports multiple named connections, SSH tunnels, readonly mode, and per-connection row limits.
23
+
24
+ ## Install & Registration
25
+
26
+ _Tip: ask Claude to read this README and set up the server for you._
27
+
28
+ **Option 1: uvx (recommended)** — no installation needed, always runs the latest version:
29
+
30
+ ```bash
31
+ claude mcp add mcp-sequel uvx mcp-sequel
32
+ ```
33
+
34
+ **Option 2: from cloned repository:**
35
+
36
+ ```bash
37
+ git clone https://github.com/eukos/mcp-sequel
38
+ claude mcp add mcp-sequel uv run --directory /path/to/mcp-sequel mcp-sequel
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ _Tip: ask Claude to read this README and create a connection config for you._
44
+
45
+ One file per connection in `~/.config/mcp-sequel/`. The filename (without `.json`) becomes the connection name.
46
+
47
+ ```bash
48
+ ~/.config/mcp-sequel/
49
+ ├── production.json
50
+ ├── staging.json
51
+ └── local.json
52
+ ```
53
+
54
+ Each file is one connection. Examples:
55
+
56
+ **MySQL / MariaDB**
57
+
58
+ ```json
59
+ {
60
+ "type": "mysql",
61
+ "host": "db.example.com",
62
+ "port": 3306,
63
+ "user": "analyst",
64
+ "password": "secret",
65
+ "database": "myapp",
66
+ "readonly": true,
67
+ "row_limit": 1000,
68
+ "description": "Production replica, analytics only"
69
+ }
70
+ ```
71
+
72
+ | Field | Required | Default | Description |
73
+ |---------------|----------|---------|--------------------------------------------------------|
74
+ | `type` | yes | — | `"mysql"` or `"mariadb"` |
75
+ | `host` | yes | — | hostname or IP |
76
+ | `user` | yes | — | database user |
77
+ | `password` | yes | — | database password |
78
+ | `port` | no | `3306` | TCP port |
79
+ | `database` | no | — | default database; can be overridden per query |
80
+ | `readonly` | no | `true` | if true, only SELECT/SHOW/DESCRIBE/EXPLAIN are allowed |
81
+ | `row_limit` | no | `1000` | max rows returned; `null` for no limit |
82
+ | `description` | no | — | human-readable label shown in `list_connections` |
83
+ | `ssh_tunnel` | no | — | SSH tunnel config (see below); routes the connection through a bastion host |
84
+
85
+ **MySQL via SSH tunnel**
86
+
87
+ Use `ssh_tunnel` when the database is only reachable through a bastion/jump host. `host` and `port` in the top-level config refer to the DB as seen **from the SSH server** (commonly `localhost`).
88
+
89
+ With a key file (most common):
90
+
91
+ ```json
92
+ {
93
+ "type": "mysql",
94
+ "host": "localhost",
95
+ "port": 3306,
96
+ "user": "reader",
97
+ "password": "secret",
98
+ "database": "myapp",
99
+ "ssh_tunnel": {
100
+ "host": "bastion.example.com",
101
+ "user": "ubuntu",
102
+ "key_file": "~/.ssh/id_rsa"
103
+ }
104
+ }
105
+ ```
106
+
107
+ With an SSH password:
108
+
109
+ ```json
110
+ {
111
+ "type": "mysql",
112
+ "host": "localhost",
113
+ "port": 3306,
114
+ "user": "reader",
115
+ "password": "secret",
116
+ "ssh_tunnel": {
117
+ "host": "bastion.example.com",
118
+ "user": "ubuntu",
119
+ "password": "sshpass"
120
+ }
121
+ }
122
+ ```
123
+
124
+ | Field | Required | Default | Description |
125
+ |------------|----------|---------|-----------------------------------------|
126
+ | `host` | yes | — | SSH server hostname or IP |
127
+ | `user` | yes | — | SSH username |
128
+ | `key_file` | no\* | — | path to private key file (`~` expanded) |
129
+ | `password` | no\* | — | SSH password (if not using key file) |
130
+ | `port` | no | `22` | SSH server port |
131
+
132
+ \* at least one of `key_file` or `password` should be provided.
133
+
134
+ **SQLite**
135
+
136
+ ```json
137
+ {
138
+ "type": "sqlite",
139
+ "path": "/data/analytics.db",
140
+ "readonly": true,
141
+ "row_limit": 1000,
142
+ "description": "Local analytics database"
143
+ }
144
+ ```
145
+
146
+ | Field | Required | Default | Description |
147
+ |---------------|----------|---------|--------------------------------------------------------------------|
148
+ | `type` | yes | — | `"sqlite"` |
149
+ | `path` | yes | — | absolute path to the `.db` file |
150
+ | `readonly` | no | `true` | if true, opens connection with `?mode=ro` (OS-level enforcement) |
151
+ | `row_limit` | no | `1000` | max rows returned; `null` for no limit |
152
+ | `description` | no | — | human-readable label shown in `list_connections` |
153
+
154
+ Set permissions to owner-only:
155
+
156
+ ```bash
157
+ chmod 600 ~/.config/mcp-sequel/*.json
158
+ ```
159
+
160
+ ## Usage
161
+
162
+ After registering, restart Claude to load the server. Then try:
163
+
164
+ - "List available database connections"
165
+ - "Show databases for staging"
166
+ - "How many customers do we have on production?"
167
+ - "Show me the schema of the orders table"
168
+ - "Query local: SELECT * FROM users LIMIT 10"
169
+ - "Query production: show me the top 10 users by order count"
170
+
171
+ ## License
172
+
173
+ MIT
@@ -0,0 +1,154 @@
1
+ # mcp-sequel
2
+
3
+ MCP server for Claude that connects to MySQL, MariaDB, and SQLite databases. Query your databases using natural language. Supports multiple named connections, SSH tunnels, readonly mode, and per-connection row limits.
4
+
5
+ ## Install & Registration
6
+
7
+ _Tip: ask Claude to read this README and set up the server for you._
8
+
9
+ **Option 1: uvx (recommended)** — no installation needed, always runs the latest version:
10
+
11
+ ```bash
12
+ claude mcp add mcp-sequel uvx mcp-sequel
13
+ ```
14
+
15
+ **Option 2: from cloned repository:**
16
+
17
+ ```bash
18
+ git clone https://github.com/eukos/mcp-sequel
19
+ claude mcp add mcp-sequel uv run --directory /path/to/mcp-sequel mcp-sequel
20
+ ```
21
+
22
+ ## Configuration
23
+
24
+ _Tip: ask Claude to read this README and create a connection config for you._
25
+
26
+ One file per connection in `~/.config/mcp-sequel/`. The filename (without `.json`) becomes the connection name.
27
+
28
+ ```bash
29
+ ~/.config/mcp-sequel/
30
+ ├── production.json
31
+ ├── staging.json
32
+ └── local.json
33
+ ```
34
+
35
+ Each file is one connection. Examples:
36
+
37
+ **MySQL / MariaDB**
38
+
39
+ ```json
40
+ {
41
+ "type": "mysql",
42
+ "host": "db.example.com",
43
+ "port": 3306,
44
+ "user": "analyst",
45
+ "password": "secret",
46
+ "database": "myapp",
47
+ "readonly": true,
48
+ "row_limit": 1000,
49
+ "description": "Production replica, analytics only"
50
+ }
51
+ ```
52
+
53
+ | Field | Required | Default | Description |
54
+ |---------------|----------|---------|--------------------------------------------------------|
55
+ | `type` | yes | — | `"mysql"` or `"mariadb"` |
56
+ | `host` | yes | — | hostname or IP |
57
+ | `user` | yes | — | database user |
58
+ | `password` | yes | — | database password |
59
+ | `port` | no | `3306` | TCP port |
60
+ | `database` | no | — | default database; can be overridden per query |
61
+ | `readonly` | no | `true` | if true, only SELECT/SHOW/DESCRIBE/EXPLAIN are allowed |
62
+ | `row_limit` | no | `1000` | max rows returned; `null` for no limit |
63
+ | `description` | no | — | human-readable label shown in `list_connections` |
64
+ | `ssh_tunnel` | no | — | SSH tunnel config (see below); routes the connection through a bastion host |
65
+
66
+ **MySQL via SSH tunnel**
67
+
68
+ Use `ssh_tunnel` when the database is only reachable through a bastion/jump host. `host` and `port` in the top-level config refer to the DB as seen **from the SSH server** (commonly `localhost`).
69
+
70
+ With a key file (most common):
71
+
72
+ ```json
73
+ {
74
+ "type": "mysql",
75
+ "host": "localhost",
76
+ "port": 3306,
77
+ "user": "reader",
78
+ "password": "secret",
79
+ "database": "myapp",
80
+ "ssh_tunnel": {
81
+ "host": "bastion.example.com",
82
+ "user": "ubuntu",
83
+ "key_file": "~/.ssh/id_rsa"
84
+ }
85
+ }
86
+ ```
87
+
88
+ With an SSH password:
89
+
90
+ ```json
91
+ {
92
+ "type": "mysql",
93
+ "host": "localhost",
94
+ "port": 3306,
95
+ "user": "reader",
96
+ "password": "secret",
97
+ "ssh_tunnel": {
98
+ "host": "bastion.example.com",
99
+ "user": "ubuntu",
100
+ "password": "sshpass"
101
+ }
102
+ }
103
+ ```
104
+
105
+ | Field | Required | Default | Description |
106
+ |------------|----------|---------|-----------------------------------------|
107
+ | `host` | yes | — | SSH server hostname or IP |
108
+ | `user` | yes | — | SSH username |
109
+ | `key_file` | no\* | — | path to private key file (`~` expanded) |
110
+ | `password` | no\* | — | SSH password (if not using key file) |
111
+ | `port` | no | `22` | SSH server port |
112
+
113
+ \* at least one of `key_file` or `password` should be provided.
114
+
115
+ **SQLite**
116
+
117
+ ```json
118
+ {
119
+ "type": "sqlite",
120
+ "path": "/data/analytics.db",
121
+ "readonly": true,
122
+ "row_limit": 1000,
123
+ "description": "Local analytics database"
124
+ }
125
+ ```
126
+
127
+ | Field | Required | Default | Description |
128
+ |---------------|----------|---------|--------------------------------------------------------------------|
129
+ | `type` | yes | — | `"sqlite"` |
130
+ | `path` | yes | — | absolute path to the `.db` file |
131
+ | `readonly` | no | `true` | if true, opens connection with `?mode=ro` (OS-level enforcement) |
132
+ | `row_limit` | no | `1000` | max rows returned; `null` for no limit |
133
+ | `description` | no | — | human-readable label shown in `list_connections` |
134
+
135
+ Set permissions to owner-only:
136
+
137
+ ```bash
138
+ chmod 600 ~/.config/mcp-sequel/*.json
139
+ ```
140
+
141
+ ## Usage
142
+
143
+ After registering, restart Claude to load the server. Then try:
144
+
145
+ - "List available database connections"
146
+ - "Show databases for staging"
147
+ - "How many customers do we have on production?"
148
+ - "Show me the schema of the orders table"
149
+ - "Query local: SELECT * FROM users LIMIT 10"
150
+ - "Query production: show me the top 10 users by order count"
151
+
152
+ ## License
153
+
154
+ MIT
File without changes
@@ -0,0 +1,8 @@
1
+ from mcp_sequel.adapters.mysql import MySQLAdapter
2
+ from mcp_sequel.adapters.sqlite import SQLiteAdapter
3
+
4
+ ADAPTERS: dict[str, type] = {
5
+ "mysql": MySQLAdapter,
6
+ "mariadb": MySQLAdapter,
7
+ "sqlite": SQLiteAdapter,
8
+ }
@@ -0,0 +1,54 @@
1
+ import datetime
2
+ import decimal
3
+ from abc import ABC, abstractmethod
4
+ from dataclasses import dataclass
5
+ from typing import Any
6
+
7
+
8
+ def _serialize(value: Any) -> Any:
9
+ if isinstance(value, (datetime.date, datetime.datetime, datetime.timedelta)):
10
+ return str(value)
11
+ if isinstance(value, decimal.Decimal):
12
+ return str(value)
13
+ if isinstance(value, bytes):
14
+ return value.hex()
15
+ return value
16
+
17
+
18
+ class ReadonlyViolationError(Exception):
19
+ pass
20
+
21
+
22
+ @dataclass
23
+ class QueryResult:
24
+ columns: list[str]
25
+ rows: list[list]
26
+ row_count: int
27
+ limit_applied: int | None
28
+
29
+
30
+ class BaseAdapter(ABC):
31
+ ALLOWED_STATEMENTS: frozenset[str] = frozenset()
32
+ sqlglot_dialect: str = ""
33
+
34
+ def __init__(self, config: Any) -> None:
35
+ self.config = config
36
+
37
+ def guard_readonly(self, sql: str) -> None:
38
+ # No-op by default. Two strategies exist:
39
+ # - Connection-level enforcement (SQLite: file URI with mode=ro) — leave as no-op
40
+ # - Statement-level enforcement (MySQL: parse SQL, reject non-SELECT) — override this method
41
+ pass
42
+
43
+ @abstractmethod
44
+ def connect(self) -> Any: ...
45
+
46
+ @abstractmethod
47
+ def ping(self, conn: Any) -> bool: ...
48
+
49
+ @abstractmethod
50
+ def execute(self, conn: Any, sql: str, database: str | None) -> QueryResult: ...
51
+
52
+ @abstractmethod
53
+ def close(self, conn: Any) -> None: ...
54
+
@@ -0,0 +1,85 @@
1
+ from typing import Any
2
+
3
+ import mysql.connector
4
+ import sqlglot
5
+
6
+ from mcp_sequel.adapters.base import (
7
+ BaseAdapter,
8
+ QueryResult,
9
+ ReadonlyViolationError,
10
+ _serialize,
11
+ )
12
+ from mcp_sequel.tunnel import close_tunnel, open_tunnel
13
+
14
+
15
+ class MySQLAdapter(BaseAdapter):
16
+ ALLOWED_STATEMENTS = frozenset({"SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "USE"})
17
+
18
+ def __init__(self, config: Any) -> None:
19
+ super().__init__(config)
20
+ self.sqlglot_dialect = config.type # "mysql" or "mariadb"
21
+ self._tunnel: Any = None
22
+
23
+ def guard_readonly(self, sql: str) -> None:
24
+ stmts = sqlglot.parse(sql, dialect=self.sqlglot_dialect)
25
+ if not stmts:
26
+ raise ReadonlyViolationError("could not parse SQL")
27
+ for stmt in stmts:
28
+ stmt_type = type(stmt).__name__.upper()
29
+ if stmt_type not in self.ALLOWED_STATEMENTS:
30
+ raise ReadonlyViolationError(
31
+ f"{stmt_type} statement is not allowed in readonly mode"
32
+ )
33
+
34
+ def connect(self) -> Any:
35
+ if self.config.ssh_tunnel:
36
+ self._tunnel = open_tunnel(
37
+ self.config.ssh_tunnel,
38
+ self.config.host,
39
+ self.config.port,
40
+ )
41
+ host = "127.0.0.1"
42
+ port = self._tunnel.local_bind_port
43
+ else:
44
+ self._tunnel = None
45
+ host = self.config.host
46
+ port = self.config.port
47
+
48
+ return mysql.connector.connect(
49
+ host=host,
50
+ port=port,
51
+ user=self.config.user,
52
+ password=self.config.password,
53
+ database=self.config.database or None,
54
+ autocommit=True,
55
+ )
56
+
57
+ def ping(self, conn: Any) -> bool:
58
+ conn.ping(reconnect=True)
59
+ return True
60
+
61
+ def execute(self, conn: Any, sql: str, database: str | None) -> QueryResult:
62
+ cursor = conn.cursor()
63
+ try:
64
+ if database is not None:
65
+ cursor.execute(f"USE `{database}`")
66
+ cursor.execute(sql)
67
+ columns = (
68
+ [desc[0] for desc in cursor.description] if cursor.description else []
69
+ )
70
+ raw_rows = cursor.fetchall() or []
71
+ rows = [[_serialize(v) for v in row] for row in raw_rows]
72
+ return QueryResult(
73
+ columns=columns,
74
+ rows=rows,
75
+ row_count=len(rows),
76
+ limit_applied=None,
77
+ )
78
+ finally:
79
+ cursor.close()
80
+
81
+ def close(self, conn: Any) -> None:
82
+ conn.close()
83
+ if self._tunnel is not None:
84
+ close_tunnel(self._tunnel)
85
+ self._tunnel = None
@@ -0,0 +1,36 @@
1
+ import sqlite3
2
+ from typing import Any
3
+
4
+ from mcp_sequel.adapters.base import BaseAdapter, QueryResult, _serialize
5
+
6
+
7
+ class SQLiteAdapter(BaseAdapter):
8
+ sqlglot_dialect = "sqlite"
9
+
10
+ def connect(self) -> sqlite3.Connection:
11
+ path = self.config.path
12
+ if self.config.readonly:
13
+ uri = f"file:{path}?mode=ro"
14
+ return sqlite3.connect(uri, uri=True)
15
+ return sqlite3.connect(path)
16
+
17
+ def ping(self, conn: sqlite3.Connection) -> bool:
18
+ conn.execute("SELECT 1")
19
+ return True
20
+
21
+ def execute(
22
+ self, conn: sqlite3.Connection, sql: str, database: str | None
23
+ ) -> QueryResult:
24
+ cursor = conn.execute(sql)
25
+ columns = [desc[0] for desc in cursor.description] if cursor.description else []
26
+ raw_rows = cursor.fetchall() or []
27
+ rows = [[_serialize(v) for v in row] for row in raw_rows]
28
+ return QueryResult(
29
+ columns=columns,
30
+ rows=rows,
31
+ row_count=len(rows),
32
+ limit_applied=None,
33
+ )
34
+
35
+ def close(self, conn: sqlite3.Connection) -> None:
36
+ conn.close()