memgraph-ingester-tool 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. memgraph_ingester_tool-0.1.0/.github/workflows/publish.yml +43 -0
  2. memgraph_ingester_tool-0.1.0/LICENSE +21 -0
  3. memgraph_ingester_tool-0.1.0/PKG-INFO +191 -0
  4. memgraph_ingester_tool-0.1.0/README.md +167 -0
  5. memgraph_ingester_tool-0.1.0/pyproject.toml +55 -0
  6. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/__init__.py +7 -0
  7. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/__main__.py +5 -0
  8. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/cli.py +704 -0
  9. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/config.py +128 -0
  10. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/db.py +65 -0
  11. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/__init__.py +111 -0
  12. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_callees.cypher +20 -0
  13. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_callees_count.cypher +10 -0
  14. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_callers.cypher +20 -0
  15. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_callers_count.cypher +10 -0
  16. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_file_context.cypher +68 -0
  17. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_flow_context_edges.cypher +18 -0
  18. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hierarchy_ancestors.cypher +5 -0
  19. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hierarchy_class.cypher +7 -0
  20. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hierarchy_implementors.cypher +5 -0
  21. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hot_paths_fan_in.cypher +11 -0
  22. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hot_paths_fan_out.cypher +11 -0
  23. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hot_paths_largest_types.cypher +10 -0
  24. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_hot_paths_longest_methods.cypher +12 -0
  25. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_impact_callers.cypher +60 -0
  26. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_impact_targets.cypher +16 -0
  27. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_impact_text_reference.cypher +43 -0
  28. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_field.cypher +12 -0
  29. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_field_count.cypher +6 -0
  30. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_file.cypher +12 -0
  31. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_file_count.cypher +4 -0
  32. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_methods.cypher +10 -0
  33. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_methods_count.cypher +6 -0
  34. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_type.cypher +11 -0
  35. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_type_count.cypher +6 -0
  36. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_type_members_fields.cypher +5 -0
  37. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_lookup_type_members_methods.cypher +5 -0
  38. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_operation_hot_paths.cypher +40 -0
  39. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_orientation_cross_owner_calls.cypher +9 -0
  40. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_orientation_languages.cypher +4 -0
  41. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_orientation_largest_types.cypher +8 -0
  42. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_orientation_packages.cypher +6 -0
  43. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_quality_stats.cypher +75 -0
  44. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_resource_risk_scan.cypher +10 -0
  45. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_search.cypher +37 -0
  46. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_test_files.cypher +13 -0
  47. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_test_methods.cypher +30 -0
  48. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/code_test_production_callees.cypher +25 -0
  49. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/lexical_chunk_rows.cypher +40 -0
  50. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/server_status_inventory.cypher +9 -0
  51. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/server_status_languages.cypher +3 -0
  52. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/code/server_status_memories.cypher +5 -0
  53. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_delete_orphan_refs.cypher +7 -0
  54. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_delete_read.cypher +10 -0
  55. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_delete_write.cypher +7 -0
  56. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_get.cypher +12 -0
  57. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_link_code_ref.cypher +8 -0
  58. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_orientation_active_tasks.cypher +4 -0
  59. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_orientation_open_findings.cypher +4 -0
  60. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_orientation_open_questions.cypher +4 -0
  61. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_orientation_open_risks.cypher +4 -0
  62. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_orientation_rules.cypher +3 -0
  63. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_refresh_chunk.cypher +12 -0
  64. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_refresh_embeddings_embed.cypher +9 -0
  65. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_refresh_embeddings_mark.cypher +7 -0
  66. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_refresh_embeddings_pending.cypher +11 -0
  67. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_search.cypher +11 -0
  68. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_update_status.cypher +3 -0
  69. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/queries/memory/memory_upsert.cypher +7 -0
  70. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/schema.py +106 -0
  71. memgraph_ingester_tool-0.1.0/src/memgraph_ingester_tool/tools.py +3098 -0
  72. memgraph_ingester_tool-0.1.0/tests/test_config.py +62 -0
  73. memgraph_ingester_tool-0.1.0/tests/test_tools.py +2277 -0
  74. memgraph_ingester_tool-0.1.0/uv.lock +133 -0
@@ -0,0 +1,43 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ tags:
7
+ - "v*"
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ environment:
13
+ name: pypi
14
+ permissions:
15
+ contents: read
16
+ id-token: write
17
+
18
+ steps:
19
+ - name: Checkout
20
+ uses: actions/checkout@v6
21
+
22
+ - name: Install uv
23
+ uses: astral-sh/setup-uv@v7
24
+ with:
25
+ enable-cache: true
26
+
27
+ - name: Install Python
28
+ run: uv python install 3.13
29
+
30
+ - name: Install dependencies
31
+ run: uv sync --locked --dev
32
+
33
+ - name: Lint
34
+ run: uv run ruff check .
35
+
36
+ - name: Test
37
+ run: uv run pytest
38
+
39
+ - name: Build
40
+ run: uv build --no-sources
41
+
42
+ - name: Publish
43
+ run: uv publish
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oleksii Usatov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: memgraph-ingester-tool
3
+ Version: 0.1.0
4
+ Summary: Standalone query tools for Memgraph graphs created by memgraph-ingester
5
+ Project-URL: Homepage, https://github.com/ousatov-ua/memgraph-ingester-tool
6
+ Project-URL: Repository, https://github.com/ousatov-ua/memgraph-ingester-tool
7
+ Project-URL: Issues, https://github.com/ousatov-ua/memgraph-ingester-tool/issues
8
+ Author: Oleksii Usatov
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cli,codex,knowledge-graph,memgraph,rag
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Database
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: neo4j>=5.28.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # memgraph-ingester-tool
26
+
27
+ [![PyPI release](https://img.shields.io/pypi/v/memgraph-ingester-tool)](https://pypi.org/project/memgraph-ingester-tool/)
28
+ [![Python versions](https://img.shields.io/pypi/pyversions/memgraph-ingester-tool)](https://pypi.org/project/memgraph-ingester-tool/)
29
+ [![License](https://img.shields.io/pypi/l/memgraph-ingester-tool)](https://github.com/ousatov-ua/memgraph-ingester-tool/blob/main/LICENSE)
30
+
31
+ Standalone query tools for Memgraph knowledge graphs produced by
32
+ [`memgraph-ingester`](https://github.com/ousatov-ua/memgraph-ingester).
33
+
34
+ This package is the **single source of truth** for all graph query and
35
+ formatting logic. It is consumed two ways:
36
+
37
+ - as a **library** by [`memgraph-ingester-mcp`](https://github.com/ousatov-ua/memgraph-ingester-mcp),
38
+ which exposes every method as an MCP tool;
39
+ - as a **CLI** (`mgtools`) for users who work with `mgconsole` or scripts and
40
+ have no MCP client.
41
+
42
+ Any change to query logic here automatically reaches both audiences.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install memgraph-ingester-tool
48
+ # or
49
+ uv tool install memgraph-ingester-tool
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ Settings come from environment variables. `MEMGRAPH_TOOLS_*` take priority;
55
+ `MEMGRAPH_INGESTER_MCP_*` are accepted as a fallback so existing MCP
56
+ configurations keep working.
57
+
58
+ | Variable | Default | Description |
59
+ | --- | --- | --- |
60
+ | `MEMGRAPH_TOOLS_BOLT_URI` | `bolt://127.0.0.1:7687` | Memgraph Bolt endpoint |
61
+ | `MEMGRAPH_TOOLS_USERNAME` | _none_ | Bolt username |
62
+ | `MEMGRAPH_TOOLS_PASSWORD` | _none_ | Bolt password |
63
+ | `MEMGRAPH_TOOLS_DATABASE` | _none_ | Database name |
64
+ | `MEMGRAPH_TOOLS_PROJECT` | _none_ | Default project (`:Project` anchor name) |
65
+ | `MEMGRAPH_TOOLS_QUERY_TIMEOUT_SECONDS` | `30.0` | Per-query timeout |
66
+ | `MEMGRAPH_TOOLS_READ_ONLY` | `false` | Disable write operations |
67
+ | `MEMGRAPH_TOOLS_CODE_EMBEDDING_INDEX` | `code_chunk_embedding_v2` | Code vector index base name |
68
+ | `MEMGRAPH_TOOLS_MEMORY_EMBEDDING_INDEX` | `memory_chunk_embedding_v2` | Memory vector index base name |
69
+ | `MEMGRAPH_TOOLS_EMBEDDING_MODEL` | `default` | Embedding model name |
70
+ | `MEMGRAPH_TOOLS_EMBEDDING_DIMENSIONS` | `384` | Embedding dimensions |
71
+
72
+ ## Endpoints
73
+
74
+ Every endpoint below is exposed twice from the same implementation: as a public
75
+ method on `MemgraphTools` and as an `mgtools` subcommand of the same name. The
76
+ [`memgraph-ingester-mcp`](https://github.com/ousatov-ua/memgraph-ingester-mcp)
77
+ server registers the identical set as MCP tools.
78
+
79
+ ### Code graph endpoints
80
+
81
+ | Endpoint | Description |
82
+ | --- | --- |
83
+ | `server_status` | Graph inventory, memory counts, and vector index status for a project. |
84
+ | `code_orientation` | Compact package/type/call overview; pass `sections` to keep it focused. |
85
+ | `code_search` | Hybrid CodeChunk search — vector + lexical signals fused by reciprocal rank; defaults to 5 non-test, deduped, primary/file-role hits with compact filters (`kinds`, `path_prefixes`, `path_contains`, `owner_fragment`, `min_score`). |
86
+ | `code_text_search` | Ranked lexical search over indexed chunk text/path/source ids for concrete-term discovery; returns `termMatches`. |
87
+ | `code_discovery_context` | Semantic discovery plus bounded exact/caller/callee/file context in one compact response. |
88
+ | `code_flow_context` | Workflow discovery with semantic/lexical anchors, likely file outlines, related paths, and bounded nearby call edges; pass `detail="full"` for wider expansion. |
89
+ | `code_file_context` | Deterministic file outlines with language, definition/chunk counts, RAG role counts, and top symbols. |
90
+ | `code_lookup_type` | Exact class/interface/annotation lookup by name or FQN; member expansion and test code are opt-in. |
91
+ | `code_lookup_methods` | Exact method lookup by signature fragment with source ranges; defaults to 10 compact owner/name/path rows. |
92
+ | `code_lookup_field` | Exact field/constant lookup by FQN or name fragment; compact owner/name/FQN/path rows. |
93
+ | `code_lookup_file` | Indexed file/resource lookup by path fragment with definition and RAG chunk counts. |
94
+ | `code_callers` | Methods that call matching callee signatures; compact, paginated, range-first rows. |
95
+ | `code_callees` | Callees invoked by matching caller signatures; compact, paginated, range-first rows. |
96
+ | `code_method_context` | Bundled exact method lookup plus caller and callee context for tracing one target. |
97
+ | `code_impact` | Refactor blast-radius for matching method signatures: target methods plus depth-1/depth-2 callers, test flags, and file/package boundary flags; `view="files"` returns a risk-ranked file list. |
98
+ | `code_hot_paths` | Hot-path candidates from type size, method size, fan-in, and fan-out; `include_evidence=true` adds source locations. |
99
+ | `code_operation_hot_paths` | Methods with many calls into operation-like sinks (run/query/write/read/save/delete…); accepts owner/path filters for subsystem audits. |
100
+ | `code_resource_risk_scan` | Heuristic scan of query/config/resource files for risky patterns such as unbounded graph traversals, repeated subqueries, and per-row writes. |
101
+ | `code_quality_stats` | Graph-wide code quality and quantity metrics; defaults to non-test code. |
102
+ | `code_hierarchy` | Class ancestry, children, interfaces, and interface implementors for one FQN. |
103
+ | `code_test_context` | Failing-test/CI triage from a test name or class fragment to tests, test files, and production callees. |
104
+ | `raw_read_cypher` | Read-only, project-scoped Cypher escape hatch for edge cases. |
105
+
106
+ ### Memory endpoints
107
+
108
+ | Endpoint | Description |
109
+ | --- | --- |
110
+ | `memory_orientation` | Rules plus open findings, tasks, questions, and risks; `compact=true` omits body fields. |
111
+ | `memory_schema` | Allowed memory types, upsert fields, controlled values, and CodeRef targets. |
112
+ | `memory_search` | MemoryChunk vector search with index-only hit metadata. |
113
+ | `memory_get` | Canonical memory node plus resolved CodeRefs. |
114
+ | `memory_upsert` | Create/update `Decision`, `ADR`, `Rule`, `Context`, `Finding`, `Task`, `Risk`, `Question`, or `Idea`. |
115
+ | `memory_update_status` | Lifecycle status update with controlled-value validation. |
116
+ | `delete_memory` | Delete one memory node plus its derived chunk and orphan CodeRefs. |
117
+ | `memory_link_code_ref` | Link a memory node to a resolved `Code`/`Package`/`File`/`Class`/`Interface`/`Annotation`/`Method`/`Field` target. |
118
+ | `memory_refresh_chunk` | Rebuild one derived MemoryChunk (optionally re-embedding it). |
119
+ | `memory_refresh_embeddings` | Refresh embeddings for selected MemoryChunk ids and stamp metadata. |
120
+
121
+ Write operations (`memory_upsert`, `memory_update_status`, `delete_memory`,
122
+ `memory_link_code_ref`, `memory_refresh_chunk`, `memory_refresh_embeddings`)
123
+ are rejected when `MEMGRAPH_TOOLS_READ_ONLY=true`.
124
+
125
+ ## CLI usage
126
+
127
+ Every endpoint above is available as an `mgtools` subcommand:
128
+
129
+ ```bash
130
+ # graph inventory, memory counts, vector indexes
131
+ mgtools server_status --project my-project
132
+
133
+ # hybrid vector + lexical code search
134
+ mgtools code_search "authentication filter" --project my-project --limit 5
135
+
136
+ # exact lookups
137
+ mgtools code_lookup_methods "GraphWriter.upsertFile" --project my-project
138
+ mgtools code_lookup_type --type-name GraphWriter --project my-project
139
+
140
+ # call graph and refactor impact
141
+ mgtools code_callers "GraphWriter.upsertFile" --project my-project
142
+ mgtools code_impact "upsertFile" --view files --project my-project
143
+
144
+ # memory tools
145
+ mgtools memory_orientation --project my-project --compact
146
+ mgtools memory_search "ingestion pipeline decisions" --project my-project
147
+
148
+ # read-only Cypher escape hatch (project filter required)
149
+ mgtools raw_read_cypher \
150
+ "MATCH (f:File {project: \$project}) RETURN f.path LIMIT 10" \
151
+ --project my-project
152
+ ```
153
+
154
+ Run `mgtools --help` for the full command list and `mgtools <command> --help`
155
+ for per-command options. `python -m memgraph_ingester_tool` works as well.
156
+
157
+ ## Library usage
158
+
159
+ ```python
160
+ from memgraph_ingester_tool import MemgraphTools, ToolConfig
161
+
162
+ tools = MemgraphTools(ToolConfig(default_project="my-project"))
163
+ status = tools.server_status()
164
+ hits = tools.code_search("authentication filter", limit=5)
165
+ ```
166
+
167
+ `MemgraphTools` also accepts a pre-built client (anything implementing
168
+ `run(query, parameters, *, write=False)`), which is how the MCP server reuses
169
+ its own connection:
170
+
171
+ ```python
172
+ tools = MemgraphTools(config, client=my_client)
173
+ ```
174
+
175
+ ## Output formats
176
+
177
+ Row-heavy commands default to `table_json` — a compact `{cols: [...], rows: [...]}`
178
+ encoding. Pass `--format json` for plain objects. Absent keys mean null or
179
+ empty, never an error.
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ uv sync
185
+ uv run pytest
186
+ uv run ruff check .
187
+ ```
188
+
189
+ ## License
190
+
191
+ MIT
@@ -0,0 +1,167 @@
1
+ # memgraph-ingester-tool
2
+
3
+ [![PyPI release](https://img.shields.io/pypi/v/memgraph-ingester-tool)](https://pypi.org/project/memgraph-ingester-tool/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/memgraph-ingester-tool)](https://pypi.org/project/memgraph-ingester-tool/)
5
+ [![License](https://img.shields.io/pypi/l/memgraph-ingester-tool)](https://github.com/ousatov-ua/memgraph-ingester-tool/blob/main/LICENSE)
6
+
7
+ Standalone query tools for Memgraph knowledge graphs produced by
8
+ [`memgraph-ingester`](https://github.com/ousatov-ua/memgraph-ingester).
9
+
10
+ This package is the **single source of truth** for all graph query and
11
+ formatting logic. It is consumed two ways:
12
+
13
+ - as a **library** by [`memgraph-ingester-mcp`](https://github.com/ousatov-ua/memgraph-ingester-mcp),
14
+ which exposes every method as an MCP tool;
15
+ - as a **CLI** (`mgtools`) for users who work with `mgconsole` or scripts and
16
+ have no MCP client.
17
+
18
+ Any change to query logic here automatically reaches both audiences.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install memgraph-ingester-tool
24
+ # or
25
+ uv tool install memgraph-ingester-tool
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ Settings come from environment variables. `MEMGRAPH_TOOLS_*` take priority;
31
+ `MEMGRAPH_INGESTER_MCP_*` are accepted as a fallback so existing MCP
32
+ configurations keep working.
33
+
34
+ | Variable | Default | Description |
35
+ | --- | --- | --- |
36
+ | `MEMGRAPH_TOOLS_BOLT_URI` | `bolt://127.0.0.1:7687` | Memgraph Bolt endpoint |
37
+ | `MEMGRAPH_TOOLS_USERNAME` | _none_ | Bolt username |
38
+ | `MEMGRAPH_TOOLS_PASSWORD` | _none_ | Bolt password |
39
+ | `MEMGRAPH_TOOLS_DATABASE` | _none_ | Database name |
40
+ | `MEMGRAPH_TOOLS_PROJECT` | _none_ | Default project (`:Project` anchor name) |
41
+ | `MEMGRAPH_TOOLS_QUERY_TIMEOUT_SECONDS` | `30.0` | Per-query timeout |
42
+ | `MEMGRAPH_TOOLS_READ_ONLY` | `false` | Disable write operations |
43
+ | `MEMGRAPH_TOOLS_CODE_EMBEDDING_INDEX` | `code_chunk_embedding_v2` | Code vector index base name |
44
+ | `MEMGRAPH_TOOLS_MEMORY_EMBEDDING_INDEX` | `memory_chunk_embedding_v2` | Memory vector index base name |
45
+ | `MEMGRAPH_TOOLS_EMBEDDING_MODEL` | `default` | Embedding model name |
46
+ | `MEMGRAPH_TOOLS_EMBEDDING_DIMENSIONS` | `384` | Embedding dimensions |
47
+
48
+ ## Endpoints
49
+
50
+ Every endpoint below is exposed twice from the same implementation: as a public
51
+ method on `MemgraphTools` and as an `mgtools` subcommand of the same name. The
52
+ [`memgraph-ingester-mcp`](https://github.com/ousatov-ua/memgraph-ingester-mcp)
53
+ server registers the identical set as MCP tools.
54
+
55
+ ### Code graph endpoints
56
+
57
+ | Endpoint | Description |
58
+ | --- | --- |
59
+ | `server_status` | Graph inventory, memory counts, and vector index status for a project. |
60
+ | `code_orientation` | Compact package/type/call overview; pass `sections` to keep it focused. |
61
+ | `code_search` | Hybrid CodeChunk search — vector + lexical signals fused by reciprocal rank; defaults to 5 non-test, deduped, primary/file-role hits with compact filters (`kinds`, `path_prefixes`, `path_contains`, `owner_fragment`, `min_score`). |
62
+ | `code_text_search` | Ranked lexical search over indexed chunk text/path/source ids for concrete-term discovery; returns `termMatches`. |
63
+ | `code_discovery_context` | Semantic discovery plus bounded exact/caller/callee/file context in one compact response. |
64
+ | `code_flow_context` | Workflow discovery with semantic/lexical anchors, likely file outlines, related paths, and bounded nearby call edges; pass `detail="full"` for wider expansion. |
65
+ | `code_file_context` | Deterministic file outlines with language, definition/chunk counts, RAG role counts, and top symbols. |
66
+ | `code_lookup_type` | Exact class/interface/annotation lookup by name or FQN; member expansion and test code are opt-in. |
67
+ | `code_lookup_methods` | Exact method lookup by signature fragment with source ranges; defaults to 10 compact owner/name/path rows. |
68
+ | `code_lookup_field` | Exact field/constant lookup by FQN or name fragment; compact owner/name/FQN/path rows. |
69
+ | `code_lookup_file` | Indexed file/resource lookup by path fragment with definition and RAG chunk counts. |
70
+ | `code_callers` | Methods that call matching callee signatures; compact, paginated, range-first rows. |
71
+ | `code_callees` | Callees invoked by matching caller signatures; compact, paginated, range-first rows. |
72
+ | `code_method_context` | Bundled exact method lookup plus caller and callee context for tracing one target. |
73
+ | `code_impact` | Refactor blast-radius for matching method signatures: target methods plus depth-1/depth-2 callers, test flags, and file/package boundary flags; `view="files"` returns a risk-ranked file list. |
74
+ | `code_hot_paths` | Hot-path candidates from type size, method size, fan-in, and fan-out; `include_evidence=true` adds source locations. |
75
+ | `code_operation_hot_paths` | Methods with many calls into operation-like sinks (run/query/write/read/save/delete…); accepts owner/path filters for subsystem audits. |
76
+ | `code_resource_risk_scan` | Heuristic scan of query/config/resource files for risky patterns such as unbounded graph traversals, repeated subqueries, and per-row writes. |
77
+ | `code_quality_stats` | Graph-wide code quality and quantity metrics; defaults to non-test code. |
78
+ | `code_hierarchy` | Class ancestry, children, interfaces, and interface implementors for one FQN. |
79
+ | `code_test_context` | Failing-test/CI triage from a test name or class fragment to tests, test files, and production callees. |
80
+ | `raw_read_cypher` | Read-only, project-scoped Cypher escape hatch for edge cases. |
81
+
82
+ ### Memory endpoints
83
+
84
+ | Endpoint | Description |
85
+ | --- | --- |
86
+ | `memory_orientation` | Rules plus open findings, tasks, questions, and risks; `compact=true` omits body fields. |
87
+ | `memory_schema` | Allowed memory types, upsert fields, controlled values, and CodeRef targets. |
88
+ | `memory_search` | MemoryChunk vector search with index-only hit metadata. |
89
+ | `memory_get` | Canonical memory node plus resolved CodeRefs. |
90
+ | `memory_upsert` | Create/update `Decision`, `ADR`, `Rule`, `Context`, `Finding`, `Task`, `Risk`, `Question`, or `Idea`. |
91
+ | `memory_update_status` | Lifecycle status update with controlled-value validation. |
92
+ | `delete_memory` | Delete one memory node plus its derived chunk and orphan CodeRefs. |
93
+ | `memory_link_code_ref` | Link a memory node to a resolved `Code`/`Package`/`File`/`Class`/`Interface`/`Annotation`/`Method`/`Field` target. |
94
+ | `memory_refresh_chunk` | Rebuild one derived MemoryChunk (optionally re-embedding it). |
95
+ | `memory_refresh_embeddings` | Refresh embeddings for selected MemoryChunk ids and stamp metadata. |
96
+
97
+ Write operations (`memory_upsert`, `memory_update_status`, `delete_memory`,
98
+ `memory_link_code_ref`, `memory_refresh_chunk`, `memory_refresh_embeddings`)
99
+ are rejected when `MEMGRAPH_TOOLS_READ_ONLY=true`.
100
+
101
+ ## CLI usage
102
+
103
+ Every endpoint above is available as an `mgtools` subcommand:
104
+
105
+ ```bash
106
+ # graph inventory, memory counts, vector indexes
107
+ mgtools server_status --project my-project
108
+
109
+ # hybrid vector + lexical code search
110
+ mgtools code_search "authentication filter" --project my-project --limit 5
111
+
112
+ # exact lookups
113
+ mgtools code_lookup_methods "GraphWriter.upsertFile" --project my-project
114
+ mgtools code_lookup_type --type-name GraphWriter --project my-project
115
+
116
+ # call graph and refactor impact
117
+ mgtools code_callers "GraphWriter.upsertFile" --project my-project
118
+ mgtools code_impact "upsertFile" --view files --project my-project
119
+
120
+ # memory tools
121
+ mgtools memory_orientation --project my-project --compact
122
+ mgtools memory_search "ingestion pipeline decisions" --project my-project
123
+
124
+ # read-only Cypher escape hatch (project filter required)
125
+ mgtools raw_read_cypher \
126
+ "MATCH (f:File {project: \$project}) RETURN f.path LIMIT 10" \
127
+ --project my-project
128
+ ```
129
+
130
+ Run `mgtools --help` for the full command list and `mgtools <command> --help`
131
+ for per-command options. `python -m memgraph_ingester_tool` works as well.
132
+
133
+ ## Library usage
134
+
135
+ ```python
136
+ from memgraph_ingester_tool import MemgraphTools, ToolConfig
137
+
138
+ tools = MemgraphTools(ToolConfig(default_project="my-project"))
139
+ status = tools.server_status()
140
+ hits = tools.code_search("authentication filter", limit=5)
141
+ ```
142
+
143
+ `MemgraphTools` also accepts a pre-built client (anything implementing
144
+ `run(query, parameters, *, write=False)`), which is how the MCP server reuses
145
+ its own connection:
146
+
147
+ ```python
148
+ tools = MemgraphTools(config, client=my_client)
149
+ ```
150
+
151
+ ## Output formats
152
+
153
+ Row-heavy commands default to `table_json` — a compact `{cols: [...], rows: [...]}`
154
+ encoding. Pass `--format json` for plain objects. Absent keys mean null or
155
+ empty, never an error.
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ uv sync
161
+ uv run pytest
162
+ uv run ruff check .
163
+ ```
164
+
165
+ ## License
166
+
167
+ MIT
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "memgraph-ingester-tool"
3
+ version = "0.1.0"
4
+ description = "Standalone query tools for Memgraph graphs created by memgraph-ingester"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ authors = [{ name = "Oleksii Usatov" }]
9
+ keywords = ["memgraph", "knowledge-graph", "rag", "codex", "cli"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Topic :: Database",
19
+ "Topic :: Software Development :: Libraries :: Python Modules",
20
+ ]
21
+ dependencies = [
22
+ "neo4j>=5.28.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/ousatov-ua/memgraph-ingester-tool"
27
+ Repository = "https://github.com/ousatov-ua/memgraph-ingester-tool"
28
+ Issues = "https://github.com/ousatov-ua/memgraph-ingester-tool/issues"
29
+
30
+ [project.scripts]
31
+ mgtools = "memgraph_ingester_tool.cli:main"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=8.3.0",
36
+ "ruff>=0.8.0",
37
+ ]
38
+
39
+ [build-system]
40
+ requires = ["hatchling"]
41
+ build-backend = "hatchling.build"
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/memgraph_ingester_tool"]
45
+
46
+ [tool.ruff]
47
+ line-length = 100
48
+ target-version = "py311"
49
+
50
+ [tool.ruff.lint]
51
+ select = ["E", "F", "I", "UP", "B", "SIM", "C4", "RUF"]
52
+
53
+ [tool.pytest.ini_options]
54
+ addopts = "-q"
55
+ testpaths = ["tests"]
@@ -0,0 +1,7 @@
1
+ """memgraph-ingester-tool — standalone query tools for Memgraph knowledge graphs."""
2
+
3
+ from memgraph_ingester_tool.config import ToolConfig
4
+ from memgraph_ingester_tool.db import ToolClient, ToolError
5
+ from memgraph_ingester_tool.tools import MemgraphTools
6
+
7
+ __all__ = ["MemgraphTools", "ToolClient", "ToolConfig", "ToolError"]
@@ -0,0 +1,5 @@
1
+ """Allow ``python -m memgraph_ingester_tool`` to invoke the CLI."""
2
+
3
+ from memgraph_ingester_tool.cli import main
4
+
5
+ main()