@sharkdyt/omni-memory-mcp 1.0.0
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.
- package/LICENSE +190 -0
- package/README.md +219 -0
- package/dist/database.d.ts +26 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +257 -0
- package/dist/database.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/add.d.ts +13 -0
- package/dist/tools/add.d.ts.map +1 -0
- package/dist/tools/add.js +36 -0
- package/dist/tools/add.js.map +1 -0
- package/dist/tools/delete.d.ts +10 -0
- package/dist/tools/delete.d.ts.map +1 -0
- package/dist/tools/delete.js +46 -0
- package/dist/tools/delete.js.map +1 -0
- package/dist/tools/get.d.ts +10 -0
- package/dist/tools/get.d.ts.map +1 -0
- package/dist/tools/get.js +46 -0
- package/dist/tools/get.js.map +1 -0
- package/dist/tools/index.d.ts +15 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list.d.ts +13 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +62 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/search.d.ts +13 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +54 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/update.d.ts +14 -0
- package/dist/tools/update.d.ts.map +1 -0
- package/dist/tools/update.js +60 -0
- package/dist/tools/update.js.map +1 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Allan Schramm
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Omni Memory MCP
|
|
2
|
+
|
|
3
|
+
Universal memory MCP server for multi-agent workflows.
|
|
4
|
+
100% local with SQLite + FTS5.
|
|
5
|
+
|
|
6
|
+
## Why this exists
|
|
7
|
+
|
|
8
|
+
- Keep AI memory local (no cloud dependency)
|
|
9
|
+
- Reuse the same memory across tools/agents
|
|
10
|
+
- Search fast with SQLite FTS5
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Local-first storage (SQLite)
|
|
15
|
+
- Full-text search with FTS5
|
|
16
|
+
- MCP-native tools
|
|
17
|
+
- CRUD operations (`memory_add`, `memory_get`, `memory_update`, `memory_delete`, `memory_list`, `memory_search`)
|
|
18
|
+
- Organization by `area`, `project`, and `tags`
|
|
19
|
+
|
|
20
|
+
## Quick Start (Most Newbie Friendly)
|
|
21
|
+
|
|
22
|
+
You do **not** need to set a path to `dist/index.js` if you use `npx`.
|
|
23
|
+
|
|
24
|
+
Use this in your MCP client config:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"mcpServers": {
|
|
29
|
+
"omni-memory": {
|
|
30
|
+
"command": "npx",
|
|
31
|
+
"args": ["-y", "@sharkdyt/omni-memory-mcp"],
|
|
32
|
+
"env": {
|
|
33
|
+
"OMNI_MEMORY_DIR": "~/.omni-memory"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This is the easiest setup because:
|
|
41
|
+
- No manual clone path
|
|
42
|
+
- No manual build path
|
|
43
|
+
- Works after npm registry publish
|
|
44
|
+
|
|
45
|
+
## Path Guide (Relative vs Absolute)
|
|
46
|
+
|
|
47
|
+
If you prefer running from local source (`dist/index.js`), use an **absolute path**.
|
|
48
|
+
|
|
49
|
+
- Relative path example (can break): `./dist/index.js`
|
|
50
|
+
- Absolute path example (recommended): full path to file on disk
|
|
51
|
+
|
|
52
|
+
Why relative paths break:
|
|
53
|
+
- Many MCP clients resolve paths from their own process working directory, not from your config file directory.
|
|
54
|
+
|
|
55
|
+
### Absolute path examples
|
|
56
|
+
|
|
57
|
+
Linux:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"command": "node",
|
|
62
|
+
"args": ["/home/your-user/.local/mcp/omni-memory-mcp/dist/index.js"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
macOS:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"command": "node",
|
|
71
|
+
"args": ["/Users/your-user/.local/mcp/omni-memory-mcp/dist/index.js"]
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Windows:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"command": "node",
|
|
80
|
+
"args": ["C:\\Users\\your-user\\.local\\mcp\\omni-memory-mcp\\dist\\index.js"]
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Note:
|
|
85
|
+
- `~` is convenient, but not every client expands it consistently on Windows. Absolute paths are safer.
|
|
86
|
+
|
|
87
|
+
## Install from Source (Local Dev)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
git clone https://github.com/allanschramm/omni-memory-mcp.git
|
|
91
|
+
cd omni-memory-mcp
|
|
92
|
+
npm install
|
|
93
|
+
npm run build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Then configure your MCP client with `node` + absolute path to `dist/index.js`.
|
|
97
|
+
|
|
98
|
+
## Tools
|
|
99
|
+
|
|
100
|
+
### `memory_add`
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"content": "User prefers TypeScript with strict mode",
|
|
105
|
+
"area": "preferences",
|
|
106
|
+
"project": "my-project",
|
|
107
|
+
"tags": ["typescript", "coding-style"]
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `memory_get`
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"id": "abc123"
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `memory_update`
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"id": "abc123",
|
|
124
|
+
"content": "Updated content",
|
|
125
|
+
"tags": ["new-tag"]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `memory_delete`
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"id": "abc123"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `memory_list`
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"area": "snippets",
|
|
142
|
+
"project": "my-project",
|
|
143
|
+
"tag": "important",
|
|
144
|
+
"limit": 20
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `memory_search`
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"query": "typescript configuration",
|
|
153
|
+
"project": "my-project",
|
|
154
|
+
"limit": 10
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Memory Areas
|
|
159
|
+
|
|
160
|
+
| Area | Description |
|
|
161
|
+
| --- | --- |
|
|
162
|
+
| `general` | General notes |
|
|
163
|
+
| `snippets` | Code snippets and patterns |
|
|
164
|
+
| `solutions` | Problem-solution pairs |
|
|
165
|
+
| `preferences` | User/team preferences |
|
|
166
|
+
|
|
167
|
+
## Data Storage
|
|
168
|
+
|
|
169
|
+
Default directory:
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
~/.omni-memory/
|
|
173
|
+
|- omni-memory.db
|
|
174
|
+
|- omni-memory.db-wal
|
|
175
|
+
`- omni-memory.db-shm
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Environment variables:
|
|
179
|
+
|
|
180
|
+
| Variable | Default | Description |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `OMNI_MEMORY_DIR` | `~/.omni-memory` | Data storage directory |
|
|
183
|
+
| `OMNI_MEMORY_DB` | `{OMNI_MEMORY_DIR}/omni-memory.db` | SQLite DB file path |
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
npm install
|
|
189
|
+
npm run check
|
|
190
|
+
npm run build
|
|
191
|
+
npm test
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Extra commands:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
npm run dev # watch mode
|
|
198
|
+
npm run start # run server from dist/
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Publish to npm
|
|
202
|
+
|
|
203
|
+
Checklist:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
npm whoami
|
|
207
|
+
npm run check
|
|
208
|
+
npm test
|
|
209
|
+
npm pack
|
|
210
|
+
npm publish --access public
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Notes:
|
|
214
|
+
- Package name is scoped: `@sharkdyt/omni-memory-mcp`
|
|
215
|
+
- `publishConfig.access=public` is already configured in `package.json`
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
Apache 2.0. See `LICENSE`.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omni Memory MCP - Database Module
|
|
3
|
+
* SQLite + FTS5 for local memory storage and full-text search
|
|
4
|
+
*/
|
|
5
|
+
import type { Memory, AddMemoryArgs, UpdateMemoryArgs, ListMemoryArgs, SearchMemoryArgs, SearchResult } from "./types.js";
|
|
6
|
+
declare function normalizeUserPath(inputPath: string): string;
|
|
7
|
+
declare function resolveStoragePaths(): {
|
|
8
|
+
dataDir: string;
|
|
9
|
+
dbPath: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function addMemory(args: AddMemoryArgs): {
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function getMemory(id: string): Memory | null;
|
|
15
|
+
export declare function updateMemory(args: UpdateMemoryArgs): {
|
|
16
|
+
changes: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function deleteMemory(id: string): {
|
|
19
|
+
changes: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function listMemories(args: ListMemoryArgs): Memory[];
|
|
22
|
+
export declare function searchMemories(args: SearchMemoryArgs): SearchResult[];
|
|
23
|
+
export declare function closeDatabase(): void;
|
|
24
|
+
export { resolveStoragePaths, normalizeUserPath };
|
|
25
|
+
export declare function resetDatabase(): void;
|
|
26
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,KAAK,EACV,MAAM,EAEN,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACb,MAAM,YAAY,CAAC;AAcpB,iBAAS,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CASpD;AAED,iBAAS,mBAAmB,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAQlE;AAuFD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAe7D;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMnD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAwBxE;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAM5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,EAAE,CA6B3D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,YAAY,EAAE,CA8CrE;AA+BD,wBAAgB,aAAa,IAAI,IAAI,CAKpC;AAED,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,CAAC;AAGlD,wBAAgB,aAAa,IAAI,IAAI,CASpC"}
|
package/dist/database.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omni Memory MCP - Database Module
|
|
3
|
+
* SQLite + FTS5 for local memory storage and full-text search
|
|
4
|
+
*/
|
|
5
|
+
import Database from "better-sqlite3";
|
|
6
|
+
import { v4 as uuidv4 } from "uuid";
|
|
7
|
+
import { join, dirname, isAbsolute, resolve, normalize } from "path";
|
|
8
|
+
import { mkdirSync, existsSync } from "fs";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
function expandHomePath(inputPath) {
|
|
11
|
+
if (inputPath === "~") {
|
|
12
|
+
return homedir();
|
|
13
|
+
}
|
|
14
|
+
if (inputPath.startsWith("~/") || inputPath.startsWith("~\\")) {
|
|
15
|
+
return join(homedir(), inputPath.slice(2));
|
|
16
|
+
}
|
|
17
|
+
return inputPath;
|
|
18
|
+
}
|
|
19
|
+
function normalizeUserPath(inputPath) {
|
|
20
|
+
const trimmedPath = inputPath.trim();
|
|
21
|
+
const expandedPath = expandHomePath(trimmedPath);
|
|
22
|
+
if (isAbsolute(expandedPath)) {
|
|
23
|
+
return normalize(expandedPath);
|
|
24
|
+
}
|
|
25
|
+
return normalize(resolve(process.cwd(), expandedPath));
|
|
26
|
+
}
|
|
27
|
+
function resolveStoragePaths() {
|
|
28
|
+
const defaultDir = join(homedir(), ".omni-memory");
|
|
29
|
+
const dataDir = normalizeUserPath(process.env.OMNI_MEMORY_DIR || defaultDir);
|
|
30
|
+
const dbPath = process.env.OMNI_MEMORY_DB
|
|
31
|
+
? normalizeUserPath(process.env.OMNI_MEMORY_DB)
|
|
32
|
+
: join(dataDir, "omni-memory.db");
|
|
33
|
+
return { dataDir, dbPath };
|
|
34
|
+
}
|
|
35
|
+
const { dataDir: DATA_DIR, dbPath: DB_PATH } = resolveStoragePaths();
|
|
36
|
+
let db = null;
|
|
37
|
+
function getDatabase() {
|
|
38
|
+
if (db)
|
|
39
|
+
return db;
|
|
40
|
+
// Ensure storage directories exist
|
|
41
|
+
if (!existsSync(DATA_DIR)) {
|
|
42
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
const dbDirectory = dirname(DB_PATH);
|
|
45
|
+
if (!existsSync(dbDirectory)) {
|
|
46
|
+
mkdirSync(dbDirectory, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
db = new Database(DB_PATH);
|
|
49
|
+
db.pragma("journal_mode = WAL");
|
|
50
|
+
initializeSchema(db);
|
|
51
|
+
return db;
|
|
52
|
+
}
|
|
53
|
+
function initializeSchema(database) {
|
|
54
|
+
// Create memories table
|
|
55
|
+
database.exec(`
|
|
56
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
57
|
+
id TEXT PRIMARY KEY,
|
|
58
|
+
content TEXT NOT NULL,
|
|
59
|
+
area TEXT DEFAULT 'general',
|
|
60
|
+
project TEXT,
|
|
61
|
+
tags TEXT DEFAULT '[]',
|
|
62
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
63
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
64
|
+
)
|
|
65
|
+
`);
|
|
66
|
+
// Create FTS5 virtual table
|
|
67
|
+
database.exec(`
|
|
68
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
69
|
+
content,
|
|
70
|
+
project,
|
|
71
|
+
tags,
|
|
72
|
+
content='memories',
|
|
73
|
+
content_rowid='rowid'
|
|
74
|
+
)
|
|
75
|
+
`);
|
|
76
|
+
// Create triggers for FTS sync
|
|
77
|
+
database.exec(`
|
|
78
|
+
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
79
|
+
INSERT INTO memories_fts(rowid, content, project, tags)
|
|
80
|
+
VALUES (new.rowid, new.content, COALESCE(new.project, ''), new.tags);
|
|
81
|
+
END
|
|
82
|
+
`);
|
|
83
|
+
database.exec(`
|
|
84
|
+
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
85
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, project, tags)
|
|
86
|
+
VALUES('delete', old.rowid, old.content, COALESCE(old.project, ''), old.tags);
|
|
87
|
+
END
|
|
88
|
+
`);
|
|
89
|
+
database.exec(`
|
|
90
|
+
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
91
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, project, tags)
|
|
92
|
+
VALUES('delete', old.rowid, old.content, COALESCE(old.project, ''), old.tags);
|
|
93
|
+
INSERT INTO memories_fts(rowid, content, project, tags)
|
|
94
|
+
VALUES (new.rowid, new.content, COALESCE(new.project, ''), new.tags);
|
|
95
|
+
END
|
|
96
|
+
`);
|
|
97
|
+
}
|
|
98
|
+
function rowToMemory(row) {
|
|
99
|
+
return {
|
|
100
|
+
id: row.id,
|
|
101
|
+
content: row.content,
|
|
102
|
+
area: row.area || "general",
|
|
103
|
+
project: row.project,
|
|
104
|
+
tags: JSON.parse(row.tags || "[]"),
|
|
105
|
+
created_at: row.created_at,
|
|
106
|
+
updated_at: row.updated_at,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function addMemory(args) {
|
|
110
|
+
const database = getDatabase();
|
|
111
|
+
const id = uuidv4();
|
|
112
|
+
const area = args.area || "general";
|
|
113
|
+
const project = args.project || null;
|
|
114
|
+
const tags = JSON.stringify(args.tags || []);
|
|
115
|
+
const stmt = database.prepare(`
|
|
116
|
+
INSERT INTO memories (id, content, area, project, tags)
|
|
117
|
+
VALUES (?, ?, ?, ?, ?)
|
|
118
|
+
`);
|
|
119
|
+
stmt.run(id, args.content, area, project, tags);
|
|
120
|
+
return { id };
|
|
121
|
+
}
|
|
122
|
+
export function getMemory(id) {
|
|
123
|
+
const database = getDatabase();
|
|
124
|
+
const stmt = database.prepare("SELECT * FROM memories WHERE id = ?");
|
|
125
|
+
const row = stmt.get(id);
|
|
126
|
+
return row ? rowToMemory(row) : null;
|
|
127
|
+
}
|
|
128
|
+
export function updateMemory(args) {
|
|
129
|
+
const database = getDatabase();
|
|
130
|
+
// First get existing memory
|
|
131
|
+
const existing = getMemory(args.id);
|
|
132
|
+
if (!existing) {
|
|
133
|
+
return { changes: 0 };
|
|
134
|
+
}
|
|
135
|
+
// Merge updates
|
|
136
|
+
const content = args.content ?? existing.content;
|
|
137
|
+
const area = args.area ?? existing.area;
|
|
138
|
+
const project = args.project !== undefined ? args.project : existing.project;
|
|
139
|
+
const tags = args.tags !== undefined ? JSON.stringify(args.tags) : JSON.stringify(existing.tags);
|
|
140
|
+
const stmt = database.prepare(`
|
|
141
|
+
UPDATE memories
|
|
142
|
+
SET content = ?, area = ?, project = ?, tags = ?, updated_at = datetime('now')
|
|
143
|
+
WHERE id = ?
|
|
144
|
+
`);
|
|
145
|
+
const result = stmt.run(content, area, project, tags, args.id);
|
|
146
|
+
return { changes: result.changes };
|
|
147
|
+
}
|
|
148
|
+
export function deleteMemory(id) {
|
|
149
|
+
const database = getDatabase();
|
|
150
|
+
const stmt = database.prepare("DELETE FROM memories WHERE id = ?");
|
|
151
|
+
const result = stmt.run(id);
|
|
152
|
+
return { changes: result.changes };
|
|
153
|
+
}
|
|
154
|
+
export function listMemories(args) {
|
|
155
|
+
const database = getDatabase();
|
|
156
|
+
const limit = Math.min(args.limit || 50, 100);
|
|
157
|
+
let sql = "SELECT * FROM memories WHERE 1=1";
|
|
158
|
+
const params = [];
|
|
159
|
+
if (args.area) {
|
|
160
|
+
sql += " AND area = ?";
|
|
161
|
+
params.push(args.area);
|
|
162
|
+
}
|
|
163
|
+
if (args.project) {
|
|
164
|
+
sql += " AND project = ?";
|
|
165
|
+
params.push(args.project);
|
|
166
|
+
}
|
|
167
|
+
if (args.tag) {
|
|
168
|
+
sql += " AND tags LIKE ?";
|
|
169
|
+
params.push(`%"${args.tag}"%`);
|
|
170
|
+
}
|
|
171
|
+
sql += " ORDER BY created_at DESC LIMIT ?";
|
|
172
|
+
params.push(limit);
|
|
173
|
+
const stmt = database.prepare(sql);
|
|
174
|
+
const rows = stmt.all(...params);
|
|
175
|
+
return rows.map(rowToMemory);
|
|
176
|
+
}
|
|
177
|
+
export function searchMemories(args) {
|
|
178
|
+
const database = getDatabase();
|
|
179
|
+
const limit = Math.min(args.limit || 10, 50);
|
|
180
|
+
// Build FTS5 query with filters
|
|
181
|
+
let ftsQuery = args.query;
|
|
182
|
+
// Add area filter to query
|
|
183
|
+
if (args.area) {
|
|
184
|
+
// We'll filter results after search
|
|
185
|
+
}
|
|
186
|
+
// Build SQL for FTS search
|
|
187
|
+
let sql = `
|
|
188
|
+
SELECT m.*, fts.rank as score
|
|
189
|
+
FROM memories m
|
|
190
|
+
JOIN memories_fts fts ON m.rowid = fts.rowid
|
|
191
|
+
WHERE memories_fts MATCH ?
|
|
192
|
+
`;
|
|
193
|
+
const params = [ftsQuery];
|
|
194
|
+
if (args.area) {
|
|
195
|
+
sql += " AND m.area = ?";
|
|
196
|
+
params.push(args.area);
|
|
197
|
+
}
|
|
198
|
+
if (args.project) {
|
|
199
|
+
sql += " AND m.project = ?";
|
|
200
|
+
params.push(args.project);
|
|
201
|
+
}
|
|
202
|
+
sql += " ORDER BY fts.rank LIMIT ?";
|
|
203
|
+
params.push(limit);
|
|
204
|
+
try {
|
|
205
|
+
const stmt = database.prepare(sql);
|
|
206
|
+
const rows = stmt.all(...params);
|
|
207
|
+
return rows.map((row) => ({
|
|
208
|
+
...rowToMemory(row),
|
|
209
|
+
score: Math.abs(row.score) || 0,
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
// FTS5 might fail on special characters, fallback to LIKE search
|
|
214
|
+
return fallbackSearch(args);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function fallbackSearch(args) {
|
|
218
|
+
const database = getDatabase();
|
|
219
|
+
const limit = Math.min(args.limit || 10, 50);
|
|
220
|
+
let sql = "SELECT * FROM memories WHERE content LIKE ?";
|
|
221
|
+
const params = [`%${args.query}%`];
|
|
222
|
+
if (args.area) {
|
|
223
|
+
sql += " AND area = ?";
|
|
224
|
+
params.push(args.area);
|
|
225
|
+
}
|
|
226
|
+
if (args.project) {
|
|
227
|
+
sql += " AND project = ?";
|
|
228
|
+
params.push(args.project);
|
|
229
|
+
}
|
|
230
|
+
sql += " ORDER BY created_at DESC LIMIT ?";
|
|
231
|
+
params.push(limit);
|
|
232
|
+
const stmt = database.prepare(sql);
|
|
233
|
+
const rows = stmt.all(...params);
|
|
234
|
+
return rows.map((row) => ({
|
|
235
|
+
...rowToMemory(row),
|
|
236
|
+
score: 0.5, // Default score for fallback search
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
export function closeDatabase() {
|
|
240
|
+
if (db) {
|
|
241
|
+
db.close();
|
|
242
|
+
db = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
export { resolveStoragePaths, normalizeUserPath };
|
|
246
|
+
// For testing
|
|
247
|
+
export function resetDatabase() {
|
|
248
|
+
if (db) {
|
|
249
|
+
db.exec("DROP TABLE IF EXISTS memories");
|
|
250
|
+
db.exec("DROP TABLE IF EXISTS memories_fts");
|
|
251
|
+
db.exec("DROP TRIGGER IF EXISTS memories_ai");
|
|
252
|
+
db.exec("DROP TRIGGER IF EXISTS memories_ad");
|
|
253
|
+
db.exec("DROP TRIGGER IF EXISTS memories_au");
|
|
254
|
+
initializeSchema(db);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=database.js.map
|