mcpbeat Sign in

Pg Graph Agent Skill

Graph database skills for Apache AGE on PostgreSQL. Covers the full lifecycle: deriving an ontology from structured or unstructured data with a human feedback loop, building the graph, and querying it with openCypher, natural language to Cypher, and graph augmented retrieval.

19k tokens
context cost
the whole folder, loaded on every use
11
files
instructions only
0
copies elsewhere
how many repositories repackaged it
0
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/microsoft/postgres-skills --skill pg-graph

What comes with it

67 387 bytes besides the instruction
references/azure-ai-semantic-search.md
references/context-dedup.md
references/examples.md
references/extract-to-graph.md
references/graph-augmented-rag.md
references/graph-explainability.md
references/graph-schema-introspection.md
references/ontology-derivation.md
references/opencypher-age-patterns.md
references/text-to-cypher.md

The instruction itself

6 sections, as written by the author

pg-graph — Apache AGE Graph Skills (Routing Table)

Use references as supplemental context, combined with your Apache AGE and openCypher knowledge. If reference guidance is incomplete, answer with appropriate caveats rather than inventing syntax.

This skill is the single home for graph work on PostgreSQL, covering the full lifecycle. The generic PostgreSQL skill (postgresql-best-practices) points here for anything involving Apache AGE, openCypher, ag_catalog, knowledge graphs, or ontology. Keep AGE specific guidance in this skill rather than duplicating it in the generic skill.

Lifecycle: construct then consume

  • Derive an ontology from the user's structured or unstructured data, and run a human feedback loop before finalizing. See ontology-derivation.
  • Build the graph by extracting, deduplicating, and MERGE loading into AGE using the finalized ontology. See extract-to-graph.
  • Consume the graph with openCypher, natural language to Cypher, schema introspection, and graph augmented retrieval.

Construction uses only capabilities available today: agent driven extraction over the MCP query tools (works on any PostgreSQL with AGE), or the azure_ai extension for in-database work at scale on Azure. It does NOT depend on unreleased ai.* pipeline primitives. Never finalize an ontology without explicit user approval.

Prerequisites (verify before graph work)

  • Apache AGE is an extension. Confirm it is installed and load it once per session before any Cypher call.
  • On managed Azure Database for PostgreSQL (Flexible Server and Azure HorizonDB), age must be allowlisted in azure.extensions and added to shared_preload_libraries, then created with CREATE EXTENSION IF NOT EXISTS age CASCADE;. Set both on Flexible Server via server parameters; on Azure HorizonDB via a parameter group connected to the cluster. Both auto-restart to apply. It cannot be enabled with ALTER SYSTEM. AGE is preloaded on both, so do NOT run LOAD 'age'; there (a non-superuser gets access to library "age" is not allowed).
  • Non superuser sessions must set search_path so ag_catalog is available but NOT first. Use SET search_path = public, ag_catalog;. Putting ag_catalog first makes ordinary CREATE TABLE fail with permission denied for schema ag_catalog.

Key Constraints (what models get wrong)

| Fact | Detail |

|------|--------|

| Cypher is wrapped in a function | Every query runs as SELECT * FROM ag_catalog.cypher('graph_name', $$ ... $$) AS (col agtype). It is not a bare statement. |

| Column definition list is required | The AS (col agtype) list must match the RETURN arity, and every returned column is typed agtype. |

| agtype casting | Scalars come back as agtype. Cast for SQL use rather than assuming a raw text or int is returned. State uncertainty about exact cast helpers instead of inventing function names. |

| search_path ordering | SET search_path = public, ag_catalog; (never ag_catalog first) for non superuser roles. |

| Graph must exist | Create the graph once with create_graph('graph_name') before MERGE or MATCH. |

| MERGE for idempotent load | Use MERGE on a stable business key to avoid duplicate vertices during repeated extraction. |

| Parameters | AGE Cypher does not accept host bind parameters inside $$...$$ the way SQL does. Interpolate safely on the server side or wrap the cypher call in SQL. Never string concatenate untrusted input. |

Routing Table

| Keyword triggers | Reference | When to use |

|---|---|---|

| derive ontology, suggest ontology, generate ontology, ontology from data, ontology from documents, propose ontology | ontology-derivation | Analyze structured or unstructured data, propose an ontology, and run a human feedback loop before finalizing |

| extract to graph, build graph from data, build knowledge graph, populate graph, extract entities to graph | extract-to-graph | Apply a finalized ontology: extract, deduplicate, and MERGE into the AGE graph |

| entity resolution, context dedup, deduplicate entities, canonicalize entities, merge duplicate entities | context-dedup | Resolve entity aliases using type, graph neighborhood, and source snippet, with scalable blocking and a persistent canonical map |

| apache age, opencypher, cypher(), create_graph, property graph, vertices and edges, MERGE node | opencypher-age-patterns | AGE setup, Cypher wrapping, MATCH/MERGE/CREATE patterns, indexing vertices and edges |

| text to cypher, natural language to cypher, english to cypher, generate cypher, nl to cypher | text-to-cypher | Turning a user question into a validated openCypher query and running it |

| graph schema, list vertex labels, edge labels, ag_label, describe graph | graph-schema-introspection | Discovering labels, edge types, and properties so generated Cypher is grounded |

| visualize graph, vs code graph, render the graph, graph explorer, see the graph, plot the graph, ms-ossdata.vscode-pgsql | text-to-cypher | Generate visualization-ready Cypher (full vertex/edge objects, disp_label, matched AS columns) for the PostgreSQL extension for VS Code graph explorer |

| graph rag, graph augmented, graph augmented retrieval, hybrid graph retrieval | graph-augmented-rag | Retrieval that combines vector similarity with graph traversal and reranking |

| explainability, traceability, provenance, why this recommendation, reasoning path, audit graph answer | graph-explainability | Make facts traceable to sources and recommendations explainable: provenance on vertices and edges, returned reasoning path, weakest link path confidence, and a reproducible reasoning trace log |

| graph semantic search, graph azure_ai embeddings, graph azure openai embeddings, enable azure_ai for graph, configure azure openai for graph | azure-ai-semantic-search | Enable and configure the azure_ai extension, prompt the user for endpoint/key/deployment, and generate embeddings for semantic search |

| cypher example, graph query example, worked graph example | examples | End to end worked examples spanning schema, query, and results |

Anti-Hallucination Rules

  • Do NOT present a Cypher query as a bare statement. Always wrap it in ag_catalog.cypher(...) with a column definition list.
  • Do NOT claim host bind parameters work inside the $$...$$ body.
  • Do NOT put ag_catalog first in search_path.
  • Do NOT enable age with ALTER SYSTEM on managed Azure. Use the azure.extensions + shared_preload_libraries allowlist, set via server parameters (Flexible Server) or a parameter group connected to the cluster (Azure HorizonDB).
  • Verify labels and properties with schema introspection before generating Cypher against an unknown graph.
  • State uncertainty about exact agtype cast helpers rather than inventing function names.
  • Do NOT finalize a derived ontology without explicit user approval. Treat it as a proposal and run the feedback loop.
  • Do NOT rely on unreleased ai.* pipeline primitives. Use agent-driven extraction or the azure_ai extension over Apache AGE, both available today.
  • For semantic search, do NOT invent an Azure OpenAI endpoint, key, or embedding deployment name. Read current azure_ai settings and ask the user for anything missing. See azure-ai-semantic-search.

10. Do NOT present a graph recommendation without its reasoning path, supporting evidence, and a confidence bounded by the weakest edge on the path. See graph-explainability.

How to use it

Copy the folder

Take microsoft/pg-graph from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.