SQL code graph analyzer and lineage tracer
Project description
sql-code-graph
SQL lineage and dependency analysis as an MCP server for Claude Code.
Indexes a directory of .sql files into a graph database and exposes lineage
queries as MCP tools — so Claude can answer questions like "what tables does
this view depend on?" or "where is orders.customer_id derived from?"
without reading every file.
Quick start
pip install sql-code-graph # or: uvx sql-code-graph (no install needed)
sqlcg install # register MCP server in Claude Code
Restart Claude Code, then inside your project ask:
Index my SQL files at ./sql --dialect snowflake
That's it. The MCP tools are now available to Claude in every conversation for that project.
Full setup (recommended)
# 1. Install
pip install sql-code-graph
# 2. Register with Claude Code (~/.claude/settings.json)
sqlcg install
# 3. Restart Claude Code
# 4. Index your SQL repo
# Only git-tracked files are indexed — build artefacts, node_modules,
# and .venv are ignored automatically.
sqlcg db init
sqlcg index ./sql --dialect snowflake # or: bigquery, postgres, ansi
# 5. (Optional) Keep the graph fresh on branch switches
cd /your/sql/repo
sqlcg git install-hooks
Step 5 installs a post-checkout git hook that re-indexes automatically
whenever you switch branches. Without it the graph may be stale after a
git checkout until you re-run sqlcg index manually.
Dialect config
To avoid passing --dialect every time, create .sqlcg.toml in your repo root:
[sqlcg]
dialect = "snowflake" # snowflake | bigquery | postgres | ansi
The git hook and sqlcg index --dialect auto both read this file.
Add to your project CLAUDE.md (recommended)
Adding a short note to your project's CLAUDE.md helps Claude know the tools
are available and when to use them:
## SQL lineage
This project uses sql-code-graph. MCP tools are available:
- `index_repo` — index or re-index a directory of SQL files
- `find_table_usages` — find all queries that read a table
- `trace_column_lineage` — trace where a column's value comes from
- `get_upstream_dependencies` / `get_downstream_dependencies` — dependency chains
- `search_sql_pattern` — full-text search across all indexed SQL
- `execute_cypher` — raw graph query for advanced analysis
The MCP server works without this — Claude can discover the tools on its own — but the CLAUDE.md snippet ensures they get used proactively.
MCP tools reference
| Tool | Description |
|---|---|
index_repo(repo_path, dialect) |
Index a directory of SQL files |
trace_column_lineage(table_col) |
Trace column lineage upstream |
find_table_usages(table_name) |
Find all queries that read a table |
get_upstream_dependencies(table_col) |
Full upstream dependency chain |
get_downstream_dependencies(table_col) |
Full downstream dependency chain |
search_sql_pattern(query) |
Full-text search across indexed SQL |
list_dialects_and_repos() |
List indexed repos and dialects |
execute_cypher(query) |
Raw Cypher query against the graph |
CLI reference
Full option reference: docs/cli.md
sqlcg install # register MCP server in Claude Code
sqlcg db init # initialise graph database
sqlcg index <path> --dialect <d> # index SQL files
sqlcg index <path> --dialect auto # read dialect from .sqlcg.toml
sqlcg watch <path> # watch for file changes
sqlcg git install-hooks # install post-checkout hook
sqlcg gain # show usage metrics
sqlcg report # generate FP/error report
sqlcg mcp start # start MCP server manually
sqlcg version # show installed version
Supported dialects
snowflake · bigquery · postgres · ansi · tsql · dbt (via optional extra)
Development
git clone https://github.com/Warhorze/sql-code-graph
cd sql-code-graph
uv sync --all-extras
uv run pytest tests/unit
Issues
Bug reports and feature requests: github.com/Warhorze/sql-code-graph/issues
Questions and discussion: github.com/Warhorze/sql-code-graph/discussions
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sql_code_graph-0.2.1.tar.gz.
File metadata
- Download URL: sql_code_graph-0.2.1.tar.gz
- Upload date:
- Size: 370.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a872cba66d230928298f1863c30ae3075ce4974afe5d79b13416503996d3be5
|
|
| MD5 |
18809098173a3f00cdd4b5cffa917cfc
|
|
| BLAKE2b-256 |
8b6276165660d9e0fc718ba749610929c9b4e51fb856083cd4876c47dbd7366a
|
Provenance
The following attestation bundles were made for sql_code_graph-0.2.1.tar.gz:
Publisher:
release.yml on Warhorze/sql-code-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_code_graph-0.2.1.tar.gz -
Subject digest:
0a872cba66d230928298f1863c30ae3075ce4974afe5d79b13416503996d3be5 - Sigstore transparency entry: 1439535799
- Sigstore integration time:
-
Permalink:
Warhorze/sql-code-graph@11e448702094e7f94a0357f32bf44bb821ea0354 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Warhorze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@11e448702094e7f94a0357f32bf44bb821ea0354 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sql_code_graph-0.2.1-py3-none-any.whl.
File metadata
- Download URL: sql_code_graph-0.2.1-py3-none-any.whl
- Upload date:
- Size: 64.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
615fe5d982462ba677f2fff57a7d9fcab9b645a0c4e8aa8fc6596b468d7c425b
|
|
| MD5 |
66d3dfeb238931f4fea2e4d55e445773
|
|
| BLAKE2b-256 |
94f14164774b6e08c7875e89309029c4b928e5a87d3ddbcfe2fc1421d654e70a
|
Provenance
The following attestation bundles were made for sql_code_graph-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Warhorze/sql-code-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_code_graph-0.2.1-py3-none-any.whl -
Subject digest:
615fe5d982462ba677f2fff57a7d9fcab9b645a0c4e8aa8fc6596b468d7c425b - Sigstore transparency entry: 1439536162
- Sigstore integration time:
-
Permalink:
Warhorze/sql-code-graph@11e448702094e7f94a0357f32bf44bb821ea0354 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Warhorze
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@11e448702094e7f94a0357f32bf44bb821ea0354 -
Trigger Event:
workflow_dispatch
-
Statement type: