mcp-sequel 0.1.1__py3-none-any.whl
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.
- mcp_sequel/__init__.py +0 -0
- mcp_sequel/adapters/__init__.py +8 -0
- mcp_sequel/adapters/base.py +54 -0
- mcp_sequel/adapters/mysql.py +85 -0
- mcp_sequel/adapters/sqlite.py +36 -0
- mcp_sequel/config.py +99 -0
- mcp_sequel/pool.py +33 -0
- mcp_sequel/server.py +87 -0
- mcp_sequel/tunnel.py +26 -0
- mcp_sequel-0.1.1.dist-info/METADATA +173 -0
- mcp_sequel-0.1.1.dist-info/RECORD +14 -0
- mcp_sequel-0.1.1.dist-info/WHEEL +4 -0
- mcp_sequel-0.1.1.dist-info/entry_points.txt +2 -0
- mcp_sequel-0.1.1.dist-info/licenses/LICENSE +21 -0
mcp_sequel/__init__.py
ADDED
|
File without changes
|
|
@@ -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()
|
mcp_sequel/config.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Annotated, Literal, Union
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field, ValidationError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BaseConnectionConfig(BaseModel):
|
|
8
|
+
@property
|
|
9
|
+
def location(self) -> str:
|
|
10
|
+
raise NotImplementedError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SSHTunnelConfig(BaseModel):
|
|
14
|
+
host: str
|
|
15
|
+
port: int = 22
|
|
16
|
+
user: str
|
|
17
|
+
key_file: str | None = None
|
|
18
|
+
password: str | None = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MySQLConfig(BaseConnectionConfig):
|
|
22
|
+
type: Literal["mysql", "mariadb"]
|
|
23
|
+
host: str
|
|
24
|
+
port: int = 3306
|
|
25
|
+
database: str | None = None
|
|
26
|
+
user: str
|
|
27
|
+
password: str
|
|
28
|
+
readonly: bool = True
|
|
29
|
+
row_limit: int | None = 1000
|
|
30
|
+
description: str | None = None
|
|
31
|
+
ssh_tunnel: SSHTunnelConfig | None = None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def location(self) -> str:
|
|
35
|
+
host = self.host if self.port == 3306 else f"{self.host}:{self.port}"
|
|
36
|
+
loc = f"{self.user}@{host}"
|
|
37
|
+
if self.database:
|
|
38
|
+
loc += f"/{self.database}"
|
|
39
|
+
if self.ssh_tunnel:
|
|
40
|
+
ssh = self.ssh_tunnel
|
|
41
|
+
ssh_host = ssh.host if ssh.port == 22 else f"{ssh.host}:{ssh.port}"
|
|
42
|
+
loc = f"{ssh.user}@{ssh_host} -> {loc}"
|
|
43
|
+
return loc
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class SQLiteConfig(BaseConnectionConfig):
|
|
47
|
+
type: Literal["sqlite"]
|
|
48
|
+
path: str
|
|
49
|
+
readonly: bool = True
|
|
50
|
+
row_limit: int | None = 1000
|
|
51
|
+
description: str | None = None
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def location(self) -> str:
|
|
55
|
+
return self.path
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
ConnectionConfig = Annotated[
|
|
59
|
+
Union[MySQLConfig, SQLiteConfig],
|
|
60
|
+
Field(discriminator="type"),
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def config_dir() -> Path:
|
|
65
|
+
return Path.home() / ".config" / "mcp-sequel"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def load_one(name: str) -> "ConnectionConfig | None":
|
|
69
|
+
path = config_dir() / f"{name}.json"
|
|
70
|
+
if not path.exists():
|
|
71
|
+
return None
|
|
72
|
+
from pydantic import TypeAdapter
|
|
73
|
+
|
|
74
|
+
adapter = TypeAdapter(ConnectionConfig)
|
|
75
|
+
return adapter.validate_json(path.read_text())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def load_all() -> list[tuple[str, ConnectionConfig]]:
|
|
79
|
+
"""Return [(name, config), ...] for all valid .json files in the config dir."""
|
|
80
|
+
directory = config_dir()
|
|
81
|
+
if not directory.exists():
|
|
82
|
+
return []
|
|
83
|
+
|
|
84
|
+
results = []
|
|
85
|
+
for path in sorted(directory.glob("*.json")):
|
|
86
|
+
name = path.stem
|
|
87
|
+
try:
|
|
88
|
+
from pydantic import TypeAdapter
|
|
89
|
+
|
|
90
|
+
adapter = TypeAdapter(ConnectionConfig)
|
|
91
|
+
config = adapter.validate_json(path.read_text())
|
|
92
|
+
results.append((name, config))
|
|
93
|
+
except ValidationError as e:
|
|
94
|
+
# Skip invalid configs but don't crash the server
|
|
95
|
+
import sys
|
|
96
|
+
|
|
97
|
+
print(f"WARNING: skipping {path.name}: {e}", file=sys.stderr)
|
|
98
|
+
|
|
99
|
+
return results
|
mcp_sequel/pool.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from mcp_sequel.adapters import ADAPTERS
|
|
4
|
+
from mcp_sequel.adapters.base import BaseAdapter
|
|
5
|
+
from mcp_sequel.config import ConnectionConfig, load_one
|
|
6
|
+
|
|
7
|
+
_pool: dict[str, tuple[ConnectionConfig, BaseAdapter, Any]] = {}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_connection(conn_name: str) -> tuple[ConnectionConfig, BaseAdapter, Any]:
|
|
11
|
+
if conn_name in _pool:
|
|
12
|
+
cfg, adapter, conn = _pool[conn_name]
|
|
13
|
+
adapter.ping(conn)
|
|
14
|
+
return cfg, adapter, conn
|
|
15
|
+
|
|
16
|
+
cfg = load_one(conn_name)
|
|
17
|
+
if cfg is None:
|
|
18
|
+
raise ValueError(f"Connection '{conn_name}' not found")
|
|
19
|
+
|
|
20
|
+
adapter_class = ADAPTERS[cfg.type]
|
|
21
|
+
adapter = adapter_class(cfg)
|
|
22
|
+
conn = adapter.connect()
|
|
23
|
+
_pool[conn_name] = (cfg, adapter, conn)
|
|
24
|
+
return cfg, adapter, conn
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def close_all() -> None:
|
|
28
|
+
for cfg, adapter, conn in _pool.values():
|
|
29
|
+
try:
|
|
30
|
+
adapter.close(conn)
|
|
31
|
+
except Exception:
|
|
32
|
+
pass
|
|
33
|
+
_pool.clear()
|
mcp_sequel/server.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import sqlglot
|
|
4
|
+
from mcp.server.fastmcp import FastMCP
|
|
5
|
+
|
|
6
|
+
from mcp_sequel.adapters.base import ReadonlyViolationError
|
|
7
|
+
from mcp_sequel.config import load_all
|
|
8
|
+
from mcp_sequel.pool import get_connection
|
|
9
|
+
|
|
10
|
+
mcp = FastMCP("mcp-sequel", instructions="MySQL database query tool")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _is_select_without_limit(sql: str, dialect: str) -> bool:
|
|
14
|
+
stmts = sqlglot.parse(sql, dialect=dialect)
|
|
15
|
+
if not stmts or len(stmts) != 1:
|
|
16
|
+
return False
|
|
17
|
+
stmt = stmts[0]
|
|
18
|
+
return isinstance(stmt, sqlglot.exp.Select) and stmt.args.get("limit") is None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@mcp.tool()
|
|
22
|
+
def list_connections() -> str:
|
|
23
|
+
"""List all configured database connections."""
|
|
24
|
+
try:
|
|
25
|
+
connections = load_all()
|
|
26
|
+
except Exception as e:
|
|
27
|
+
return f"ERROR: failed to load configs: {e}"
|
|
28
|
+
|
|
29
|
+
if not connections:
|
|
30
|
+
from mcp_sequel.config import config_dir
|
|
31
|
+
|
|
32
|
+
return f"No connections configured. Add .json files to: {config_dir()}"
|
|
33
|
+
|
|
34
|
+
blocks = []
|
|
35
|
+
for name, cfg in connections:
|
|
36
|
+
readonly = "yes" if cfg.readonly else "no"
|
|
37
|
+
|
|
38
|
+
header = f"{name} ({cfg.location}) [{cfg.type}], readonly: {readonly}"
|
|
39
|
+
if cfg.description:
|
|
40
|
+
blocks.append(f"{header}\n {cfg.description}")
|
|
41
|
+
else:
|
|
42
|
+
blocks.append(header)
|
|
43
|
+
|
|
44
|
+
return "\n\n".join(blocks)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@mcp.tool()
|
|
48
|
+
def query(connection: str, sql: str, database: str | None = None) -> str:
|
|
49
|
+
"""Execute a SQL query on a database connection. Returns JSON with columns, rows, row_count, limit_applied."""
|
|
50
|
+
try:
|
|
51
|
+
cfg, adapter, conn = get_connection(connection)
|
|
52
|
+
|
|
53
|
+
if cfg.readonly:
|
|
54
|
+
adapter.guard_readonly(sql)
|
|
55
|
+
|
|
56
|
+
actual_sql = sql
|
|
57
|
+
limit_applied = None
|
|
58
|
+
if cfg.row_limit is not None and _is_select_without_limit(
|
|
59
|
+
sql, adapter.sqlglot_dialect
|
|
60
|
+
):
|
|
61
|
+
actual_sql = sql.rstrip().rstrip(";") + f" LIMIT {cfg.row_limit}"
|
|
62
|
+
limit_applied = cfg.row_limit
|
|
63
|
+
|
|
64
|
+
result = adapter.execute(conn, actual_sql, database)
|
|
65
|
+
result.limit_applied = limit_applied
|
|
66
|
+
|
|
67
|
+
return json.dumps(
|
|
68
|
+
{
|
|
69
|
+
"columns": result.columns,
|
|
70
|
+
"rows": result.rows,
|
|
71
|
+
"row_count": result.row_count,
|
|
72
|
+
"limit_applied": result.limit_applied,
|
|
73
|
+
},
|
|
74
|
+
ensure_ascii=False,
|
|
75
|
+
)
|
|
76
|
+
except ReadonlyViolationError as e:
|
|
77
|
+
return f"ERROR: readonly violation: {e}"
|
|
78
|
+
except Exception as e:
|
|
79
|
+
return f"ERROR: {e}"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def main():
|
|
83
|
+
mcp.run(transport="stdio")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
mcp_sequel/tunnel.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from sshtunnel import SSHTunnelForwarder
|
|
4
|
+
|
|
5
|
+
from mcp_sequel.config import SSHTunnelConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def open_tunnel(
|
|
9
|
+
ssh_cfg: SSHTunnelConfig, remote_host: str, remote_port: int
|
|
10
|
+
) -> SSHTunnelForwarder:
|
|
11
|
+
kwargs: dict = {
|
|
12
|
+
"ssh_username": ssh_cfg.user,
|
|
13
|
+
"remote_bind_address": (remote_host, remote_port),
|
|
14
|
+
}
|
|
15
|
+
if ssh_cfg.key_file:
|
|
16
|
+
kwargs["ssh_pkey"] = str(Path(ssh_cfg.key_file).expanduser())
|
|
17
|
+
if ssh_cfg.password:
|
|
18
|
+
kwargs["ssh_password"] = ssh_cfg.password
|
|
19
|
+
|
|
20
|
+
tunnel = SSHTunnelForwarder((ssh_cfg.host, ssh_cfg.port), **kwargs)
|
|
21
|
+
tunnel.start()
|
|
22
|
+
return tunnel
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def close_tunnel(tunnel: SSHTunnelForwarder) -> None:
|
|
26
|
+
tunnel.stop()
|
|
@@ -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,14 @@
|
|
|
1
|
+
mcp_sequel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mcp_sequel/config.py,sha256=uWlcsqNvFUgWq2SANEA9aak3y6k4kQ9qGr-Esi3fbbg,2604
|
|
3
|
+
mcp_sequel/pool.py,sha256=bJeZTjFAKoXrgCMVXhccQjtyiEmhgI-m9jonBl0-1Bs,924
|
|
4
|
+
mcp_sequel/server.py,sha256=yh1fCpp1XrtWrdVkFSJPdmeNiSPzeXScIZ2u4n5QMEk,2524
|
|
5
|
+
mcp_sequel/tunnel.py,sha256=9Os6Zw47U-AdDccyrJ1ymU387_Gw6RK43caQD_4SiuQ,701
|
|
6
|
+
mcp_sequel/adapters/__init__.py,sha256=SSGY9kK_jKuIQK_38Ri8BXJ4F32z2sZhTlgm6ao2yyk,222
|
|
7
|
+
mcp_sequel/adapters/base.py,sha256=mHiUiibLRUMco7s9d9rJrszci9PRPzZfizQk62FCtA8,1374
|
|
8
|
+
mcp_sequel/adapters/mysql.py,sha256=vp4mj410CrwAjW0NRXzHI4QerUBag8vQiyMo4vB-uts,2670
|
|
9
|
+
mcp_sequel/adapters/sqlite.py,sha256=p_HjrWrEIOCP3Tj664pbGY3zfjBeXpwlLlcXHBc3lHg,1103
|
|
10
|
+
mcp_sequel-0.1.1.dist-info/METADATA,sha256=a5Be4q15G_NOtqBQFKI64SaYiVic3SQk_gF7mrZ47gM,5840
|
|
11
|
+
mcp_sequel-0.1.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
12
|
+
mcp_sequel-0.1.1.dist-info/entry_points.txt,sha256=XDHdQ_JNIsHKhLsl85F5WmuS3UEnHL2PXlhz6LjlWpc,54
|
|
13
|
+
mcp_sequel-0.1.1.dist-info/licenses/LICENSE,sha256=tdNgBtlRWF1KbLtPlYVZuomItZsT1Xrbab__zrlJpbY,1072
|
|
14
|
+
mcp_sequel-0.1.1.dist-info/RECORD,,
|
|
@@ -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.
|