Skip to content

Commit b1154f2

Browse files
authored
Add procedure tool (#137)
1 parent 409c937 commit b1154f2

File tree

11 files changed

+108
-8
lines changed

11 files changed

+108
-8
lines changed

integrations/mcp-memgraph/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Equivalent to running `SHOW STORAGE INFO`.
4646
List all database triggers.
4747
Equivalent to running `SHOW TRIGGERS`.
4848

49+
### get_procedures()
50+
51+
List all available Memgraph procedures (query modules).
52+
Returns information about all available procedures including MAGE algorithms and custom query modules. Each procedure includes its name, signature, and whether it performs write operations.
53+
Use this to discover available graph algorithms and utility functions before executing them.
54+
Equivalent to running `CALL mg.procedures() YIELD *`.
55+
4956
### get_betweenness_centrality()
5057

5158
Compute betweenness centrality on the entire graph.

integrations/mcp-memgraph/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies = [
2424
"httpx>=0.28.1",
2525
"mcp[cli]>=1.9.3",
2626
"neo4j>=5.28.1",
27-
"memgraph-toolbox>=0.1.8",
27+
"memgraph-toolbox>=0.1.9",
2828
"pytest>=8.3.5",
2929
"fastmcp>=2.13.0.2",
3030
]

integrations/mcp-memgraph/src/mcp_memgraph/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
get_schema,
77
get_storage,
88
get_triggers,
9+
get_procedures,
910
get_betweenness_centrality,
1011
get_page_rank,
1112
get_node_neighborhood,
@@ -23,6 +24,7 @@
2324
"get_schema",
2425
"get_storage",
2526
"get_triggers",
27+
"get_procedures",
2628
"get_betweenness_centrality",
2729
"get_page_rank",
2830
"get_node_neighborhood",

integrations/mcp-memgraph/src/mcp_memgraph/servers/server.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from memgraph_toolbox.tools.schema import ShowSchemaInfoTool
99
from memgraph_toolbox.tools.storage import ShowStorageInfoTool
1010
from memgraph_toolbox.tools.trigger import ShowTriggersTool
11+
from memgraph_toolbox.tools.procedures import ShowProceduresTool
1112
from memgraph_toolbox.tools.betweenness_centrality import (
1213
BetweennessCentralityTool,
1314
)
@@ -161,6 +162,22 @@ def get_triggers() -> List[Dict[str, Any]]:
161162
return [{"error": f"Error fetching triggers: {str(e)}"}]
162163

163164

165+
@mcp.tool()
166+
def get_procedures() -> List[Dict[str, Any]]:
167+
"""List all available Memgraph procedures (query modules).
168+
169+
Returns information about all available procedures including MAGE algorithms
170+
and custom query modules. Each procedure includes its name, signature, and
171+
whether it performs write operations. Use this to discover available graph
172+
algorithms and utility functions before executing them."""
173+
logger.info("Fetching Memgraph procedures...")
174+
try:
175+
procedures = ShowProceduresTool(db=db).call({})
176+
return procedures
177+
except Exception as e:
178+
return [{"error": f"Error fetching procedures: {str(e)}"}]
179+
180+
164181
@mcp.tool()
165182
def get_betweenness_centrality() -> List[Dict[str, Any]]:
166183
"""Get betweenness centrality information"""

integrations/mcp-memgraph/tests/test_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ async def test_tools_and_resources():
238238
"get_page_rank",
239239
"get_node_neighborhood",
240240
"search_node_vectors",
241+
"get_procedures",
241242
]
242243
expected_resources = []
243244

integrations/mcp-memgraph/uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

memgraph-toolbox/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "memgraph-toolbox"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "Memgraph toolbox library for Memgraph AI tools and utilities"
55
readme = "README.md"
66
authors = [

memgraph-toolbox/src/memgraph_toolbox/tests/test_tools.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..tools.schema import ShowSchemaInfoTool
1313
from ..tools.storage import ShowStorageInfoTool
1414
from ..tools.trigger import ShowTriggersTool
15+
from ..tools.procedures import ShowProceduresTool
1516
from ..utils.logger import logger_init
1617

1718
logger = logger_init("test-tools")
@@ -311,3 +312,32 @@ def test_node_neighborhood_tool():
311312
assert isinstance(result, list)
312313
assert len(result) == 2
313314
memgraph_client.query(f"MATCH (n:{label}) DETACH DELETE n;")
315+
316+
317+
def test_show_procedures_tool():
318+
"""Test the ShowProcedures tool."""
319+
320+
url = "bolt://localhost:7687"
321+
user = ""
322+
password = ""
323+
324+
memgraph_client = Memgraph(url=url, username=user, password=password)
325+
326+
procedures_tool = ShowProceduresTool(db=memgraph_client)
327+
assert "show_procedures" in procedures_tool.name
328+
329+
result = procedures_tool.call({})
330+
331+
assert isinstance(result, list)
332+
# Memgraph should always have some built-in procedures
333+
assert len(result) >= 1
334+
335+
# Verify the structure of the returned data
336+
first_procedure = result[0]
337+
assert "name" in first_procedure
338+
assert "signature" in first_procedure
339+
assert "is_write" in first_procedure
340+
341+
# Verify that mg.procedures is in the list (it's a built-in procedure)
342+
procedure_names = [proc["name"] for proc in result]
343+
assert "mg.procedures" in procedure_names
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import Any, Dict, List
2+
3+
from ..api.memgraph import Memgraph
4+
from ..api.tool import BaseTool
5+
6+
7+
class ShowProceduresTool(BaseTool):
8+
"""
9+
Tool for listing all available Memgraph procedures (query modules).
10+
11+
This tool queries the Memgraph database to retrieve information about
12+
all available procedures from MAGE and custom query modules.
13+
"""
14+
15+
def __init__(self, db: Memgraph):
16+
super().__init__(
17+
name="show_procedures",
18+
description=(
19+
"Lists all available Memgraph procedures (query modules) including "
20+
"MAGE algorithms and custom query modules. Returns procedure name, "
21+
"signature, and whether it's a read-only operation. Use this to "
22+
"discover available graph algorithms and utility functions."
23+
),
24+
input_schema={"type": "object", "properties": {}, "required": []},
25+
)
26+
self.db = db
27+
28+
def call(self, arguments: Dict[str, Any]) -> List[Dict[str, Any]]:
29+
"""Execute the mg.procedures() query and return the available procedures."""
30+
procedures = self.db.query(
31+
"CALL mg.procedures() YIELD name, signature, is_write "
32+
"RETURN name, signature, is_write "
33+
"ORDER BY name"
34+
)
35+
return procedures

memgraph-toolbox/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)