@nuzo/mcp-server 0.1.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 ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ 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 source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work.
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form,
39
+ that is based on (or derived from) the Work and for which the editorial
40
+ revisions, annotations, elaborations, or other modifications represent, as a
41
+ whole, an original work of authorship. For the purposes of this License,
42
+ Derivative Works shall not include works that remain separable from, or
43
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
44
+ Works thereof.
45
+
46
+ "Contribution" shall mean any work of authorship, including the original
47
+ version of the Work and any modifications or additions to that Work or
48
+ Derivative Works thereof, that is intentionally submitted to Licensor for
49
+ inclusion in the Work by the copyright owner or by an individual or Legal
50
+ Entity authorized to submit on behalf of the copyright owner. For the
51
+ purposes of this definition, "submitted" means any form of electronic,
52
+ verbal, or written communication sent to the Licensor or its representatives,
53
+ including but not limited to communication on electronic mailing lists,
54
+ source code control systems, and issue tracking systems that are managed by,
55
+ or on behalf of, the Licensor for the purpose of discussing and improving the
56
+ Work, but excluding communication that is conspicuously marked or otherwise
57
+ designated in writing by the copyright owner as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
60
+ behalf of whom a Contribution has been received by Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
64
+ License, each Contributor hereby grants to You a perpetual, worldwide,
65
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
66
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
67
+ sublicense, and distribute the Work and such Derivative Works in Source or
68
+ Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of this
71
+ License, each Contributor hereby grants to You a perpetual, worldwide,
72
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
73
+ section) patent license to make, have made, use, offer to sell, sell, import,
74
+ and otherwise transfer the Work, where such license applies only to those
75
+ patent claims licensable by such Contributor that are necessarily infringed
76
+ by their Contribution(s) alone or by combination of their Contribution(s)
77
+ with the Work to which such Contribution(s) was submitted. If You institute
78
+ patent litigation against any entity (including a cross-claim or
79
+ counterclaim in a lawsuit) alleging that the Work or a Contribution
80
+ incorporated within the Work constitutes direct or contributory patent
81
+ infringement, then any patent licenses granted to You under this License for
82
+ that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
85
+ Derivative Works thereof in any medium, with or without modifications, and in
86
+ Source or Object form, provided that You meet the following conditions:
87
+
88
+ (a) You must give any other recipients of the Work or Derivative Works a copy
89
+ of this License; and
90
+
91
+ (b) You must cause any modified files to carry prominent notices stating that
92
+ You changed the files; and
93
+
94
+ (c) You must retain, in the Source form of any Derivative Works that You
95
+ distribute, all copyright, patent, trademark, and attribution notices from
96
+ the Source form of the Work, excluding those notices that do not pertain to
97
+ any part of the Derivative Works; and
98
+
99
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
100
+ then any Derivative Works that You distribute must include a readable copy of
101
+ the attribution notices contained within such NOTICE file, excluding those
102
+ notices that do not pertain to any part of the Derivative Works, in at least
103
+ one of the following places: within a NOTICE text file distributed as part of
104
+ the Derivative Works; within the Source form or documentation, if provided
105
+ along with the Derivative Works; or, within a display generated by the
106
+ Derivative Works, if and wherever such third-party notices normally appear.
107
+ The contents of the NOTICE file are for informational purposes only and do
108
+ not modify the License. You may add Your own attribution notices within
109
+ Derivative Works that You distribute, alongside or as an addendum to the
110
+ NOTICE text from the Work, provided that such additional attribution notices
111
+ cannot be construed as modifying the License.
112
+
113
+ You may add Your own copyright statement to Your modifications and may
114
+ provide additional or different license terms and conditions for use,
115
+ reproduction, or distribution of Your modifications, or for any such
116
+ Derivative Works as a whole, provided Your use, reproduction, and
117
+ distribution of the Work otherwise complies with the conditions stated in
118
+ this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the
130
+ Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to
144
+ in writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ Copyright 2026 fabionfsc
165
+
166
+ Licensed under the Apache License, Version 2.0 (the "License");
167
+ you may not use this file except in compliance with the License.
168
+ You may obtain a copy of the License at
169
+
170
+ https://www.apache.org/licenses/LICENSE-2.0
171
+
172
+ Unless required by applicable law or agreed to in writing, software
173
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
174
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ See the License for the specific language governing permissions and
176
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @nuzo/mcp-server
2
+
3
+ The MCP stdio server for Nuzo, a local-first and auditable memory layer for AI
4
+ agents.
5
+
6
+ The server exposes Nuzo memory tools and stores memory locally under
7
+ `~/.nuzo/memory/` by default.
8
+
9
+ Its read-only tools include recall, listing, audit history, export, and doctor
10
+ diagnostics.
11
+
12
+ Run a published version with:
13
+
14
+ ```bash
15
+ npx --yes @nuzo/mcp-server@<version>
16
+ ```
17
+
18
+ Use a fixed version in host plugins and automated configuration. Do not depend
19
+ on `latest` for reproducible installs.
20
+
21
+ Documentation: https://nuzo.com.br/
22
+
23
+ License: Apache-2.0
@@ -0,0 +1,178 @@
1
+ import type { MemoryExportDocument, MemoryKind, MemoryScope, MemoryService } from "@nuzo/memory-core";
2
+ export interface RememberToolInput {
3
+ content: string;
4
+ kind: MemoryKind;
5
+ scope: string;
6
+ tags: string[];
7
+ source: string;
8
+ confidence?: number;
9
+ }
10
+ export interface RecallToolInput {
11
+ query: string;
12
+ scope: string;
13
+ limit: number;
14
+ include_global: boolean;
15
+ }
16
+ export interface RecallHookToolInput {
17
+ task_context: string;
18
+ project_scope?: string;
19
+ limit?: number;
20
+ }
21
+ export interface ListToolInput {
22
+ scope?: string;
23
+ tags: string[];
24
+ include_archived: boolean;
25
+ }
26
+ export interface UpdateToolInput {
27
+ id: string;
28
+ content?: string;
29
+ kind?: MemoryKind;
30
+ scope?: string;
31
+ tags?: string[];
32
+ confidence?: number;
33
+ }
34
+ export interface HistoryToolInput {
35
+ id: string;
36
+ }
37
+ export interface ForgetToolInput {
38
+ id: string;
39
+ mode: "archive" | "delete";
40
+ confirm: boolean;
41
+ reason?: string;
42
+ }
43
+ export interface ForgetManyToolInput {
44
+ scope?: string;
45
+ tags: string[];
46
+ all: boolean;
47
+ mode: "archive" | "delete";
48
+ confirm: boolean;
49
+ dry_run: boolean;
50
+ reason?: string;
51
+ }
52
+ export interface ExportToolInput {
53
+ scope?: string;
54
+ tags: string[];
55
+ include_archived: boolean;
56
+ }
57
+ export interface ImportToolInput {
58
+ document: MemoryExportDocument;
59
+ scope?: string;
60
+ dry_run: boolean;
61
+ }
62
+ export interface MemoryToolHandlerOptions {
63
+ storePath?: string;
64
+ doctorDiagnostics?: MemoryDoctorDiagnostics;
65
+ }
66
+ export interface MemoryDoctorDiagnostics {
67
+ schema?: {
68
+ currentVersion: number;
69
+ supportedVersion: number;
70
+ };
71
+ writable?: boolean;
72
+ }
73
+ export interface MemoryToolHandlers {
74
+ remember(input: RememberToolInput): Promise<{
75
+ id: string;
76
+ created: true;
77
+ warnings: string[];
78
+ }>;
79
+ recall(input: RecallToolInput): Promise<{
80
+ results: Array<{
81
+ id: string;
82
+ content: string;
83
+ kind: MemoryKind;
84
+ scope: MemoryScope;
85
+ tags: string[];
86
+ score: number;
87
+ reason: string;
88
+ }>;
89
+ }>;
90
+ recallHook(input: RecallHookToolInput): Promise<{
91
+ mode: "read_only";
92
+ memory_writes: false;
93
+ capture_suggestions: false;
94
+ query: string;
95
+ scope: MemoryScope;
96
+ include_global: true;
97
+ limit: number;
98
+ results: Array<{
99
+ id: string;
100
+ content: string;
101
+ kind: MemoryKind;
102
+ scope: MemoryScope;
103
+ tags: string[];
104
+ score: number;
105
+ reason: string;
106
+ }>;
107
+ }>;
108
+ list(input: ListToolInput): Promise<{
109
+ memories: MemoryToolRecord[];
110
+ }>;
111
+ update(input: UpdateToolInput): Promise<{
112
+ memory: MemoryToolRecord;
113
+ }>;
114
+ history(input: HistoryToolInput): Promise<{
115
+ events: MemoryToolEvent[];
116
+ }>;
117
+ forget(input: ForgetToolInput): Promise<{
118
+ id: string;
119
+ forgotten: true;
120
+ mode: "archive" | "delete";
121
+ }>;
122
+ forgetMany(input: ForgetManyToolInput): Promise<{
123
+ matched: number;
124
+ affected: number;
125
+ mode: "archive" | "delete";
126
+ dry_run: boolean;
127
+ ids: string[];
128
+ }>;
129
+ exportMemories(input: ExportToolInput): Promise<MemoryExportDocument>;
130
+ importMemories(input: ImportToolInput): Promise<{
131
+ imported: number;
132
+ skipped: number;
133
+ dry_run: boolean;
134
+ }>;
135
+ doctor(): Promise<{
136
+ ok: boolean;
137
+ network: "disabled";
138
+ store: {
139
+ path: string | null;
140
+ readable: boolean;
141
+ writable_check: "writable" | "not_writable" | "not_performed";
142
+ };
143
+ schema: {
144
+ current_version: number | null;
145
+ supported_version: number | null;
146
+ status: "current" | "outdated" | "newer" | "not_performed";
147
+ };
148
+ counts: {
149
+ active_memories: number | null;
150
+ archived_memories: number | null;
151
+ total_memories: number | null;
152
+ };
153
+ tools: string[];
154
+ warnings: string[];
155
+ }>;
156
+ }
157
+ export type MemoryToolRecord = {
158
+ id: string;
159
+ content: string;
160
+ kind: MemoryKind;
161
+ scope: MemoryScope;
162
+ tags: string[];
163
+ source: string;
164
+ confidence: number;
165
+ created_at: string;
166
+ updated_at: string;
167
+ last_used_at: string | null;
168
+ archived_at: string | null;
169
+ };
170
+ export type MemoryToolEvent = {
171
+ id: string;
172
+ memory_id: string | null;
173
+ event_type: string;
174
+ actor: string;
175
+ payload: Record<string, unknown>;
176
+ created_at: string;
177
+ };
178
+ export declare function createMemoryToolHandlers(service: MemoryService, options?: MemoryToolHandlerOptions): MemoryToolHandlers;
@@ -0,0 +1,301 @@
1
+ export function createMemoryToolHandlers(service, options = {}) {
2
+ return {
3
+ async remember(input) {
4
+ const rememberInput = {
5
+ content: input.content,
6
+ kind: input.kind,
7
+ scope: input.scope,
8
+ tags: input.tags,
9
+ source: input.source,
10
+ };
11
+ if (input.confidence !== undefined) {
12
+ rememberInput.confidence = input.confidence;
13
+ }
14
+ const memory = await service.remember(rememberInput);
15
+ return {
16
+ id: memory.id,
17
+ created: true,
18
+ warnings: [],
19
+ };
20
+ },
21
+ async recall(input) {
22
+ const results = await service.recall({
23
+ query: input.query,
24
+ scope: input.scope,
25
+ limit: input.limit,
26
+ includeGlobal: input.include_global,
27
+ });
28
+ return {
29
+ results: results.map(toRecallOutput),
30
+ };
31
+ },
32
+ async recallHook(input) {
33
+ const query = buildRecallHookQuery(input.task_context);
34
+ const limit = clampRecallHookLimit(input.limit);
35
+ const scope = (input.project_scope ?? "project:auto");
36
+ const results = await service.recall({
37
+ query,
38
+ scope,
39
+ limit,
40
+ includeGlobal: true,
41
+ recordUsage: false,
42
+ });
43
+ return {
44
+ mode: "read_only",
45
+ memory_writes: false,
46
+ capture_suggestions: false,
47
+ query,
48
+ scope,
49
+ include_global: true,
50
+ limit,
51
+ results: results.map(toRecallOutput),
52
+ };
53
+ },
54
+ async list(input) {
55
+ const listInput = {
56
+ includeArchived: input.include_archived,
57
+ };
58
+ if (input.scope !== undefined) {
59
+ listInput.scope = input.scope;
60
+ }
61
+ if (input.tags.length > 0) {
62
+ listInput.tags = input.tags;
63
+ }
64
+ const memories = await service.list(listInput);
65
+ return {
66
+ memories: memories.map(toToolRecord),
67
+ };
68
+ },
69
+ async update(input) {
70
+ const updateInput = {
71
+ id: input.id,
72
+ actor: "nuzo:mcp",
73
+ };
74
+ if (input.content !== undefined) {
75
+ updateInput.content = input.content;
76
+ }
77
+ if (input.kind !== undefined) {
78
+ updateInput.kind = input.kind;
79
+ }
80
+ if (input.scope !== undefined) {
81
+ updateInput.scope = input.scope;
82
+ }
83
+ if (input.tags !== undefined) {
84
+ updateInput.tags = input.tags;
85
+ }
86
+ if (input.confidence !== undefined) {
87
+ updateInput.confidence = input.confidence;
88
+ }
89
+ const memory = await service.update(updateInput);
90
+ return {
91
+ memory: toToolRecord(memory),
92
+ };
93
+ },
94
+ async history(input) {
95
+ const events = await service.history(input.id);
96
+ return {
97
+ events: events.map((event) => ({
98
+ id: event.id,
99
+ memory_id: event.memoryId,
100
+ event_type: event.eventType,
101
+ actor: event.actor,
102
+ payload: event.payload,
103
+ created_at: event.createdAt.toISOString(),
104
+ })),
105
+ };
106
+ },
107
+ async forget(input) {
108
+ const forgetInput = {
109
+ id: input.id,
110
+ mode: input.mode,
111
+ confirm: input.confirm,
112
+ actor: "nuzo:mcp",
113
+ };
114
+ if (input.reason !== undefined) {
115
+ forgetInput.reason = input.reason;
116
+ }
117
+ await service.forget(forgetInput);
118
+ return {
119
+ id: input.id,
120
+ forgotten: true,
121
+ mode: input.mode,
122
+ };
123
+ },
124
+ async forgetMany(input) {
125
+ const forgetInput = {
126
+ tags: input.tags,
127
+ all: input.all,
128
+ mode: input.mode,
129
+ confirm: input.confirm,
130
+ dryRun: input.dry_run,
131
+ actor: "nuzo:mcp",
132
+ };
133
+ if (input.scope !== undefined) {
134
+ forgetInput.scope = input.scope;
135
+ }
136
+ if (input.reason !== undefined) {
137
+ forgetInput.reason = input.reason;
138
+ }
139
+ const result = await service.forgetMany(forgetInput);
140
+ return {
141
+ matched: result.matched,
142
+ affected: result.affected,
143
+ mode: result.mode,
144
+ dry_run: result.dryRun,
145
+ ids: result.ids,
146
+ };
147
+ },
148
+ async exportMemories(input) {
149
+ const exportInput = {
150
+ actor: "nuzo:mcp",
151
+ includeArchived: input.include_archived,
152
+ };
153
+ if (input.scope !== undefined) {
154
+ exportInput.scope = input.scope;
155
+ }
156
+ if (input.tags.length > 0) {
157
+ exportInput.tags = input.tags;
158
+ }
159
+ return service.exportMemories(exportInput);
160
+ },
161
+ async importMemories(input) {
162
+ const importInput = {
163
+ document: input.document,
164
+ actor: "nuzo:mcp",
165
+ dryRun: input.dry_run,
166
+ };
167
+ if (input.scope !== undefined) {
168
+ importInput.scope = input.scope;
169
+ }
170
+ const result = await service.importMemories(importInput);
171
+ return {
172
+ imported: result.imported,
173
+ skipped: result.skipped,
174
+ dry_run: result.dryRun,
175
+ };
176
+ },
177
+ async doctor() {
178
+ const warnings = [];
179
+ let activeMemories = null;
180
+ let archivedMemories = null;
181
+ let totalMemories = null;
182
+ let readable = false;
183
+ try {
184
+ const [active, all] = await Promise.all([
185
+ service.list({ includeArchived: false }),
186
+ service.list({ includeArchived: true }),
187
+ ]);
188
+ activeMemories = active.length;
189
+ totalMemories = all.length;
190
+ archivedMemories = Math.max(totalMemories - activeMemories, 0);
191
+ readable = true;
192
+ }
193
+ catch (error) {
194
+ warnings.push(`memory store read check failed: ${formatDoctorError(error)}`);
195
+ }
196
+ const writableCheck = options.doctorDiagnostics?.writable === undefined
197
+ ? "not_performed"
198
+ : options.doctorDiagnostics.writable
199
+ ? "writable"
200
+ : "not_writable";
201
+ if (writableCheck === "not_writable") {
202
+ warnings.push("memory store writability check failed");
203
+ }
204
+ const schema = formatSchemaDiagnostics(options.doctorDiagnostics?.schema);
205
+ if (schema.status === "outdated") {
206
+ warnings.push("memory store schema is older than the supported version");
207
+ }
208
+ if (schema.status === "newer") {
209
+ warnings.push("memory store schema is newer than the supported version");
210
+ }
211
+ return {
212
+ ok: warnings.length === 0,
213
+ network: "disabled",
214
+ store: {
215
+ path: options.storePath ?? null,
216
+ readable,
217
+ writable_check: writableCheck,
218
+ },
219
+ schema,
220
+ counts: {
221
+ active_memories: activeMemories,
222
+ archived_memories: archivedMemories,
223
+ total_memories: totalMemories,
224
+ },
225
+ tools: [
226
+ "memory.remember",
227
+ "memory.recall",
228
+ "memory.recall_hook",
229
+ "memory.list",
230
+ "memory.update",
231
+ "memory.history",
232
+ "memory.forget",
233
+ "memory.forget_many",
234
+ "memory.export",
235
+ "memory.import",
236
+ "memory.doctor",
237
+ ],
238
+ warnings,
239
+ };
240
+ },
241
+ };
242
+ }
243
+ function formatSchemaDiagnostics(schema) {
244
+ if (schema === undefined) {
245
+ return {
246
+ current_version: null,
247
+ supported_version: null,
248
+ status: "not_performed",
249
+ };
250
+ }
251
+ return {
252
+ current_version: schema.currentVersion,
253
+ supported_version: schema.supportedVersion,
254
+ status: schema.currentVersion === schema.supportedVersion
255
+ ? "current"
256
+ : schema.currentVersion < schema.supportedVersion
257
+ ? "outdated"
258
+ : "newer",
259
+ };
260
+ }
261
+ function formatDoctorError(error) {
262
+ if (error instanceof Error && error.message.length > 0) {
263
+ return error.message;
264
+ }
265
+ return "unknown error";
266
+ }
267
+ function buildRecallHookQuery(taskContext) {
268
+ return taskContext.trim().replace(/\s+/g, " ").slice(0, 500);
269
+ }
270
+ function clampRecallHookLimit(limit) {
271
+ if (limit === undefined) {
272
+ return 5;
273
+ }
274
+ return Math.min(Math.max(Math.trunc(limit), 1), 8);
275
+ }
276
+ function toRecallOutput(result) {
277
+ return {
278
+ id: result.memory.id,
279
+ content: result.memory.content,
280
+ kind: result.memory.kind,
281
+ scope: result.memory.scope,
282
+ tags: result.memory.tags,
283
+ score: result.score,
284
+ reason: result.reason,
285
+ };
286
+ }
287
+ function toToolRecord(memory) {
288
+ return {
289
+ id: memory.id,
290
+ content: memory.content,
291
+ kind: memory.kind,
292
+ scope: memory.scope,
293
+ tags: memory.tags,
294
+ source: memory.source,
295
+ confidence: memory.confidence,
296
+ created_at: memory.createdAt.toISOString(),
297
+ updated_at: memory.updatedAt.toISOString(),
298
+ last_used_at: memory.lastUsedAt?.toISOString() ?? null,
299
+ archived_at: memory.archivedAt?.toISOString() ?? null,
300
+ };
301
+ }
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { type MemoryService } from "@nuzo/memory-core";
4
+ import type { MemoryDoctorDiagnostics } from "./handlers.js";
5
+ export interface NuzoMcpServerOptions {
6
+ storePath?: string;
7
+ doctorDiagnostics?: MemoryDoctorDiagnostics;
8
+ }
9
+ export interface NuzoMcpServerRuntime {
10
+ server: McpServer;
11
+ close(): void;
12
+ }
13
+ export declare function createNuzoMcpServer(options?: NuzoMcpServerOptions): McpServer;
14
+ export declare function createNuzoMcpServerRuntime(options?: NuzoMcpServerOptions): NuzoMcpServerRuntime;
15
+ export declare function registerMemoryTools(server: McpServer, service: MemoryService, options?: NuzoMcpServerOptions): void;
package/dist/index.js ADDED
@@ -0,0 +1,333 @@
1
+ #!/usr/bin/env node
2
+ import { accessSync, constants, mkdirSync, realpathSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
+ import { z } from "zod";
9
+ import { createMemoryService, DefaultPolicyEngine, RandomIdGenerator, RegexSecretScanner, SQLiteMemoryDatabase, SystemClock, memoryScopePattern, memoryTagPattern, schemaVersion, } from "@nuzo/memory-core";
10
+ import { createMemoryToolHandlers } from "./handlers.js";
11
+ const defaultStorePath = resolve(homedir(), ".nuzo", "memory", "memories.sqlite");
12
+ const scopeSchema = z.string().regex(memoryScopePattern);
13
+ const tagSchema = z.string().regex(memoryTagPattern);
14
+ export function createNuzoMcpServer(options = {}) {
15
+ return createNuzoMcpServerRuntime(options).server;
16
+ }
17
+ export function createNuzoMcpServerRuntime(options = {}) {
18
+ const storePath = options.storePath ?? defaultStorePath;
19
+ const database = openDatabase(storePath);
20
+ const service = createService(database);
21
+ let closed = false;
22
+ const server = new McpServer({
23
+ name: "nuzo",
24
+ version: "0.1.0",
25
+ });
26
+ registerMemoryTools(server, service, {
27
+ storePath,
28
+ doctorDiagnostics: options.doctorDiagnostics ?? {
29
+ schema: {
30
+ currentVersion: database.getSchemaVersion(),
31
+ supportedVersion: schemaVersion,
32
+ },
33
+ writable: isStoreWritable(storePath),
34
+ },
35
+ });
36
+ return {
37
+ server,
38
+ close: () => {
39
+ if (!closed) {
40
+ database.close();
41
+ closed = true;
42
+ }
43
+ },
44
+ };
45
+ }
46
+ export function registerMemoryTools(server, service, options = {}) {
47
+ const handlerOptions = {
48
+ ...(options.storePath === undefined ? {} : { storePath: options.storePath }),
49
+ ...(options.doctorDiagnostics === undefined
50
+ ? {}
51
+ : { doctorDiagnostics: options.doctorDiagnostics }),
52
+ };
53
+ const handlers = createMemoryToolHandlers(service, handlerOptions);
54
+ server.registerTool("memory.remember", {
55
+ description: "Store a local Nuzo memory.",
56
+ inputSchema: {
57
+ content: z.string().min(1),
58
+ kind: z.enum(["preference", "project_decision", "fact", "instruction", "note"]),
59
+ scope: scopeSchema.default("user:default"),
60
+ tags: z.array(tagSchema).default([]),
61
+ source: z.string().min(1).default("nuzo:mcp"),
62
+ confidence: z.number().min(0).max(1).optional(),
63
+ },
64
+ }, async (input) => {
65
+ const rememberInput = {
66
+ content: input.content,
67
+ kind: input.kind,
68
+ scope: input.scope,
69
+ tags: input.tags,
70
+ source: input.source,
71
+ };
72
+ if (input.confidence !== undefined) {
73
+ rememberInput.confidence = input.confidence;
74
+ }
75
+ return jsonToolResult(await handlers.remember(rememberInput));
76
+ });
77
+ server.registerTool("memory.recall", {
78
+ description: "Recall relevant local Nuzo memories.",
79
+ inputSchema: {
80
+ query: z.string().min(1),
81
+ scope: scopeSchema.default("user:default"),
82
+ limit: z.number().int().min(1).max(50).default(8),
83
+ include_global: z.boolean().default(false),
84
+ },
85
+ }, async (input) => {
86
+ return jsonToolResult(await handlers.recall(input));
87
+ });
88
+ server.registerTool("memory.recall_hook", {
89
+ description: "Prototype read-only recall entrypoint for host lifecycle hooks. It never captures or creates memories.",
90
+ inputSchema: {
91
+ task_context: z.string().min(1),
92
+ project_scope: scopeSchema.optional(),
93
+ limit: z.number().int().min(1).max(8).default(5),
94
+ },
95
+ }, async (input) => {
96
+ const recallHookInput = {
97
+ task_context: input.task_context,
98
+ limit: input.limit,
99
+ };
100
+ if (input.project_scope !== undefined) {
101
+ recallHookInput.project_scope = input.project_scope;
102
+ }
103
+ return jsonToolResult(await handlers.recallHook(recallHookInput));
104
+ });
105
+ server.registerTool("memory.list", {
106
+ description: "List local Nuzo memories.",
107
+ inputSchema: {
108
+ scope: scopeSchema.optional(),
109
+ tags: z.array(tagSchema).default([]),
110
+ include_archived: z.boolean().default(false),
111
+ },
112
+ }, async (input) => {
113
+ const listInput = {
114
+ tags: input.tags,
115
+ include_archived: input.include_archived,
116
+ };
117
+ if (input.scope !== undefined) {
118
+ listInput.scope = input.scope;
119
+ }
120
+ return jsonToolResult(await handlers.list(listInput));
121
+ });
122
+ server.registerTool("memory.update", {
123
+ description: "Update a local Nuzo memory.",
124
+ inputSchema: {
125
+ id: z.string().min(1),
126
+ content: z.string().optional(),
127
+ kind: z.enum(["preference", "project_decision", "fact", "instruction", "note"]).optional(),
128
+ scope: scopeSchema.optional(),
129
+ tags: z.array(tagSchema).optional(),
130
+ confidence: z.number().min(0).max(1).optional(),
131
+ },
132
+ }, async (input) => {
133
+ const updateInput = {
134
+ id: input.id,
135
+ };
136
+ if (input.content !== undefined) {
137
+ updateInput.content = input.content;
138
+ }
139
+ if (input.kind !== undefined) {
140
+ updateInput.kind = input.kind;
141
+ }
142
+ if (input.scope !== undefined) {
143
+ updateInput.scope = input.scope;
144
+ }
145
+ if (input.tags !== undefined) {
146
+ updateInput.tags = input.tags;
147
+ }
148
+ if (input.confidence !== undefined) {
149
+ updateInput.confidence = input.confidence;
150
+ }
151
+ return jsonToolResult(await handlers.update(updateInput));
152
+ });
153
+ server.registerTool("memory.history", {
154
+ description: "List audit events for one Nuzo memory ID.",
155
+ inputSchema: {
156
+ id: z.string().min(1),
157
+ },
158
+ }, async (input) => {
159
+ const historyInput = {
160
+ id: input.id,
161
+ };
162
+ return jsonToolResult(await handlers.history(historyInput));
163
+ });
164
+ server.registerTool("memory.forget", {
165
+ description: "Archive or delete a local Nuzo memory.",
166
+ inputSchema: {
167
+ id: z.string().min(1),
168
+ mode: z.enum(["archive", "delete"]).default("archive"),
169
+ confirm: z.boolean().default(false),
170
+ reason: z.string().optional(),
171
+ },
172
+ }, async (input) => {
173
+ const forgetInput = {
174
+ id: input.id,
175
+ mode: input.mode,
176
+ confirm: input.confirm,
177
+ };
178
+ if (input.reason !== undefined) {
179
+ forgetInput.reason = input.reason;
180
+ }
181
+ return jsonToolResult(await handlers.forget(forgetInput));
182
+ });
183
+ server.registerTool("memory.forget_many", {
184
+ description: "Preview or apply a filtered bulk archive/delete operation.",
185
+ inputSchema: {
186
+ scope: scopeSchema.optional(),
187
+ tags: z.array(tagSchema).default([]),
188
+ all: z.boolean().default(false),
189
+ mode: z.enum(["archive", "delete"]).default("archive"),
190
+ confirm: z.boolean().default(false),
191
+ dry_run: z.boolean().default(true),
192
+ reason: z.string().optional(),
193
+ },
194
+ }, async (input) => {
195
+ const forgetInput = {
196
+ tags: input.tags,
197
+ all: input.all,
198
+ mode: input.mode,
199
+ confirm: input.confirm,
200
+ dry_run: input.dry_run,
201
+ };
202
+ if (input.scope !== undefined) {
203
+ forgetInput.scope = input.scope;
204
+ }
205
+ if (input.reason !== undefined) {
206
+ forgetInput.reason = input.reason;
207
+ }
208
+ return jsonToolResult(await handlers.forgetMany(forgetInput));
209
+ });
210
+ server.registerTool("memory.export", {
211
+ description: "Export local Nuzo memories as a versioned JSON document.",
212
+ inputSchema: {
213
+ scope: scopeSchema.optional(),
214
+ tags: z.array(tagSchema).default([]),
215
+ include_archived: z.boolean().default(false),
216
+ },
217
+ }, async (input) => {
218
+ const exportInput = {
219
+ tags: input.tags,
220
+ include_archived: input.include_archived,
221
+ };
222
+ if (input.scope !== undefined) {
223
+ exportInput.scope = input.scope;
224
+ }
225
+ return jsonToolResult(await handlers.exportMemories(exportInput));
226
+ });
227
+ server.registerTool("memory.import", {
228
+ description: "Import local Nuzo memories from a versioned JSON document.",
229
+ inputSchema: {
230
+ document: z.object({
231
+ format: z.literal("nuzo-memory-export"),
232
+ version: z.literal(1),
233
+ exported_at: z.string(),
234
+ memories: z.array(z.object({
235
+ scope: scopeSchema,
236
+ kind: z.enum(["preference", "project_decision", "fact", "instruction", "note"]),
237
+ content: z.string(),
238
+ tags: z.array(tagSchema),
239
+ source: z.string().min(1),
240
+ confidence: z.number().min(0).max(1),
241
+ created_at: z.string(),
242
+ updated_at: z.string(),
243
+ last_used_at: z.string().nullable(),
244
+ archived_at: z.string().nullable(),
245
+ })),
246
+ }),
247
+ scope: scopeSchema.optional(),
248
+ dry_run: z.boolean().default(false),
249
+ },
250
+ }, async (input) => {
251
+ const importInput = {
252
+ document: input.document,
253
+ dry_run: input.dry_run,
254
+ };
255
+ if (input.scope !== undefined) {
256
+ importInput.scope = input.scope;
257
+ }
258
+ return jsonToolResult(await handlers.importMemories(importInput));
259
+ });
260
+ server.registerTool("memory.doctor", {
261
+ description: "Report the local Nuzo MCP memory environment.",
262
+ inputSchema: {},
263
+ }, async () => {
264
+ return jsonToolResult(await handlers.doctor());
265
+ });
266
+ }
267
+ if (isMainModule()) {
268
+ const options = {};
269
+ if (process.env.NUZO_MEMORY_STORE !== undefined) {
270
+ options.storePath = process.env.NUZO_MEMORY_STORE;
271
+ }
272
+ const runtime = createNuzoMcpServerRuntime(options);
273
+ const closeRuntime = () => {
274
+ runtime.close();
275
+ };
276
+ process.once("SIGINT", () => {
277
+ closeRuntime();
278
+ process.exit(130);
279
+ });
280
+ process.once("SIGTERM", () => {
281
+ closeRuntime();
282
+ process.exit(143);
283
+ });
284
+ process.once("beforeExit", closeRuntime);
285
+ await runtime.server.connect(new StdioServerTransport());
286
+ }
287
+ function isMainModule() {
288
+ const entrypoint = process.argv[1];
289
+ if (entrypoint === undefined) {
290
+ return false;
291
+ }
292
+ try {
293
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(entrypoint);
294
+ }
295
+ catch {
296
+ return false;
297
+ }
298
+ }
299
+ function openDatabase(storePath) {
300
+ mkdirSync(dirname(storePath), { recursive: true });
301
+ return new SQLiteMemoryDatabase({ path: storePath });
302
+ }
303
+ function isStoreWritable(storePath) {
304
+ try {
305
+ accessSync(dirname(storePath), constants.W_OK);
306
+ accessSync(storePath, constants.W_OK);
307
+ return true;
308
+ }
309
+ catch {
310
+ return false;
311
+ }
312
+ }
313
+ function createService(database) {
314
+ return createMemoryService({
315
+ store: database,
316
+ searchIndex: database,
317
+ auditLog: database,
318
+ clock: new SystemClock(),
319
+ ids: new RandomIdGenerator(),
320
+ policy: new DefaultPolicyEngine(new RegexSecretScanner()),
321
+ transactions: database,
322
+ });
323
+ }
324
+ function jsonToolResult(value) {
325
+ return {
326
+ content: [
327
+ {
328
+ type: "text",
329
+ text: JSON.stringify(value, null, 2),
330
+ },
331
+ ],
332
+ };
333
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@nuzo/mcp-server",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Nuzo.",
5
+ "keywords": [
6
+ "ai-agents",
7
+ "mcp",
8
+ "memory",
9
+ "codex",
10
+ "claude-code",
11
+ "local-first"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "type": "module",
15
+ "engines": {
16
+ "node": ">=22",
17
+ "npm": ">=10"
18
+ },
19
+ "bin": {
20
+ "nuzo-mcp-server": "dist/index.js"
21
+ },
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "dependencies": {
36
+ "@nuzo/memory-core": "0.1.0",
37
+ "@modelcontextprotocol/sdk": "^1.29.0",
38
+ "zod": "^4.1.13"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/fabionfsc/nuzo-memory.git",
46
+ "directory": "packages/mcp-server"
47
+ },
48
+ "homepage": "https://nuzo.com.br/",
49
+ "bugs": {
50
+ "url": "https://github.com/fabionfsc/nuzo-memory/issues"
51
+ }
52
+ }