/memgraph:memgraph-python-query-modulesfrom memgraph
Develop custom query modules in Python for Memgraph graph database. Covers mgp API, graph traversal, procedures, and functions.
Ships in memgraph. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Develop custom query modules in Python for Memgraph graph database.
@mgp.read_proc) for data analysis@mgp.write_proc) for data modification@mgp.function) for use in Cypher queriespip install mgp| Feature | Procedures | Functions |
|---|---|---|
| Decorator | @mgp.read_proc / @mgp.write_proc | @mgp.function |
| Cypher | CALL module.proc() YIELD ... | RETURN module.func() |
| Return Type | mgp.Record | Any supported type |
| Modify Graph | Yes (with @mgp.write_proc) | No |
| Type | Description |
|---|---|
mgp.Vertex | Graph node with properties, labels, edges |
mgp.Edge | Relationship with type and properties |
mgp.Path | Sequence of vertices and edges |
mgp.Record | Return type for procedures |
mgp.ProcCtx | Procedure context with graph access |
mgp.FuncCtx | Function context |
import mgp
@mgp.read_proc
def hello_world(
context: mgp.ProcCtx,
name: str
) -> mgp.Record(message=str):
"""A simple hello world procedure."""
return mgp.Record(message=f"Hello, {name}!")
CALL module_name.hello_world("Memgraph") YIELD message;
import mgp
@mgp.read_proc
def count_nodes_by_label(
context: mgp.ProcCtx,
label_name: str
) -> mgp.Record(count=int):
"""Count nodes with a specific label."""
count = 0
for vertex in context.graph.vertices:
for label in vertex.labels:
if label.name == label_name:
count += 1
break
return mgp.Record(count=count)
import mgp
@mgp.write_proc
def create_person(
context: mgp.ProcCtx,
name: str,
age: mgp.Nullable[int] = None
) -> mgp.Record(vertex=mgp.Vertex):
"""Create a new Person node."""
vertex = context.graph.create_vertex()
vertex.add_label("Person")
vertex.properties["name"] = name
if age is not None:
vertex.properties["age"] = age
return mgp.Record(vertex=vertex)
import mgp
@mgp.function
def full_name(
context: mgp.FuncCtx,
first_name: str,
last_name: str
) -> str:
"""Concatenate first and last name."""
return f"{first_name} {last_name}"
MATCH (p:Person)
RETURN module_name.full_name(p.first_name, p.last_name) AS name;
import mgp
@mgp.read_proc
def get_neighbors(
context: mgp.ProcCtx,
node: mgp.Vertex
) -> mgp.Record(neighbor=mgp.Vertex, edge_type=str):
"""Get all neighbors of a node."""
results = []
for edge in node.out_edges:
results.append(mgp.Record(
neighbor=edge.to_vertex,
edge_type=edge.type.name
))
for edge in node.in_edges:
results.append(mgp.Record(
neighbor=edge.from_vertex,
edge_type=edge.type.name
))
return results
# Access vertex properties
vertex.id # Unique identifier
vertex.labels # Iterable of labels
vertex.properties # Dict-like properties
vertex.in_edges # Incoming edges
vertex.out_edges # Outgoing edges
# Modify (write procedures only)
vertex.add_label("Label")
vertex.remove_label("Label")
vertex.properties["key"] = value
edge.id # Unique identifier
edge.type # EdgeType object
edge.type.name # Relationship type name
edge.from_vertex # Source vertex
edge.to_vertex # Target vertex
edge.properties # Dict-like properties
path = mgp.Path(start_vertex)
path.expand(edge) # Extend path
path.vertices # List of vertices
path.edges # List of edges
@mgp.read_proc
def long_running_analysis(
context: mgp.ProcCtx
) -> mgp.Record(result=int):
"""A procedure that can be terminated."""
count = 0
try:
for vertex in context.graph.vertices:
if context.check_must_abort():
break
# Expensive computation...
count += 1
except mgp.AbortError:
pass
return mgp.Record(result=count)
import mgp
try:
import networkx as nx
HAS_NETWORKX = True
except ImportError:
HAS_NETWORKX = False
@mgp.read_proc
def pagerank(
context: mgp.ProcCtx,
damping: float = 0.85
) -> mgp.Record(node_id=int, rank=float):
"""Calculate PageRank using NetworkX."""
if not HAS_NETWORKX:
raise Exception("NetworkX not installed")
G = nx.DiGraph()
for vertex in context.graph.vertices:
G.add_node(vertex.id)
for vertex in context.graph.vertices:
for edge in vertex.out_edges:
G.add_edge(vertex.id, edge.to_vertex.id)
ranks = nx.pagerank(G, alpha=damping)
return [mgp.Record(node_id=nid, rank=rank)
for nid, rank in ranks.items()]
import mgp
logger = mgp.Logger()
logger.trace("Trace message")
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical message")
| Path | Description |
|---|---|
/usr/lib/memgraph/query_modules/ | System modules |
/var/lib/memgraph/internal_modules/ | User modules (Memgraph Lab) |
docker cp my_module.py memgraph:/usr/lib/memgraph/query_modules/
echo "CALL mg.load_all();" | docker exec -i memgraph mgconsole
docker run -d \
-p 7687:7687 \
-v $(pwd)/modules:/usr/lib/memgraph/query_modules \
--name memgraph \
memgraph/memgraph-mage
docker exec -i -u memgraph memgraph bash -c "pip install pandas networkx"
echo "CALL mg.load_all();" | docker exec -i memgraph mgconsole
CALL mg.load_all(); -- Load all modules
CALL mg.load("module_name"); -- Load specific module
CALL mg.procedures() YIELD *; -- List procedures
CALL mg.functions() YIELD *; -- List functions
import mgp
@mgp.read_proc
def safe_procedure(
context: mgp.ProcCtx,
vertex_id: int
) -> mgp.Record(result=str):
try:
vertex = context.graph.get_vertex_by_id(vertex_id)
return mgp.Record(result=f"Found vertex: {vertex.id}")
except IndexError:
raise Exception(f"Vertex with ID {vertex_id} not found")
except mgp.InvalidContextError:
raise Exception("Invalid context")
context.check_must_abort() in long-running procedures| Issue | Solution |
|---|---|
| Module not found | Run CALL mg.load_all(); |
| Import error | Install library in Memgraph container |
| InvalidContextError | Don't store graph objects globally |
| Type error | Ensure all parameters have type annotations |
For detailed API documentation and examples, see references/REFERENCE.md.
What SKILL.md sets; muted values are Claude Code's defaults
memgraph@memgraph is listed by memgraph/marketplace — review the source before installing
npx claudepluginhub memgraph/marketplace --plugin memgraph14 skills in this plugin
/memgraph-brand-uiGenerate apps, demos, dashboards, diagrams, landing pages, and any visual output that looks like it belongs in the Memgraph product family. Use whenever producing UI, visual artifacts (Mermaid, SVGs, charts), Lab-style admin tools, internal dashboards, feature splash pages, or embeddable widgets for Memgraph engineers./memgraph-cpp-query-modulesDevelop custom query modules in C++ for Memgraph graph database. Use when creating high-performance graph algorithms, procedures (ProcedureType::Read/Write), or functions using the mgp.hpp C++ API. Covers compilation, memory management, graph traversal, and module deployment./memgraph-cypher-syntaxWrite Cypher queries for Memgraph, including Memgraph-specific extensions like deep path traversals (BFS, DFS, WSP, ASP, KSP with filter/weight lambdas), text and vector search, parallel execution, and CALL subqueries. Use when the user asks to write, fix, or optimize a Cypher query for Memgraph, or asks about Cypher syntax differences between Memgraph and Neo4j./memgraph-database-configurationConfigure Memgraph triggers, transactions, storage modes, data durability, and memory settings. Use when the user asks about triggers, transaction isolation levels, storage modes (transactional vs analytical), snapshots, WAL, memory limits, data types, or database runtime configuration./memgraph-graph-ragLanguage-agnostic blueprint for building GraphRAG systems with Memgraph and agent tooling. Covers end-to-end architecture, schema design, ingestion, hybrid retrieval, tool contracts, and evaluation. Use when designing GraphRAG platforms that must work across multiple programming languages./memgraph-import-dataImport or migrate data into Memgraph from CSV, Parquet, JSON/JSONL, CYPHERL dumps, relational databases (PostgreSQL, MySQL, SQL Server, Oracle, DuckDB) or Neo4j: choosing between LOAD CSV, cross_database procedures and client-driven batches, preparing indexes and storage mode, ordering nodes before relationships, and verifying counts. Use when the user wants to load, bulk-insert, ingest or migrate data into Memgraph, or an import is slow or failing.Other plugins' skills for the same job