sql-query-mcp 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.
- sql_query_mcp-0.1.1/LICENSE +21 -0
- sql_query_mcp-0.1.1/PKG-INFO +235 -0
- sql_query_mcp-0.1.1/README.md +205 -0
- sql_query_mcp-0.1.1/pyproject.toml +45 -0
- sql_query_mcp-0.1.1/setup.cfg +4 -0
- sql_query_mcp-0.1.1/sql_query_mcp/__init__.py +5 -0
- sql_query_mcp-0.1.1/sql_query_mcp/__main__.py +5 -0
- sql_query_mcp-0.1.1/sql_query_mcp/adapters/__init__.py +15 -0
- sql_query_mcp-0.1.1/sql_query_mcp/adapters/mysql.py +171 -0
- sql_query_mcp-0.1.1/sql_query_mcp/adapters/postgres.py +180 -0
- sql_query_mcp-0.1.1/sql_query_mcp/app.py +105 -0
- sql_query_mcp-0.1.1/sql_query_mcp/audit.py +42 -0
- sql_query_mcp-0.1.1/sql_query_mcp/config.py +255 -0
- sql_query_mcp-0.1.1/sql_query_mcp/errors.py +34 -0
- sql_query_mcp-0.1.1/sql_query_mcp/executor.py +243 -0
- sql_query_mcp-0.1.1/sql_query_mcp/introspection.py +225 -0
- sql_query_mcp-0.1.1/sql_query_mcp/namespace.py +48 -0
- sql_query_mcp-0.1.1/sql_query_mcp/registry.py +67 -0
- sql_query_mcp-0.1.1/sql_query_mcp/release_metadata.py +93 -0
- sql_query_mcp-0.1.1/sql_query_mcp/validator.py +128 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/PKG-INFO +235 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/SOURCES.txt +32 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/dependency_links.txt +1 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/entry_points.txt +2 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/requires.txt +8 -0
- sql_query_mcp-0.1.1/sql_query_mcp.egg-info/top_level.txt +1 -0
- sql_query_mcp-0.1.1/tests/test_audit.py +79 -0
- sql_query_mcp-0.1.1/tests/test_config.py +380 -0
- sql_query_mcp-0.1.1/tests/test_executor.py +205 -0
- sql_query_mcp-0.1.1/tests/test_metadata.py +231 -0
- sql_query_mcp-0.1.1/tests/test_namespace.py +80 -0
- sql_query_mcp-0.1.1/tests/test_registry.py +78 -0
- sql_query_mcp-0.1.1/tests/test_release_metadata.py +138 -0
- sql_query_mcp-0.1.1/tests/test_validator.py +121 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andy Wang
|
|
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,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sql-query-mcp
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Read-only SQL MCP server for PostgreSQL and MySQL.
|
|
5
|
+
Author: Andy Wang
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/andyWang1688/sql-query-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/andyWang1688/sql-query-mcp
|
|
9
|
+
Project-URL: Documentation, https://github.com/andyWang1688/sql-query-mcp/blob/main/README.md
|
|
10
|
+
Project-URL: Issues, https://github.com/andyWang1688/sql-query-mcp/issues
|
|
11
|
+
Keywords: mcp,mcp-server,sql,database,postgresql,mysql,cli,codex,chatgpt
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Environment :: Console
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: mcp>=1.12.4
|
|
24
|
+
Requires-Dist: PyMySQL>=1.1
|
|
25
|
+
Requires-Dist: psycopg[binary]>=3.2
|
|
26
|
+
Requires-Dist: psycopg-pool>=3.2
|
|
27
|
+
Requires-Dist: sqlglot>=25.20.2
|
|
28
|
+
Requires-Dist: tomli>=2; python_version < "3.11"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# sql-query-mcp
|
|
32
|
+
|
|
33
|
+
[中文版](README-zh.md)
|
|
34
|
+
|
|
35
|
+
A general-purpose MCP server that lets AI work with multiple databases within
|
|
36
|
+
clear boundaries.
|
|
37
|
+
|
|
38
|
+
## Current database support
|
|
39
|
+
|
|
40
|
+
| Database | Status | Current availability |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| PostgreSQL | Supported | Available today |
|
|
43
|
+
| MySQL | Supported | Available today |
|
|
44
|
+
| SQLite | Candidate | Not supported yet |
|
|
45
|
+
| SQL Server | Candidate | Not supported yet |
|
|
46
|
+
| ClickHouse | Candidate | Not supported yet |
|
|
47
|
+
|
|
48
|
+
## Product value
|
|
49
|
+
|
|
50
|
+
`sql-query-mcp` helps AI clients discover schema, sample data, and analyze
|
|
51
|
+
read-only queries through one controlled MCP interface.
|
|
52
|
+
|
|
53
|
+
It keeps connection handling, namespace rules, SQL validation, and audit
|
|
54
|
+
logging on the server side, so you can expose useful database context to AI
|
|
55
|
+
without exposing raw connection strings or flattening engine-specific concepts.
|
|
56
|
+
|
|
57
|
+
## What AI can do with it
|
|
58
|
+
|
|
59
|
+
The current tool set focuses on database discovery and controlled query
|
|
60
|
+
workflows. You can use it to help an AI assistant understand structure before
|
|
61
|
+
it generates or refines SQL.
|
|
62
|
+
|
|
63
|
+
MySQL supports `explain_query`, but not `explain_query(..., analyze=True)` in
|
|
64
|
+
the current implementation.
|
|
65
|
+
|
|
66
|
+
| Tool | PostgreSQL | MySQL | Purpose |
|
|
67
|
+
| --- | --- | --- | --- |
|
|
68
|
+
| `list_connections()` | Yes | Yes | List configured connections |
|
|
69
|
+
| `list_schemas(connection_id)` | Yes | No | List visible PostgreSQL schemas |
|
|
70
|
+
| `list_databases(connection_id)` | No | Yes | List visible MySQL databases |
|
|
71
|
+
| `list_tables(connection_id, schema?, database?)` | Yes | Yes | List tables and views |
|
|
72
|
+
| `describe_table(connection_id, table_name, schema?, database?)` | Yes | Yes | Inspect columns, keys, and indexes |
|
|
73
|
+
| `run_select(connection_id, sql, limit?)` | Yes | Yes | Run read-only queries |
|
|
74
|
+
| `explain_query(connection_id, sql, analyze?)` | Yes | Yes | Inspect query plans |
|
|
75
|
+
| `get_table_sample(connection_id, table_name, schema?, database?, limit?)` | Yes | Yes | Fetch small table samples |
|
|
76
|
+
|
|
77
|
+
These tools are useful for tasks such as listing namespaces, inspecting table
|
|
78
|
+
definitions, reviewing indexes, sampling records, and analyzing read-only
|
|
79
|
+
queries with `EXPLAIN`. For full request and response details, see
|
|
80
|
+
`docs/api-reference.md` (Chinese).
|
|
81
|
+
|
|
82
|
+
## How boundaries are constrained
|
|
83
|
+
|
|
84
|
+
The product boundary is intentionally narrow today. Only PostgreSQL and MySQL
|
|
85
|
+
are available today, and the current tool set is fully read-only.
|
|
86
|
+
|
|
87
|
+
The service keeps those boundaries explicit in a few ways.
|
|
88
|
+
|
|
89
|
+
- Connections declare `engine` explicitly, so the server never guesses from
|
|
90
|
+
`connection_id`.
|
|
91
|
+
- PostgreSQL uses `schema`, and MySQL uses `database`, without collapsing both
|
|
92
|
+
into one vague namespace field.
|
|
93
|
+
- Real DSNs stay in environment variables, while config files store only the
|
|
94
|
+
environment variable names.
|
|
95
|
+
- Query execution passes through `sqlglot` validation before reaching the
|
|
96
|
+
database.
|
|
97
|
+
- The server accepts only `SELECT` and `WITH ... SELECT`, rejects comments and
|
|
98
|
+
multi-statement input, and records audit logs for each call.
|
|
99
|
+
|
|
100
|
+
For MySQL, `explain_query(..., analyze=True)` is not available in the current
|
|
101
|
+
implementation.
|
|
102
|
+
|
|
103
|
+
## Quick start
|
|
104
|
+
|
|
105
|
+
If you want to get the server running first and explore the rest later, follow
|
|
106
|
+
these steps.
|
|
107
|
+
|
|
108
|
+
1. Create a virtual environment and install the project.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python3.10 -m venv .venv
|
|
112
|
+
source .venv/bin/activate
|
|
113
|
+
python -m pip install --upgrade pip
|
|
114
|
+
pip install sql-query-mcp
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Install a specific release with `pip install sql-query-mcp==X.Y.Z` if you want
|
|
118
|
+
to pin a version. Published release artifacts are also attached to each GitHub
|
|
119
|
+
Release.
|
|
120
|
+
|
|
121
|
+
2. Copy the example connection config.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
cp config/connections.example.json config/connections.json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
3. Export your database DSNs as environment variables.
|
|
128
|
+
|
|
129
|
+
These example names match the copied `config/connections.example.json` file.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
export PG_CONN_CRM_PROD_MUQIAO_RO='postgresql://user:password@host:5432/dbname'
|
|
133
|
+
export MYSQL_CONN_CRM_PROD_MUQIAO_RO='mysql://user:password@host:3306/crm'
|
|
134
|
+
export SQL_QUERY_MCP_CONFIG='/absolute/path/to/sql-query-mcp/config/connections.json'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
4. Register the server in your MCP client.
|
|
138
|
+
|
|
139
|
+
- Codex: `docs/codex-setup.md` (Chinese)
|
|
140
|
+
- OpenCode: `docs/opencode-setup.md` (Chinese)
|
|
141
|
+
|
|
142
|
+
The console entry point is `sql-query-mcp`, which maps to
|
|
143
|
+
`sql_query_mcp.app:main`.
|
|
144
|
+
|
|
145
|
+
The PyPI install name is `sql-query-mcp`, and the Python package import path is
|
|
146
|
+
`sql_query_mcp`.
|
|
147
|
+
|
|
148
|
+
The default config path is `config/connections.json`. If you need a different
|
|
149
|
+
location, set `SQL_QUERY_MCP_CONFIG`.
|
|
150
|
+
|
|
151
|
+
The example config looks like this.
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"settings": {
|
|
156
|
+
"default_limit": 200,
|
|
157
|
+
"max_limit": 1000,
|
|
158
|
+
"audit_log_path": "logs/audit.jsonl"
|
|
159
|
+
},
|
|
160
|
+
"connections": [
|
|
161
|
+
{
|
|
162
|
+
"connection_id": "crm_prod_muqiao_ro",
|
|
163
|
+
"engine": "postgres",
|
|
164
|
+
"label": "CRM PostgreSQL production / Muqiao / read-only",
|
|
165
|
+
"env": "prod",
|
|
166
|
+
"tenant": "muqiao",
|
|
167
|
+
"role": "ro",
|
|
168
|
+
"dsn_env": "PG_CONN_CRM_PROD_MUQIAO_RO",
|
|
169
|
+
"enabled": true,
|
|
170
|
+
"default_schema": "public"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"connection_id": "crm_mysql_prod_muqiao_ro",
|
|
174
|
+
"engine": "mysql",
|
|
175
|
+
"label": "CRM MySQL production / Muqiao / read-only",
|
|
176
|
+
"env": "prod",
|
|
177
|
+
"tenant": "muqiao",
|
|
178
|
+
"role": "ro",
|
|
179
|
+
"dsn_env": "MYSQL_CONN_CRM_PROD_MUQIAO_RO",
|
|
180
|
+
"enabled": true,
|
|
181
|
+
"default_database": "crm"
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
If you want implementation details, setup guidance, or internal structure, use
|
|
190
|
+
these docs as your starting points.
|
|
191
|
+
|
|
192
|
+
- `docs/project-overview.md`: project goals, concepts, and code structure (Chinese)
|
|
193
|
+
- `docs/api-reference.md`: MCP tool reference (Chinese)
|
|
194
|
+
- `docs/codex-setup.md`: Codex setup steps (Chinese)
|
|
195
|
+
- `docs/opencode-setup.md`: OpenCode setup steps (Chinese)
|
|
196
|
+
- `docs/release-process.md`: PyPI and GitHub Release workflow (Chinese)
|
|
197
|
+
- `docs/git-workflow.md`: repository collaboration workflow (Chinese)
|
|
198
|
+
|
|
199
|
+
## Development
|
|
200
|
+
|
|
201
|
+
If you want to modify or verify the project locally, use this shortest path.
|
|
202
|
+
Editable install remains the development path, and the local environment still
|
|
203
|
+
requires Python 3.10+.
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
python3.10 -m venv .venv
|
|
207
|
+
source .venv/bin/activate
|
|
208
|
+
python -m pip install --upgrade pip
|
|
209
|
+
pip install -e .
|
|
210
|
+
PYTHONPATH=. python3 -m unittest discover -s tests
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The main entry point is `sql_query_mcp/app.py`. Core modules include:
|
|
214
|
+
|
|
215
|
+
- `sql_query_mcp/config.py`: config loading and validation
|
|
216
|
+
- `sql_query_mcp/validator.py`: read-only SQL validation
|
|
217
|
+
- `sql_query_mcp/introspection.py`: metadata inspection
|
|
218
|
+
- `sql_query_mcp/executor.py`: query execution and limits
|
|
219
|
+
- `sql_query_mcp/adapters/`: PostgreSQL and MySQL adapters
|
|
220
|
+
|
|
221
|
+
## Contributing
|
|
222
|
+
|
|
223
|
+
If you want to contribute or review the repository workflow, start with these
|
|
224
|
+
pages.
|
|
225
|
+
|
|
226
|
+
- `CONTRIBUTING.md`
|
|
227
|
+
- `docs/roadmap.md`
|
|
228
|
+
- `docs/git-workflow.md` (Chinese)
|
|
229
|
+
|
|
230
|
+
Run `PYTHONPATH=. python3 -m unittest discover -s tests` before you submit
|
|
231
|
+
changes.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
This project is released under the MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# sql-query-mcp
|
|
2
|
+
|
|
3
|
+
[中文版](README-zh.md)
|
|
4
|
+
|
|
5
|
+
A general-purpose MCP server that lets AI work with multiple databases within
|
|
6
|
+
clear boundaries.
|
|
7
|
+
|
|
8
|
+
## Current database support
|
|
9
|
+
|
|
10
|
+
| Database | Status | Current availability |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| PostgreSQL | Supported | Available today |
|
|
13
|
+
| MySQL | Supported | Available today |
|
|
14
|
+
| SQLite | Candidate | Not supported yet |
|
|
15
|
+
| SQL Server | Candidate | Not supported yet |
|
|
16
|
+
| ClickHouse | Candidate | Not supported yet |
|
|
17
|
+
|
|
18
|
+
## Product value
|
|
19
|
+
|
|
20
|
+
`sql-query-mcp` helps AI clients discover schema, sample data, and analyze
|
|
21
|
+
read-only queries through one controlled MCP interface.
|
|
22
|
+
|
|
23
|
+
It keeps connection handling, namespace rules, SQL validation, and audit
|
|
24
|
+
logging on the server side, so you can expose useful database context to AI
|
|
25
|
+
without exposing raw connection strings or flattening engine-specific concepts.
|
|
26
|
+
|
|
27
|
+
## What AI can do with it
|
|
28
|
+
|
|
29
|
+
The current tool set focuses on database discovery and controlled query
|
|
30
|
+
workflows. You can use it to help an AI assistant understand structure before
|
|
31
|
+
it generates or refines SQL.
|
|
32
|
+
|
|
33
|
+
MySQL supports `explain_query`, but not `explain_query(..., analyze=True)` in
|
|
34
|
+
the current implementation.
|
|
35
|
+
|
|
36
|
+
| Tool | PostgreSQL | MySQL | Purpose |
|
|
37
|
+
| --- | --- | --- | --- |
|
|
38
|
+
| `list_connections()` | Yes | Yes | List configured connections |
|
|
39
|
+
| `list_schemas(connection_id)` | Yes | No | List visible PostgreSQL schemas |
|
|
40
|
+
| `list_databases(connection_id)` | No | Yes | List visible MySQL databases |
|
|
41
|
+
| `list_tables(connection_id, schema?, database?)` | Yes | Yes | List tables and views |
|
|
42
|
+
| `describe_table(connection_id, table_name, schema?, database?)` | Yes | Yes | Inspect columns, keys, and indexes |
|
|
43
|
+
| `run_select(connection_id, sql, limit?)` | Yes | Yes | Run read-only queries |
|
|
44
|
+
| `explain_query(connection_id, sql, analyze?)` | Yes | Yes | Inspect query plans |
|
|
45
|
+
| `get_table_sample(connection_id, table_name, schema?, database?, limit?)` | Yes | Yes | Fetch small table samples |
|
|
46
|
+
|
|
47
|
+
These tools are useful for tasks such as listing namespaces, inspecting table
|
|
48
|
+
definitions, reviewing indexes, sampling records, and analyzing read-only
|
|
49
|
+
queries with `EXPLAIN`. For full request and response details, see
|
|
50
|
+
`docs/api-reference.md` (Chinese).
|
|
51
|
+
|
|
52
|
+
## How boundaries are constrained
|
|
53
|
+
|
|
54
|
+
The product boundary is intentionally narrow today. Only PostgreSQL and MySQL
|
|
55
|
+
are available today, and the current tool set is fully read-only.
|
|
56
|
+
|
|
57
|
+
The service keeps those boundaries explicit in a few ways.
|
|
58
|
+
|
|
59
|
+
- Connections declare `engine` explicitly, so the server never guesses from
|
|
60
|
+
`connection_id`.
|
|
61
|
+
- PostgreSQL uses `schema`, and MySQL uses `database`, without collapsing both
|
|
62
|
+
into one vague namespace field.
|
|
63
|
+
- Real DSNs stay in environment variables, while config files store only the
|
|
64
|
+
environment variable names.
|
|
65
|
+
- Query execution passes through `sqlglot` validation before reaching the
|
|
66
|
+
database.
|
|
67
|
+
- The server accepts only `SELECT` and `WITH ... SELECT`, rejects comments and
|
|
68
|
+
multi-statement input, and records audit logs for each call.
|
|
69
|
+
|
|
70
|
+
For MySQL, `explain_query(..., analyze=True)` is not available in the current
|
|
71
|
+
implementation.
|
|
72
|
+
|
|
73
|
+
## Quick start
|
|
74
|
+
|
|
75
|
+
If you want to get the server running first and explore the rest later, follow
|
|
76
|
+
these steps.
|
|
77
|
+
|
|
78
|
+
1. Create a virtual environment and install the project.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python3.10 -m venv .venv
|
|
82
|
+
source .venv/bin/activate
|
|
83
|
+
python -m pip install --upgrade pip
|
|
84
|
+
pip install sql-query-mcp
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Install a specific release with `pip install sql-query-mcp==X.Y.Z` if you want
|
|
88
|
+
to pin a version. Published release artifacts are also attached to each GitHub
|
|
89
|
+
Release.
|
|
90
|
+
|
|
91
|
+
2. Copy the example connection config.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cp config/connections.example.json config/connections.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
3. Export your database DSNs as environment variables.
|
|
98
|
+
|
|
99
|
+
These example names match the copied `config/connections.example.json` file.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
export PG_CONN_CRM_PROD_MUQIAO_RO='postgresql://user:password@host:5432/dbname'
|
|
103
|
+
export MYSQL_CONN_CRM_PROD_MUQIAO_RO='mysql://user:password@host:3306/crm'
|
|
104
|
+
export SQL_QUERY_MCP_CONFIG='/absolute/path/to/sql-query-mcp/config/connections.json'
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
4. Register the server in your MCP client.
|
|
108
|
+
|
|
109
|
+
- Codex: `docs/codex-setup.md` (Chinese)
|
|
110
|
+
- OpenCode: `docs/opencode-setup.md` (Chinese)
|
|
111
|
+
|
|
112
|
+
The console entry point is `sql-query-mcp`, which maps to
|
|
113
|
+
`sql_query_mcp.app:main`.
|
|
114
|
+
|
|
115
|
+
The PyPI install name is `sql-query-mcp`, and the Python package import path is
|
|
116
|
+
`sql_query_mcp`.
|
|
117
|
+
|
|
118
|
+
The default config path is `config/connections.json`. If you need a different
|
|
119
|
+
location, set `SQL_QUERY_MCP_CONFIG`.
|
|
120
|
+
|
|
121
|
+
The example config looks like this.
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"settings": {
|
|
126
|
+
"default_limit": 200,
|
|
127
|
+
"max_limit": 1000,
|
|
128
|
+
"audit_log_path": "logs/audit.jsonl"
|
|
129
|
+
},
|
|
130
|
+
"connections": [
|
|
131
|
+
{
|
|
132
|
+
"connection_id": "crm_prod_muqiao_ro",
|
|
133
|
+
"engine": "postgres",
|
|
134
|
+
"label": "CRM PostgreSQL production / Muqiao / read-only",
|
|
135
|
+
"env": "prod",
|
|
136
|
+
"tenant": "muqiao",
|
|
137
|
+
"role": "ro",
|
|
138
|
+
"dsn_env": "PG_CONN_CRM_PROD_MUQIAO_RO",
|
|
139
|
+
"enabled": true,
|
|
140
|
+
"default_schema": "public"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"connection_id": "crm_mysql_prod_muqiao_ro",
|
|
144
|
+
"engine": "mysql",
|
|
145
|
+
"label": "CRM MySQL production / Muqiao / read-only",
|
|
146
|
+
"env": "prod",
|
|
147
|
+
"tenant": "muqiao",
|
|
148
|
+
"role": "ro",
|
|
149
|
+
"dsn_env": "MYSQL_CONN_CRM_PROD_MUQIAO_RO",
|
|
150
|
+
"enabled": true,
|
|
151
|
+
"default_database": "crm"
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Documentation
|
|
158
|
+
|
|
159
|
+
If you want implementation details, setup guidance, or internal structure, use
|
|
160
|
+
these docs as your starting points.
|
|
161
|
+
|
|
162
|
+
- `docs/project-overview.md`: project goals, concepts, and code structure (Chinese)
|
|
163
|
+
- `docs/api-reference.md`: MCP tool reference (Chinese)
|
|
164
|
+
- `docs/codex-setup.md`: Codex setup steps (Chinese)
|
|
165
|
+
- `docs/opencode-setup.md`: OpenCode setup steps (Chinese)
|
|
166
|
+
- `docs/release-process.md`: PyPI and GitHub Release workflow (Chinese)
|
|
167
|
+
- `docs/git-workflow.md`: repository collaboration workflow (Chinese)
|
|
168
|
+
|
|
169
|
+
## Development
|
|
170
|
+
|
|
171
|
+
If you want to modify or verify the project locally, use this shortest path.
|
|
172
|
+
Editable install remains the development path, and the local environment still
|
|
173
|
+
requires Python 3.10+.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
python3.10 -m venv .venv
|
|
177
|
+
source .venv/bin/activate
|
|
178
|
+
python -m pip install --upgrade pip
|
|
179
|
+
pip install -e .
|
|
180
|
+
PYTHONPATH=. python3 -m unittest discover -s tests
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The main entry point is `sql_query_mcp/app.py`. Core modules include:
|
|
184
|
+
|
|
185
|
+
- `sql_query_mcp/config.py`: config loading and validation
|
|
186
|
+
- `sql_query_mcp/validator.py`: read-only SQL validation
|
|
187
|
+
- `sql_query_mcp/introspection.py`: metadata inspection
|
|
188
|
+
- `sql_query_mcp/executor.py`: query execution and limits
|
|
189
|
+
- `sql_query_mcp/adapters/`: PostgreSQL and MySQL adapters
|
|
190
|
+
|
|
191
|
+
## Contributing
|
|
192
|
+
|
|
193
|
+
If you want to contribute or review the repository workflow, start with these
|
|
194
|
+
pages.
|
|
195
|
+
|
|
196
|
+
- `CONTRIBUTING.md`
|
|
197
|
+
- `docs/roadmap.md`
|
|
198
|
+
- `docs/git-workflow.md` (Chinese)
|
|
199
|
+
|
|
200
|
+
Run `PYTHONPATH=. python3 -m unittest discover -s tests` before you submit
|
|
201
|
+
changes.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
This project is released under the MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sql-query-mcp"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Read-only SQL MCP server for PostgreSQL and MySQL."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Andy Wang" }]
|
|
14
|
+
keywords = ["mcp", "mcp-server", "sql", "database", "postgresql", "mysql", "cli", "codex", "chatgpt"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Database",
|
|
23
|
+
"Environment :: Console",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"mcp>=1.12.4",
|
|
27
|
+
"PyMySQL>=1.1",
|
|
28
|
+
"psycopg[binary]>=3.2",
|
|
29
|
+
"psycopg-pool>=3.2",
|
|
30
|
+
"sqlglot>=25.20.2",
|
|
31
|
+
"tomli>=2; python_version < '3.11'",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/andyWang1688/sql-query-mcp"
|
|
36
|
+
Repository = "https://github.com/andyWang1688/sql-query-mcp"
|
|
37
|
+
Documentation = "https://github.com/andyWang1688/sql-query-mcp/blob/main/README.md"
|
|
38
|
+
Issues = "https://github.com/andyWang1688/sql-query-mcp/issues"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
sql-query-mcp = "sql_query_mcp.app:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["."]
|
|
45
|
+
include = ["sql_query_mcp*"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Engine adapters for sql-query-mcp."""
|
|
2
|
+
|
|
3
|
+
__all__ = ["MySQLAdapter", "PostgresAdapter"]
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def __getattr__(name: str):
|
|
7
|
+
if name == "MySQLAdapter":
|
|
8
|
+
from .mysql import MySQLAdapter
|
|
9
|
+
|
|
10
|
+
return MySQLAdapter
|
|
11
|
+
if name == "PostgresAdapter":
|
|
12
|
+
from .postgres import PostgresAdapter
|
|
13
|
+
|
|
14
|
+
return PostgresAdapter
|
|
15
|
+
raise AttributeError(name)
|