sgraph_cypher_query
Run read-only openCypher queries against the loaded model to analyze complex dependencies, multi-hop paths, and aggregated results with flexible filtering.
Instructions
Run an openCypher query against the loaded model. Powerful and flexible.
Use this tool for complex graph queries that the other tools can't express:
Multi-hop path queries, transitive dependencies
Aggregation (count, group by)
Complex filtering with AND/OR/NOT
Joining different relationship types
The sgraph model is mapped to a labeled property graph:
Nodes (= code elements):
Labels come from element type: :file, :class, :function, :dir, :method, etc.
Properties: name, path (always present), plus all element attributes
Elements without a type have no label
Relationships (= dependencies):
Type comes from deptype: :imports, :function_ref, :call, :inc, :uses, etc.
Properties: any edge-level attributes
:CONTAINS relationships represent parent-child hierarchy (off by default)
Example queries:
"What files does main.py import?" MATCH (a:file)-[:imports]->(b:file) WHERE a.name = 'main.py' RETURN b.name, b.path
"Count dependencies per file, top 10:" MATCH (a:file)-[r]->(b) WHERE type(r) <> 'CONTAINS' RETURN a.name, count(r) AS deps ORDER BY deps DESC LIMIT 10
"Find all transitive imports from a file (up to 3 hops):" MATCH (a:file)-[:imports*1..3]->(b) WHERE a.name = 'app.py' RETURN DISTINCT b.name, b.path
"Files with more than 500 lines of code:" MATCH (f:file) WHERE f.loc > 500 RETURN f.name, f.loc ORDER BY f.loc DESC
"Does module A depend on module B? (directory-level)" MATCH (a)-[r]->(b) WHERE a.path STARTS WITH '/project/src/web/' AND b.path STARTS WITH '/project/src/db/' AND type(r) <> 'CONTAINS' RETURN type(r), count(r) AS cnt ORDER BY cnt DESC
Performance notes:
include_hierarchy=false (default) is faster, omits :CONTAINS edges
Enable include_hierarchy only for parent-child traversal queries
Large models take a few seconds for initial indexing (cached per model)
Variable-length paths (*1..N) with large N can be slow
Returns JSON array of result rows. Read-only: CREATE/DELETE/SET not supported.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |