sqlprism 1.0.0__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.
- sqlprism/__init__.py +1 -0
- sqlprism/cli.py +625 -0
- sqlprism/core/__init__.py +0 -0
- sqlprism/core/graph.py +1547 -0
- sqlprism/core/indexer.py +677 -0
- sqlprism/core/mcp_tools.py +982 -0
- sqlprism/languages/__init__.py +28 -0
- sqlprism/languages/dbt.py +199 -0
- sqlprism/languages/sql.py +1031 -0
- sqlprism/languages/sqlmesh.py +203 -0
- sqlprism/languages/utils.py +73 -0
- sqlprism/types.py +190 -0
- sqlprism-1.0.0.dist-info/METADATA +429 -0
- sqlprism-1.0.0.dist-info/RECORD +17 -0
- sqlprism-1.0.0.dist-info/WHEEL +4 -0
- sqlprism-1.0.0.dist-info/entry_points.txt +2 -0
- sqlprism-1.0.0.dist-info/licenses/LICENSE +190 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlprism
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: SQL codebase indexer with column-level lineage, impact analysis, and MCP server support
|
|
5
|
+
Project-URL: Homepage, https://github.com/darkcofy/sqlprism
|
|
6
|
+
Project-URL: Documentation, https://darkcofy.github.io/sqlprism/
|
|
7
|
+
Project-URL: Repository, https://github.com/darkcofy/sqlprism
|
|
8
|
+
Project-URL: Issues, https://github.com/darkcofy/sqlprism/issues
|
|
9
|
+
Author-email: Alfred Johnson <alfjohnfred@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: click>=8.0.0
|
|
22
|
+
Requires-Dist: duckdb>=1.5.0
|
|
23
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
24
|
+
Requires-Dist: pydantic>=2.0.0
|
|
25
|
+
Requires-Dist: sqlglot<30,>=28.0.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# SQLPrism
|
|
29
|
+
|
|
30
|
+
[](https://github.com/darkcofy/sqlprism/actions/workflows/ci.yml)
|
|
31
|
+
[](https://codecov.io/gh/darkcofy/sqlprism)
|
|
32
|
+
[](https://pypi.org/project/sqlprism/)
|
|
33
|
+
[](https://pypi.org/project/sqlprism/)
|
|
34
|
+
[](LICENSE)
|
|
35
|
+
[](https://darkcofy.github.io/sqlprism/)
|
|
36
|
+
|
|
37
|
+
An MCP server that indexes SQL codebases into a queryable knowledge graph backed by DuckDB. Instead of grepping through files, ask structural questions: *what touches this table, where is this column transformed, what's the blast radius of this PR.*
|
|
38
|
+
|
|
39
|
+
Built for SQL-heavy data projects — works with raw SQL, [SQLMesh](https://sqlmesh.com/), and [dbt](https://www.getdbt.com/).
|
|
40
|
+
|
|
41
|
+
## Why Not Just Grep?
|
|
42
|
+
|
|
43
|
+
Grep finds strings. This tool understands SQL structure.
|
|
44
|
+
|
|
45
|
+
| Capability | Grep | SQLPrism |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Find table references | Yes | Yes |
|
|
48
|
+
| CTE-to-CTE data flow | No — manual file reading | Yes — edges tracked in graph |
|
|
49
|
+
| Column lineage with transforms (CAST, COALESCE, SUM) | No | Yes — parsed from AST |
|
|
50
|
+
| Usage type (WHERE vs SELECT vs JOIN vs GROUP BY) | Fragile regex | Precise — parsed from AST |
|
|
51
|
+
| Multi-hop impact analysis | Manual tracing | Automatic graph traversal |
|
|
52
|
+
| PR blast radius | DIY with git diff | One call |
|
|
53
|
+
| Cross-CTE column tracing | Basically impossible | Built-in |
|
|
54
|
+
|
|
55
|
+
On a 200-model SQLMesh project, a column impact query returns **75 structured results in ~5,000 tokens**. The grep equivalent would need **40-60 files opened, ~100,000+ tokens**, and still wouldn't tell you whether a column appears in a WHERE filter or a SELECT.
|
|
56
|
+
|
|
57
|
+
## What's New in v1.0
|
|
58
|
+
|
|
59
|
+
- **Non-blocking reindex** — reindex runs in the background; queries remain available during indexing via DuckDB MVCC. Call `index_status` to check progress.
|
|
60
|
+
- **PR Impact delta mode** — `pr_impact` now shows *net-new* blast radius vs the base branch (default), not just total downstream. New fields: `newly_affected`, `no_longer_affected`, `delta`. Note: delta mode captures net-new downstream impact; reduced blast radius from removed edges is not detected.
|
|
61
|
+
- **Thread-safe concurrency** — `asyncio.Lock` on reindex guard, atomic status updates, `threading.local` for transaction flags. Safe under both stdio and HTTP transports.
|
|
62
|
+
- **SELECT \* lineage for dbt/sqlmesh** — schema catalog is passed to dbt and sqlmesh renderers, enabling column expansion through `SELECT *` statements.
|
|
63
|
+
- **Input validation** — `compare_mode`, `direction`, and other string parameters use `Literal` types with Pydantic, rejecting invalid values at the API boundary.
|
|
64
|
+
- **Logging** — `--log-level` global CLI option. `serve` defaults to INFO for production visibility.
|
|
65
|
+
- **File error resilience** — unreadable files are skipped instead of aborting the entire reindex.
|
|
66
|
+
- **Code coverage** — 82%+ line coverage with 235 tests enforced via pytest-cov.
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
### From source (local development)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git clone https://github.com/darkcofy/sqlprism.git && cd sqlprism
|
|
74
|
+
|
|
75
|
+
# Install dependencies and the package
|
|
76
|
+
uv sync
|
|
77
|
+
|
|
78
|
+
# Create config
|
|
79
|
+
uv run sqlprism init
|
|
80
|
+
|
|
81
|
+
# Edit ~/.sqlprism/config.json (see Configuration below)
|
|
82
|
+
|
|
83
|
+
# Index your repos
|
|
84
|
+
uv run sqlprism reindex
|
|
85
|
+
|
|
86
|
+
# Start the MCP server
|
|
87
|
+
uv run sqlprism serve
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
All commands use `uv run sqlprism` to run within the project's virtualenv. If you activate the venv (`source .venv/bin/activate`), you can drop the `uv run` prefix.
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
`sqlprism init` creates a default config at `~/.sqlprism/config.json`. You can override the path with `--config PATH` on any command.
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"db_path": "~/.sqlprism/graph.duckdb",
|
|
99
|
+
"sql_dialect": null,
|
|
100
|
+
"repos": {
|
|
101
|
+
"my-queries": "/path/to/sql/repo",
|
|
102
|
+
"multi-dialect-repo": {
|
|
103
|
+
"path": "/path/to/repo",
|
|
104
|
+
"dialect": "starrocks",
|
|
105
|
+
"dialect_overrides": {
|
|
106
|
+
"athena/": "athena",
|
|
107
|
+
"postgres/": "postgres"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"sqlmesh_repos": {
|
|
112
|
+
"my-sqlmesh-project": {
|
|
113
|
+
"project_path": "/path/to/sqlmesh/folder",
|
|
114
|
+
"env_file": "/path/to/.env",
|
|
115
|
+
"dialect": "athena",
|
|
116
|
+
"variables": {
|
|
117
|
+
"GRACE_PERIOD": 7
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"dbt_repos": {
|
|
122
|
+
"my-dbt-project": {
|
|
123
|
+
"project_path": "/path/to/dbt/project",
|
|
124
|
+
"env_file": "/path/to/.env",
|
|
125
|
+
"target": "dev",
|
|
126
|
+
"dialect": "starrocks",
|
|
127
|
+
"dbt_command": "uv run dbt"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Field | Description |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `db_path` | Path to the DuckDB database file. Defaults to `~/.sqlprism/graph.duckdb`. |
|
|
136
|
+
| `sql_dialect` | Global default SQL dialect. `null` for auto-detect. |
|
|
137
|
+
| `repos` | Plain SQL repos. Value is a path string or an object with `path`, `dialect`, `dialect_overrides`. |
|
|
138
|
+
| `dialect` | Per-repo dialect override (e.g. `"starrocks"`, `"athena"`, `"bigquery"`). |
|
|
139
|
+
| `dialect_overrides` | Per-directory overrides using prefix matching or glob patterns. |
|
|
140
|
+
| `sqlmesh_repos` | SQLMesh projects. Renders models before parsing. See [SQLMesh and dbt Support](#sqlmesh-and-dbt-support). |
|
|
141
|
+
| `dbt_repos` | dbt projects. Compiles models before parsing. See [SQLMesh and dbt Support](#sqlmesh-and-dbt-support). |
|
|
142
|
+
|
|
143
|
+
## SQL Dialect Support
|
|
144
|
+
|
|
145
|
+
Powered by [sqlglot](https://github.com/tobymao/sqlglot), the indexer supports **33 SQL dialects** out of the box:
|
|
146
|
+
|
|
147
|
+
| Dialect | Dialect | Dialect | Dialect |
|
|
148
|
+
|---|---|---|---|
|
|
149
|
+
| Athena | Doris | Materialize | Snowflake |
|
|
150
|
+
| BigQuery | Dremio | MySQL | Spark |
|
|
151
|
+
| ClickHouse | Drill | Oracle | Spark2 |
|
|
152
|
+
| Databricks | Druid | Postgres | SQLite |
|
|
153
|
+
| DuckDB | Dune | Presto | StarRocks |
|
|
154
|
+
| Exasol | Fabric | PRQL | Tableau |
|
|
155
|
+
| Hive | | Redshift | Teradata |
|
|
156
|
+
| RisingWave | | SingleStore | Trino / TSQL |
|
|
157
|
+
|
|
158
|
+
Pass the dialect name as a lowercase string (e.g., `"starrocks"`, `"bigquery"`, `"athena"`). Dialect-specific quoting (backticks for MySQL/StarRocks, double-quotes for Postgres) and identifier case normalization (lowercase for Postgres/DuckDB, uppercase for Snowflake/Oracle) are handled automatically.
|
|
159
|
+
|
|
160
|
+
## SQLMesh and dbt Support
|
|
161
|
+
|
|
162
|
+
Both SQLMesh and dbt use macros/Jinja that can't be parsed as raw SQL. The indexer solves this by rendering models first, then parsing the clean SQL output.
|
|
163
|
+
|
|
164
|
+
Both renderers use subprocess execution — no SQLMesh or dbt Python dependencies are required in the indexer's environment. They use whatever version the project already has installed.
|
|
165
|
+
|
|
166
|
+
### SQLMesh
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
sqlprism reindex-sqlmesh \
|
|
170
|
+
--name my-project \
|
|
171
|
+
--project /path/to/sqlmesh/project \
|
|
172
|
+
--dialect athena \
|
|
173
|
+
--env-file /path/to/.env \
|
|
174
|
+
--var GRACE_PERIOD 7
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
| Parameter | Required | Description |
|
|
178
|
+
|---|---|---|
|
|
179
|
+
| `--name` | Yes | Repo name used in the index. Used to filter queries later. |
|
|
180
|
+
| `--project` | Yes | Path to the sqlmesh project directory (containing `config.yaml`). |
|
|
181
|
+
| `--dialect` | No | SQL dialect for rendering output. Default: `athena`. |
|
|
182
|
+
| `--env-file` | No | Path to `.env` file. Variables are loaded into the subprocess environment before rendering. Useful for connection strings, S3 paths, etc. |
|
|
183
|
+
| `--var` | No | SQLMesh macro variables as key-value pairs. Repeatable. e.g. `--var GRACE_PERIOD 7 --var ENV prod`. These override variables defined in `config.yaml`. |
|
|
184
|
+
| `--sqlmesh-command` | No | Command to run python in the sqlmesh project's venv. The indexer runs an inline script that imports sqlmesh's Python API. Default: `uv run python`. |
|
|
185
|
+
| `--config` | No | Path to sqlprism config file. Default: `~/.sqlprism/config.json`. |
|
|
186
|
+
| `--db` | No | Path to DuckDB file. Overrides the value in config. |
|
|
187
|
+
|
|
188
|
+
### dbt
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
sqlprism reindex-dbt \
|
|
192
|
+
--name my-project \
|
|
193
|
+
--project /path/to/dbt/project \
|
|
194
|
+
--dialect starrocks \
|
|
195
|
+
--env-file /path/to/.env \
|
|
196
|
+
--target dev
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
| Parameter | Required | Description |
|
|
200
|
+
|---|---|---|
|
|
201
|
+
| `--name` | Yes | Repo name used in the index. |
|
|
202
|
+
| `--project` | Yes | Path to dbt project directory (containing `dbt_project.yml`). |
|
|
203
|
+
| `--dialect` | No | SQL dialect for parsing the compiled output (e.g. `starrocks`, `postgres`, `bigquery`). |
|
|
204
|
+
| `--env-file` | No | Path to `.env` file for dbt connection variables. |
|
|
205
|
+
| `--target` | No | dbt target name (e.g. `dev`, `prod`). Maps to the target in `profiles.yml`. |
|
|
206
|
+
| `--profiles-dir` | No | Path to directory containing `profiles.yml`. Defaults to the project directory. |
|
|
207
|
+
| `--dbt-command` | No | Base command to invoke dbt. `compile` is appended automatically. Default: `uv run dbt`. Use `dbt` if globally installed, or `uvx --with dbt-starrocks dbt` for ephemeral install. |
|
|
208
|
+
| `--config` | No | Path to sqlprism config file. |
|
|
209
|
+
| `--db` | No | Path to DuckDB file. Overrides config. |
|
|
210
|
+
|
|
211
|
+
## CLI Commands
|
|
212
|
+
|
|
213
|
+
> **Global option:** `--log-level` sets logging verbosity (default: `WARNING`). The `serve` command defaults to `INFO`.
|
|
214
|
+
|
|
215
|
+
### `sqlprism init`
|
|
216
|
+
|
|
217
|
+
Creates a default config file at `~/.sqlprism/config.json` with example entries for repos, sqlmesh_repos, and dbt_repos.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
sqlprism init [--config PATH]
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### `sqlprism reindex`
|
|
224
|
+
|
|
225
|
+
Incremental reindex of all configured plain SQL repos (from `repos` in config). Checksums files and only re-parses what changed.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
sqlprism reindex [--config PATH] [--db PATH] [--repo NAME]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
| Parameter | Description |
|
|
232
|
+
|---|---|
|
|
233
|
+
| `--repo` | Reindex a single repo only. Omit to reindex all. |
|
|
234
|
+
|
|
235
|
+
### `sqlprism serve`
|
|
236
|
+
|
|
237
|
+
Starts the MCP server. Exposes all 10 tools to any MCP client.
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
sqlprism [--log-level DEBUG|INFO|WARNING|ERROR] serve [--config PATH] [--db PATH] [--transport stdio|streamable_http] [--port 8000]
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
| Parameter | Default | Description |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| `--transport` | `stdio` | Transport mode. Use `stdio` for Claude Code / Claude Desktop. Use `streamable_http` for web-based clients. |
|
|
246
|
+
| `--port` | `8000` | Port for HTTP transport. Only used when `--transport streamable_http`. |
|
|
247
|
+
|
|
248
|
+
### `sqlprism status`
|
|
249
|
+
|
|
250
|
+
Shows index status: repos, file counts, node counts, last indexed time, git commit/branch.
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
sqlprism status [--config PATH] [--db PATH]
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## CLI Query Commands
|
|
257
|
+
|
|
258
|
+
All query commands output JSON to stdout. They share common parameters:
|
|
259
|
+
|
|
260
|
+
| Parameter | Description |
|
|
261
|
+
|---|---|
|
|
262
|
+
| `--config PATH` | Path to config file. Default: `~/.sqlprism/config.json`. |
|
|
263
|
+
| `--db PATH` | Path to DuckDB file. Overrides config. |
|
|
264
|
+
| `--repo TEXT` | Filter results by repo name. Omit to query across all repos. |
|
|
265
|
+
|
|
266
|
+
### `sqlprism query search`
|
|
267
|
+
|
|
268
|
+
Find tables, views, CTEs, and queries by name pattern (case-insensitive partial match).
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
sqlprism query search PATTERN [--kind KIND] [--schema SCHEMA] [--repo REPO] [--limit 20]
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
| Parameter | Description |
|
|
275
|
+
|---|---|
|
|
276
|
+
| `PATTERN` | Search string. Matches against node names (partial, case-insensitive). |
|
|
277
|
+
| `--kind` | Filter by node kind: `table`, `view`, `cte`, `query`. |
|
|
278
|
+
| `--schema` | Filter by SQL schema name (e.g. `bronze`, `silver`, `public`). |
|
|
279
|
+
| `--limit` | Max results to return. Default: `20`. |
|
|
280
|
+
|
|
281
|
+
### `sqlprism query references`
|
|
282
|
+
|
|
283
|
+
Find what depends on an entity (inbound) and what it depends on (outbound).
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
sqlprism query references NAME [--direction both|inbound|outbound] [--kind KIND] [--schema SCHEMA] [--repo REPO]
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
| Parameter | Description |
|
|
290
|
+
|---|---|
|
|
291
|
+
| `NAME` | Entity name (table, view, CTE, etc.). |
|
|
292
|
+
| `--direction` | `inbound` (what depends on this), `outbound` (what this depends on), or `both`. Default: `both`. |
|
|
293
|
+
| `--kind` | Filter by node kind to disambiguate if the name exists as multiple kinds. |
|
|
294
|
+
| `--schema` | Filter by SQL schema name. |
|
|
295
|
+
|
|
296
|
+
### `sqlprism query column-usage`
|
|
297
|
+
|
|
298
|
+
Find where and how a table's columns are used across the codebase.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
sqlprism query column-usage TABLE [--column COL] [--usage-type TYPE] [--repo REPO]
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
| Parameter | Description |
|
|
305
|
+
|---|---|
|
|
306
|
+
| `TABLE` | Table name to search column usage for. |
|
|
307
|
+
| `--column` | Filter by specific column name. Omit for all columns. |
|
|
308
|
+
| `--usage-type` | Filter by usage type: `select`, `where`, `join_on`, `group_by`, `order_by`, `having`, `partition_by`, `window_order`, `insert`, `update`. |
|
|
309
|
+
|
|
310
|
+
Each result includes: table, column, usage type, alias, transform expression, the node/CTE it appears in, file path, and repo.
|
|
311
|
+
|
|
312
|
+
### `sqlprism query trace`
|
|
313
|
+
|
|
314
|
+
Multi-hop dependency tracing for impact analysis.
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
sqlprism query trace NAME [--direction downstream|upstream|both] [--max-depth 3] [--kind KIND] [--repo REPO]
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
| Parameter | Description |
|
|
321
|
+
|---|---|
|
|
322
|
+
| `NAME` | Starting entity name. |
|
|
323
|
+
| `--direction` | `downstream` (what breaks if I change this), `upstream` (what does this depend on), or `both`. Default: `downstream`. |
|
|
324
|
+
| `--max-depth` | Maximum hops to traverse. Default: `3`, max: `6`. Higher values find more transitive dependencies but produce larger results. |
|
|
325
|
+
| `--kind` | Filter by node kind to disambiguate. |
|
|
326
|
+
|
|
327
|
+
### `sqlprism query lineage`
|
|
328
|
+
|
|
329
|
+
Query end-to-end column lineage chains through CTEs and subqueries.
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
sqlprism query lineage [--table TABLE] [--column COL] [--output-node NODE] [--repo REPO]
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
| Parameter | Description |
|
|
336
|
+
|---|---|
|
|
337
|
+
| `--table` | Filter by source or intermediate table name in the lineage chain. |
|
|
338
|
+
| `--column` | Filter by column name at any hop in the chain. |
|
|
339
|
+
| `--output-node` | Filter by the output entity name (the final table/view/query the lineage flows into). |
|
|
340
|
+
|
|
341
|
+
At least one of `--table`, `--column`, or `--output-node` should be provided to avoid returning the entire lineage graph.
|
|
342
|
+
|
|
343
|
+
## MCP Tools
|
|
344
|
+
|
|
345
|
+
When running as an MCP server (`sqlprism serve`), the following 10 tools are exposed. These are the same queries as the CLI but with additional parameters like `offset` for pagination and `include_snippets` for source code context.
|
|
346
|
+
|
|
347
|
+
| Tool | Description |
|
|
348
|
+
|---|---|
|
|
349
|
+
| `search` | Find tables, views, CTEs, queries by name pattern. Filter by kind, schema, repo. Supports `limit` and `offset` for pagination. |
|
|
350
|
+
| `find_references` | What depends on X / what does X depend on. Supports `direction` (inbound/outbound/both), `limit`, `offset`. |
|
|
351
|
+
| `find_column_usage` | Where and how columns are used — usage type, transforms, aliases. Supports `limit`, `offset`. |
|
|
352
|
+
| `trace_dependencies` | Multi-hop upstream/downstream dependency chains. `max_depth` (1-6), `include_snippets`. |
|
|
353
|
+
| `trace_column_lineage` | End-to-end column lineage through CTEs and subqueries. Filter by `table`, `column`, `output_node`. |
|
|
354
|
+
| `pr_impact` | Structural diff + blast radius since a `base_commit`. **Delta mode** (default) shows net-new impact vs base branch. `absolute` mode returns total blast radius (v1 behavior). Traces `max_blast_radius_depth` hops. |
|
|
355
|
+
| `reindex` | Trigger incremental reindex of plain SQL repos. **Runs in background** — returns immediately, queries remain available during reindex. Call `index_status` to check progress. |
|
|
356
|
+
| `reindex_sqlmesh` | Render and index a SQLMesh project. **Runs in background.** Pass `variables` as a dict for macro variables. |
|
|
357
|
+
| `reindex_dbt` | Compile and index a dbt project. **Runs in background.** Pass `target`, `dialect`, `profiles_dir`. |
|
|
358
|
+
| `index_status` | Repos, file counts, node counts, last commit, staleness. **Includes reindex progress** when a background reindex is running. |
|
|
359
|
+
|
|
360
|
+
### MCP Tool Parameters
|
|
361
|
+
|
|
362
|
+
**Pagination** — `search`, `find_references`, `find_column_usage`, and `trace_column_lineage` all support:
|
|
363
|
+
- `limit`: Max results to return (default varies by tool, max 100-500).
|
|
364
|
+
- `offset`: Number of results to skip. Use for paginating through large result sets.
|
|
365
|
+
|
|
366
|
+
**Snippets** — `search`, `find_references`, and `trace_dependencies` support:
|
|
367
|
+
- `include_snippets`: Include source code snippets in results. Default `true` for search/references, `false` for trace (which can produce large output).
|
|
368
|
+
|
|
369
|
+
## MCP Client Configuration
|
|
370
|
+
|
|
371
|
+
### Claude Code
|
|
372
|
+
```bash
|
|
373
|
+
claude mcp add sqlprism -- uv run --directory /path/to/sqlprism sqlprism serve
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Claude Desktop / Cursor / Continue.dev (`.mcp.json`)
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"mcpServers": {
|
|
380
|
+
"sqlprism": {
|
|
381
|
+
"command": "uv",
|
|
382
|
+
"args": ["run", "--directory", "/path/to/sqlprism", "sqlprism", "serve"]
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Replace `/path/to/sqlprism` with the absolute path to your clone of this repo.
|
|
389
|
+
|
|
390
|
+
## Architecture
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
src/sqlprism/
|
|
394
|
+
types.py <- ParseResult, NodeResult, EdgeResult, ColumnUsageResult, parse_repo_config
|
|
395
|
+
languages/
|
|
396
|
+
__init__.py <- SQL_EXTENSIONS, is_sql_file()
|
|
397
|
+
sql.py <- sqlglot: tables, views, CTEs, column lineage, transforms
|
|
398
|
+
sqlmesh.py <- SQLMesh model renderer (subprocess)
|
|
399
|
+
dbt.py <- dbt model renderer (subprocess)
|
|
400
|
+
utils.py <- Shared helpers (find_venv_dir, parse_dotenv, build_env, enrich_nodes)
|
|
401
|
+
core/
|
|
402
|
+
graph.py <- DuckDB schema (v8), read/write separation (MVCC), queries, snippets
|
|
403
|
+
indexer.py <- Orchestrator: scan -> checksum -> parse -> store (per-file error resilience)
|
|
404
|
+
mcp_tools.py <- FastMCP tool definitions (10 tools, non-blocking reindex)
|
|
405
|
+
cli.py <- Click CLI with --log-level: serve, reindex, reindex-sqlmesh, reindex-dbt, status, init
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
The SQL parser extracts:
|
|
409
|
+
- **Nodes**: tables, views, CTEs, queries (with schema metadata and dialect-aware case normalization)
|
|
410
|
+
- **Edges**: table references, CTE references, JOINs (with context like "FROM clause", "JOIN clause")
|
|
411
|
+
- **Column usage**: per-column tracking with usage type (select, where, join_on, group_by, order_by, having, partition_by, window_order), transforms (CAST, COALESCE, SUM, etc.), output aliases, and WHERE filter expressions
|
|
412
|
+
- **Column lineage**: end-to-end tracing through CTEs and subqueries back to source tables, with SELECT * expansion when schema catalog is available
|
|
413
|
+
|
|
414
|
+
## Development
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
uv sync
|
|
418
|
+
uv run pytest # run tests (235 tests)
|
|
419
|
+
uv run pytest --cov=sqlprism # run with coverage report
|
|
420
|
+
uv run pytest --cov=sqlprism --cov-report=html:coverage_html # HTML report
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Code Coverage
|
|
424
|
+
|
|
425
|
+

|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
Apache License 2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
sqlprism/__init__.py,sha256=D6XgcTFrKGMFOcoPF-JJTxLa2yvW79lQ3NEqvDzfRYg,64
|
|
2
|
+
sqlprism/cli.py,sha256=4U1dDg6VImNR13GqN4BSyBFqT0eNDCVlUtzKzEciVWI,19958
|
|
3
|
+
sqlprism/types.py,sha256=plUN7dJFZcJQG_S3YtmwiJvIYYGHg2FMwZMFqT9RZ1k,7303
|
|
4
|
+
sqlprism/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
sqlprism/core/graph.py,sha256=zfPd9jU6A58wI9lW_WwfiSBR229VWNLNKzyMpIV-rXo,59217
|
|
6
|
+
sqlprism/core/indexer.py,sha256=4Wi1IYEimBIpfuwZZUmKpSIReSQ3TrfXgQf9u-lOgNc,26404
|
|
7
|
+
sqlprism/core/mcp_tools.py,sha256=_CgzHY9Yflobp9uPAJM_9vsWp5V0ptoHd4t46am0MLk,35485
|
|
8
|
+
sqlprism/languages/__init__.py,sha256=FPKTIRA7kZ3p3RHgVcGfCJ7toL1HvriXU0WgVp6_QFY,810
|
|
9
|
+
sqlprism/languages/dbt.py,sha256=hC-lQ909tmwSKC0tiSjhLawDFkMLVBQ4DTDoY6C1-mI,7707
|
|
10
|
+
sqlprism/languages/sql.py,sha256=ii8AIcqmBYm6jvR1LX7QFGWiLwPDGmY0ETztbxP4oCc,40285
|
|
11
|
+
sqlprism/languages/sqlmesh.py,sha256=UCiteZ3awm805qZ8UoWQhCe-wnxSrOveuMdsf8Vq_hM,6967
|
|
12
|
+
sqlprism/languages/utils.py,sha256=kSXxXKlWjRCBa6jNiWiZo63sXsIFtHJZdhDpmDcdeiU,2307
|
|
13
|
+
sqlprism-1.0.0.dist-info/METADATA,sha256=aBRHKNc1zhBJI6T6159yOJXQEFs7VZViwyPCds-pZlA,19253
|
|
14
|
+
sqlprism-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
15
|
+
sqlprism-1.0.0.dist-info/entry_points.txt,sha256=hbk6Yzuvhvqh27pUtBVsm1Hz7hgYgBEhoD0sIixV3E0,47
|
|
16
|
+
sqlprism-1.0.0.dist-info/licenses/LICENSE,sha256=N5EVbd0AQKJ-1kHcOM2hnW_UH1Ek10hNgpqkQyMIezI,10779
|
|
17
|
+
sqlprism-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 sql-indexer-mcp contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|