$npx -y skills add neo4j-contrib/neo4j-skills --skill neo4j-cypher-skillGenerates, optimizes, and validates Cypher 25 queries for Neo4j 2025.x and 2026.x.
| 1 | ## When to Use |
| 2 | - Writing, optimizing, or debugging Cypher queries |
| 3 | - Graph pattern matching, QPEs, variable-length paths |
| 4 | - Vector/fulltext search, subqueries, batch writes, LOAD CSV |
| 5 | |
| 6 | ## When NOT to Use |
| 7 | - **Driver migration/API changes** → `neo4j-migration-skill` |
| 8 | - **DB admin** (users, config, backups) → `neo4j-cli-tools-skill` |
| 9 | - **Hybrid search that combines vector with fulltext or other ranked sources** → `neo4j-vector-index-skill` |
| 10 | |
| 11 | GQL conformance note: `LET`, `FINISH`, `FILTER`, and `INSERT` are valid Cypher 25 clauses (introduced via GQL conformance, mostly in Neo4j 2025.06). On older versions, fall back to `WITH` / (omit RETURN) / `WHERE` / `CREATE`. `INSERT` requires `&`-separated multi-labels and does not support dynamic labels/types. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## Pre-flight |
| 16 | |
| 17 | | ? | Known | Unknown | |
| 18 | |---|---|---| |
| 19 | | `<db-name>-schema.json` found in project | Use it directly — skip live inspection | — | |
| 20 | | Schema (from context or live DB) | Use directly | Run Schema-First Protocol | |
| 21 | | Neo4j version | Use version features | Default to 2025.01 safe set | |
| 22 | | Executing (not generating)? | Use EXPLAIN + write gate | State query is unvalidated | |
| 23 | |
| 24 | Schema unknown + no tool → produce non-executable sketch outside a code block: |
| 25 | ``` |
| 26 | (<SOURCE_LABEL> {<KEY>: $value})-[:<REL_TYPE>]->(<TARGET_LABEL>) |
| 27 | ``` |
| 28 | Never fill guessed names — realistic guesses get copied blindly. |
| 29 | |
| 30 | --- |
| 31 | |
| 32 | ## Defaults — apply every query |
| 33 | |
| 34 | 1. `CYPHER 25` — first token; never repeat after `UNION` or inside subqueries |
| 35 | 2. Schema first — inspect before writing; if schema in prompt, use it directly |
| 36 | 3. `MERGE` on constrained key only; rel `MERGE` on already-bound endpoints only |
| 37 | 4. Label-free `MATCH (n)` forbidden unless bound or followed by `WHERE n:$($label)` |
| 38 | 5. `LIMIT 25` default on all exploratory reads; push `WITH n LIMIT` before high-cardinality operations (variable-length traversals, fan-out MATCH, Cartesian products) |
| 39 | 6. Comments: `//` only — `--` is SQL, invalid |
| 40 | 7. `REPEATABLE ELEMENTS` / `DIFFERENT RELATIONSHIPS` go after `MATCH`, not end of pattern |
| 41 | 8. `SHOW` commands: `YIELD` before `WHERE`; combinable with general Cypher clauses incl. `UNION`/`RETURN` [2026.05] — `SHOW DATABASES` still requires system db (use `USE system`) |
| 42 | 9. Inline node predicates `(:Label WHERE p=x)` — valid in `MATCH` only |
| 43 | 10. `WHERE` cannot follow bare `UNWIND` — use `WITH x WHERE` |
| 44 | 11. `(a)-[:R]-(b)` — undirected matches both directions, double-counts; use directed unless unknown |
| 45 | 12. `DETACH DELETE` — plain `DELETE` throws if node has relationships |
| 46 | |
| 47 | --- |
| 48 | |
| 49 | ## Style |
| 50 | |
| 51 | | Element | Convention | |
| 52 | |---|---| |
| 53 | | Node labels | PascalCase `:Person` | |
| 54 | | Rel types | SCREAMING_SNAKE_CASE `:KNOWS` | |
| 55 | | Properties/vars | camelCase `firstName` | |
| 56 | | Clauses | UPPERCASE `MATCH` | |
| 57 | | Booleans/null | lowercase `true false null` | |
| 58 | | Strings | single-quoted; double only if contains `'` | |
| 59 | |
| 60 | > Schema is truth. `:Person`, `:KNOWS`, `name` in examples are illustrative — substitute real names from schema. |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## Schema-First Protocol |
| 65 | |
| 66 | **Priority order:** |
| 67 | |
| 68 | 1. `<db-name>-schema.json` anywhere in project → read directly, state file name + `schema_retrieved_at`, skip live inspection. If significantly outdated and DB reachable, offer re-fetch. Full rules: [references/schema-guardrail.md](references/schema-guardrail.md). |
| 69 | - **Existence** — labels/rel-types/properties must be in schema; try synonym resolution before asking |
| 70 | - **Property type** — reason about intent first (e.g. string vs INTEGER may be null check); ask only if unclear |
| 71 | - **Relationship direction** — wrong direction → correct silently and note |
| 72 | - **Synonym mapping** — unambiguous → resolve silently; ambiguous → pick most likely, note; ask if unresolvable |
| 73 | |
| 74 | Scripts: `generate_schema.py` (live DB + APOC), `define_schema.py` (no DB), `import_neo4j_schema.py` (converts `neo4j-graphrag-python`, `graph-schema-introspector`, `graph-schema-json-js-utils`, `mcp-neo4j-data-modeling`). |
| 75 | |
| 76 | 2. Schema in context → use it, skip inspection. |
| 77 | |
| 78 | 3. Schema missing → run: |
| 79 | ```cypher |
| 80 | CALL db.schema.visualization() YIELD nodes, relationships RETURN nodes, relationships; |
| 81 | SHOW INDEXES YIELD name, type, labelsOrTypes, properties, state WHERE state = 'ONLINE'; |
| 82 | SHOW CONSTRAINTS YIELD name, type, labelsOrTypes, properties; |
| 83 | SHOW PROCEDURES YIELD name RETURN split(name,'.')[0] AS namespace, count(*) AS procedures; |
| 84 | ``` |
| 85 | |
| 86 | Property types per label — check APOC first: |
| 87 | ```cy |