samemory 0.0.0-stage → 0.0.4

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nazozokc
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.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # samemory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ agentの共有メモリをMCPサーバーにするためのツール
4
+
5
+ # Install
6
+
7
+ - Claude Code
8
+
9
+ ```json
10
+ {
11
+ "mcpServers": {
12
+ "samemory": {
13
+ "type": "stdio",
14
+ "command": "bunx",
15
+ "args": ["samemory"]
16
+ }
17
+ }
18
+ }
19
+ ```
20
+
21
+ - Codex
22
+
23
+ ```toml
24
+ [mcp_servers.samemory]
25
+ command = "bunx"
26
+ args = ["samemory"]
27
+ enabled = true
28
+ ```
29
+
30
+ - OpenCode
31
+
32
+ ```json
33
+ {
34
+ "$schema": "https://opencode.ai/config.json",
35
+ "mcp": {
36
+ "samemory": {
37
+ "type": "local",
38
+ "command": ["bunx", "samemory"],
39
+ "enabled": true
40
+ }
41
+ }
42
+ }
43
+ ```
package/dist/index.mjs ADDED
@@ -0,0 +1,226 @@
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
3
+ import { z } from "zod";
4
+ import { join } from "node:path";
5
+ import { homedir } from "node:os";
6
+ import { mkdir, readFile, readdir, rename, stat, writeFile } from "node:fs/promises";
7
+ import { randomUUIDv7 } from "node:crypto";
8
+ import Fuse from "fuse.js";
9
+ // src/memory_get/type.ts
10
+ const MemoryGetInputSchema = z.object({ id: z.string() });
11
+ // src/constant/app.ts
12
+ const MCP_NAME = "samemory";
13
+ const CONFIG_DIR = join(homedir(), ".config", "samemory", "config.json");
14
+ // src/constant/ConfigType.ts
15
+ const ConfigTypeSchema = z.object({ dir: z.string() });
16
+ // src/constant/ConfigDefault.ts
17
+ const ConfigDefault = { dir: join(homedir(), "samemory") };
18
+ // src/constant/ConfigRead.ts
19
+ const ConfigDir = async () => {
20
+ try {
21
+ const readConfig = await readFile(CONFIG_DIR, "utf-8");
22
+ const readConfigSchema = ConfigTypeSchema.safeParse(JSON.parse(readConfig));
23
+ if (readConfigSchema.error) return ConfigDefault.dir;
24
+ return readConfigSchema.data.dir;
25
+ } catch (error) {
26
+ return ConfigDefault.dir;
27
+ }
28
+ };
29
+ // src/Globaltype.ts
30
+ const CategorySchema = z.enum([
31
+ "lessons",
32
+ "patterns",
33
+ "context",
34
+ "commands",
35
+ "preferences"
36
+ ]);
37
+ const AgentMemorySchema = z.object({
38
+ id: z.string(),
39
+ category: CategorySchema,
40
+ tags: z.array(z.string()),
41
+ created: z.iso.datetime(),
42
+ agent: z.string(),
43
+ title: z.string(),
44
+ summary: z.string(),
45
+ content: z.string()
46
+ });
47
+ // src/memory_get/index.ts
48
+ const getFile = async (id) => {
49
+ const categories = [
50
+ "lessons",
51
+ "patterns",
52
+ "context",
53
+ "commands",
54
+ "preferences"
55
+ ];
56
+ const readMemoryDir = join(await ConfigDir());
57
+ const readMemory = await readdir(readMemoryDir, "utf-8");
58
+ const isCategory = (value) => {
59
+ return categories.some((category) => category === value);
60
+ };
61
+ for (const memory of readMemory) {
62
+ if (!(await stat(join(await ConfigDir(), memory))).isDirectory()) continue;
63
+ if (!isCategory(memory)) continue;
64
+ const dir = join(await ConfigDir(), memory);
65
+ if (!(await readdir(dir, "utf-8")).includes(`${id}.json`)) continue;
66
+ const joinFile = join(await ConfigDir(), memory, `${id}.json`);
67
+ const readJSON = await readFile(joinFile, "utf-8");
68
+ const SafeSchema = AgentMemorySchema.safeParse(JSON.parse(readJSON));
69
+ if (!SafeSchema.success) continue;
70
+ return SafeSchema.data;
71
+ }
72
+ };
73
+ // src/memory_save/type.ts
74
+ const AgentMemorySaveSchema = AgentMemorySchema.omit({
75
+ id: true,
76
+ created: true
77
+ });
78
+ // src/memory_save/index.ts
79
+ const writeMemoryFile = async ({ category, tags, agent, title, summary, content }) => {
80
+ const data = {
81
+ category,
82
+ tags,
83
+ agent,
84
+ title,
85
+ summary,
86
+ content
87
+ };
88
+ const SaveSchema = AgentMemorySaveSchema.safeParse(data);
89
+ if (!SaveSchema.success) throw new Error();
90
+ const savedata = {
91
+ id: randomUUIDv7(),
92
+ created: (/* @__PURE__ */ new Date()).toISOString(),
93
+ ...SaveSchema.data
94
+ };
95
+ const SchemaCheck = AgentMemorySchema.safeParse(savedata);
96
+ if (!SchemaCheck.success) throw new Error();
97
+ const categories = SchemaCheck.data.category;
98
+ const directoryTemp = join(await ConfigDir(), categories, `${SchemaCheck.data.id}.json.tmp`);
99
+ const directory = join(await ConfigDir(), categories, `${SchemaCheck.data.id}.json`);
100
+ try {
101
+ const mkcategory = join(await ConfigDir(), categories);
102
+ await mkdir(mkcategory, { recursive: true });
103
+ const stringify = JSON.stringify(SchemaCheck.data, null, 2);
104
+ await writeFile(directoryTemp, stringify, "utf-8");
105
+ await rename(directoryTemp, directory);
106
+ return true;
107
+ } catch (error) {
108
+ return false;
109
+ }
110
+ };
111
+ // src/memory_search/type.ts
112
+ const SearchSchema = z.object({
113
+ query: z.string(),
114
+ category: CategorySchema.optional(),
115
+ tags: z.array(z.string()).optional(),
116
+ limit: z.number().optional()
117
+ });
118
+ // src/memory_search/SearchData.ts
119
+ const SearchData = async () => {
120
+ const dir = await ConfigDir();
121
+ const readmemoryDir = await readdir(dir, "utf-8");
122
+ const res = [];
123
+ for (const memoryDir of readmemoryDir) {
124
+ if (!(await stat(join(dir, memoryDir))).isDirectory()) continue;
125
+ if (!CategorySchema.safeParse(memoryDir).success) continue;
126
+ const categoryreadDir = await readdir(join(dir, memoryDir), "utf-8");
127
+ for (const categoryDir of categoryreadDir) {
128
+ const filePath = join(dir, memoryDir, categoryDir);
129
+ if (!(await stat(filePath)).isFile()) continue;
130
+ const FileRead = await readFile(filePath, "utf-8");
131
+ const filesafeparse = AgentMemorySchema.safeParse(JSON.parse(FileRead));
132
+ if (!filesafeparse.success) continue;
133
+ res.push(filesafeparse.data);
134
+ }
135
+ }
136
+ return res;
137
+ };
138
+ // src/memory_search/index.ts
139
+ const Search = async ({ query, category, tags, limit }) => {
140
+ const limited = limit ?? 30;
141
+ let results = new Fuse(await SearchData(), {
142
+ includeScore: true,
143
+ includeMatches: true,
144
+ keys: [
145
+ "category",
146
+ "tags",
147
+ "agent",
148
+ "title",
149
+ "summary",
150
+ "content"
151
+ ]
152
+ }).search(query);
153
+ if (category !== void 0) results = results.filter((result) => result.item.category === category);
154
+ if (tags !== void 0) results = results.filter((result) => tags.every((tag) => result.item.tags.includes(tag)));
155
+ return results.slice(0, limited).map((result) => result.item);
156
+ };
157
+ // src/main.ts
158
+ const server = new McpServer({
159
+ name: MCP_NAME,
160
+ version: "0.0.1"
161
+ });
162
+ server.registerTool("memory_get", {
163
+ description: "Get agent memory",
164
+ inputSchema: MemoryGetInputSchema
165
+ }, async ({ id }) => {
166
+ const memory = await getFile(id);
167
+ if (!memory) return { content: [{
168
+ type: "text",
169
+ text: `Not Found ${id}`
170
+ }] };
171
+ return {
172
+ content: [{
173
+ type: "text",
174
+ text: "Memory retrieved successfully."
175
+ }],
176
+ structuredContent: memory
177
+ };
178
+ });
179
+ server.registerTool("memory_save", {
180
+ description: "Get agent memory",
181
+ inputSchema: AgentMemorySaveSchema
182
+ }, async ({ category, tags, agent, title, summary, content }) => {
183
+ if (await writeMemoryFile({
184
+ category,
185
+ tags,
186
+ agent,
187
+ title,
188
+ summary,
189
+ content
190
+ }) === true) return {
191
+ content: [{
192
+ type: "text",
193
+ text: "successfully save agent memory"
194
+ }],
195
+ structuredContent: { success: true }
196
+ };
197
+ return {
198
+ content: [{
199
+ type: "text",
200
+ text: "Failed save agent memory"
201
+ }],
202
+ structuredContent: { isError: true }
203
+ };
204
+ });
205
+ server.registerTool("memory_search", {
206
+ description: "Get agent memory",
207
+ inputSchema: SearchSchema
208
+ }, async ({ query, category, tags, limit }) => {
209
+ const result = await Search({
210
+ query,
211
+ category,
212
+ tags,
213
+ limit
214
+ });
215
+ return { content: [{
216
+ type: "text",
217
+ text: JSON.stringify(result, null, 2)
218
+ }] };
219
+ });
220
+ async function main() {
221
+ const transport = new StdioServerTransport();
222
+ await server.connect(transport);
223
+ }
224
+ // src/index.ts
225
+ main();
226
+ export {};
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "samemory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "module": "src/index.ts",
4
+ "type": "module",
5
+ "version": "0.0.4",
6
+ "bin": {
7
+ "samemory": "dist/index.mjs"
8
+ },
9
+ "repository": {
10
+ "url": "https://github.com/nazozokc/samemory.git"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "package.json",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "build": "bunx tsdown"
20
+ },
21
+ "devDependencies": {
22
+ "@types/bun": "latest",
23
+ "tsdown": "latest"
24
+ },
25
+ "peerDependencies": {
26
+ "typescript": "^7"
27
+ },
28
+ "dependencies": {
29
+ "@modelcontextprotocol/server": "^2.4.0",
30
+ "chokidar": "^6.0.0",
31
+ "fuse.js": "^7.5.0",
32
+ "zod": "^4.6.7"
33
+ }
34
+ }