claude-memory-layer 1.0.11 → 1.0.13

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 (101) hide show
  1. package/AGENTS.md +60 -0
  2. package/README.md +166 -2
  3. package/bootstrap-kb/decisions/decisions.md +244 -0
  4. package/bootstrap-kb/glossary/glossary.md +46 -0
  5. package/bootstrap-kb/modules/.claude-plugin.md +22 -0
  6. package/bootstrap-kb/modules/agents.md.md +15 -0
  7. package/bootstrap-kb/modules/claude.md.md +15 -0
  8. package/bootstrap-kb/modules/context.md.md +15 -0
  9. package/bootstrap-kb/modules/docs.md +18 -0
  10. package/bootstrap-kb/modules/handoff.md.md +15 -0
  11. package/bootstrap-kb/modules/package-lock.json.md +15 -0
  12. package/bootstrap-kb/modules/package.json.md +15 -0
  13. package/bootstrap-kb/modules/plan.md.md +15 -0
  14. package/bootstrap-kb/modules/readme.md.md +15 -0
  15. package/bootstrap-kb/modules/scripts.md +26 -0
  16. package/bootstrap-kb/modules/spec.md.md +15 -0
  17. package/bootstrap-kb/modules/specs.md +20 -0
  18. package/bootstrap-kb/modules/src.md +51 -0
  19. package/bootstrap-kb/modules/tests.md +42 -0
  20. package/bootstrap-kb/modules/tsconfig.json.md +15 -0
  21. package/bootstrap-kb/modules/vitest.config.ts.md +15 -0
  22. package/bootstrap-kb/overview/overview.md +40 -0
  23. package/bootstrap-kb/sources/manifest.json +950 -0
  24. package/bootstrap-kb/sources/manifest.md +227 -0
  25. package/bootstrap-kb/timeline/timeline.md +57 -0
  26. package/d.sh +3 -0
  27. package/deploy.sh +3 -0
  28. package/dist/cli/index.js +2389 -286
  29. package/dist/cli/index.js.map +4 -4
  30. package/dist/core/index.js +1017 -132
  31. package/dist/core/index.js.map +4 -4
  32. package/dist/hooks/post-tool-use.js +1347 -202
  33. package/dist/hooks/post-tool-use.js.map +4 -4
  34. package/dist/hooks/session-end.js +1339 -194
  35. package/dist/hooks/session-end.js.map +4 -4
  36. package/dist/hooks/session-start.js +1343 -198
  37. package/dist/hooks/session-start.js.map +4 -4
  38. package/dist/hooks/stop.js +1351 -206
  39. package/dist/hooks/stop.js.map +4 -4
  40. package/dist/hooks/user-prompt-submit.js +1347 -202
  41. package/dist/hooks/user-prompt-submit.js.map +4 -4
  42. package/dist/server/api/index.js +1436 -211
  43. package/dist/server/api/index.js.map +4 -4
  44. package/dist/server/index.js +1445 -220
  45. package/dist/server/index.js.map +4 -4
  46. package/dist/services/memory-service.js +1345 -199
  47. package/dist/services/memory-service.js.map +4 -4
  48. package/dist/ui/app.js +69 -2
  49. package/dist/ui/index.html +8 -0
  50. package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +271 -0
  51. package/docs/MEMU_ADOPTION.md +40 -0
  52. package/memory/.claude-plugin/commands/2026-02-25.md +263 -0
  53. package/memory/_index.md +405 -0
  54. package/memory/default/uncategorized/2026-02-25.md +4839 -0
  55. package/memory/specs/20260207-dashboard-upgrade/2026-02-25.md +142 -0
  56. package/memory/specs/citations-system/2026-02-25.md +1121 -0
  57. package/memory/specs/endless-mode/2026-02-25.md +1392 -0
  58. package/memory/specs/entity-edge-model/2026-02-25.md +1263 -0
  59. package/memory/specs/evidence-aligner-v2/2026-02-25.md +1028 -0
  60. package/memory/specs/mcp-desktop-integration/2026-02-25.md +1334 -0
  61. package/memory/specs/post-tool-use-hook/2026-02-25.md +1164 -0
  62. package/memory/specs/private-tags/2026-02-25.md +1057 -0
  63. package/memory/specs/progressive-disclosure/2026-02-25.md +1436 -0
  64. package/memory/specs/task-entity-system/2026-02-25.md +924 -0
  65. package/memory/specs/vector-outbox-v2/2026-02-25.md +1510 -0
  66. package/memory/specs/web-viewer-ui/2026-02-25.md +1709 -0
  67. package/package.json +2 -1
  68. package/scripts/build.ts +6 -0
  69. package/scripts/bump-patch-version.sh +18 -0
  70. package/src/cli/index.ts +281 -2
  71. package/src/core/consolidated-store.ts +63 -1
  72. package/src/core/consolidation-worker.ts +115 -6
  73. package/src/core/event-store.ts +14 -0
  74. package/src/core/index.ts +1 -0
  75. package/src/core/ingest-interceptor.ts +80 -0
  76. package/src/core/markdown-mirror.ts +70 -0
  77. package/src/core/md-mirror.ts +92 -0
  78. package/src/core/mongo-sync-config.ts +165 -0
  79. package/src/core/mongo-sync-worker.ts +381 -0
  80. package/src/core/retriever.ts +540 -150
  81. package/src/core/sqlite-event-store.ts +350 -1
  82. package/src/core/tag-taxonomy.ts +51 -0
  83. package/src/core/types.ts +28 -0
  84. package/src/server/api/health.ts +53 -0
  85. package/src/server/api/index.ts +3 -1
  86. package/src/server/api/stats.ts +46 -1
  87. package/src/services/bootstrap-organizer.ts +443 -0
  88. package/src/services/codex-session-history-importer.ts +474 -0
  89. package/src/services/memory-service.ts +373 -68
  90. package/src/services/session-history-importer.ts +53 -25
  91. package/src/ui/app.js +69 -2
  92. package/src/ui/index.html +8 -0
  93. package/tests/bootstrap-organizer.test.ts +111 -0
  94. package/tests/consolidation-worker.test.ts +75 -0
  95. package/tests/ingest-interceptor.test.ts +38 -0
  96. package/tests/markdown-mirror.test.ts +85 -0
  97. package/tests/md-mirror.test.ts +50 -0
  98. package/tests/retriever-fallback-chain.test.ts +223 -0
  99. package/tests/retriever-strategy-scope.test.ts +97 -0
  100. package/tests/retriever.memu-adoption.test.ts +122 -0
  101. package/tests/sqlite-event-store-replication.test.ts +92 -0
@@ -0,0 +1,1334 @@
1
+
2
+ ## 2026-02-25T12:31:26.330Z | 5a29de82-7227-4961-ae38-ece8700e43f5
3
+ - type: session_summary
4
+ - session: import:organized
5
+ # MCP Desktop Integration Context
6
+
7
+ > **Version**: 1.0.0
8
+ > **Created**: 2026-02-01
9
+
10
+ ## 1. 배경
11
+
12
+ ### 1.1 claude-mem의 접근 방식
13
+
14
+ claude-mem은 MCP (Model Context Protocol)를 통해 Claude Desktop 통합 제공:
15
+
16
+ ```
17
+ Claude Desktop → MCP Client → claude-mem MCP Server → Memory Storage
18
+ ```
19
+
20
+ **특징**:
21
+ - `mem-search` 도구로 자연어 검색
22
+ - Progressive disclosure 패턴 지원
23
+ - 동일한 메모리 저장소 공유
24
+
25
+ ### 1.2 MCP란?
26
+
27
+ **Model Context Protocol (MCP)**:
28
+ - Anthropic이 개발한 표준 프로토콜
29
+ - AI 모델과 외부 도구/데이터 연결
30
+ - JSON-RPC 기반 통신
31
+ - stdio 또는 HTTP 전송
32
+
33
+ ### 1.3 현재 code-memory의 상황
34
+
35
+ 현재 Claude Code CLI 전용:
36
+
37
+ ```
38
+ Claude Code CLI → Hooks → Memory Storage
39
+
40
+ (Desktop 접근 불가)
41
+ ```
42
+
43
+ **문제**:
44
+ 1. Claude Desktop에서 메모리 활용 불가
45
+ 2. CLI 없이는 검색 불가
46
+ 3. 환경 간 메모리 분리
47
+
48
+ ## 2. MCP 프로토콜 이해
49
+
50
+ ### 2.1 핵심 개념
51
+
52
+ ```
53
+ ┌─────────────────┐ ┌─────────────────┐
54
+ │ MCP Client │◀─────▶│ MCP Server │
55
+ │ (Claude Desktop)│ JSON │ (code-memory) │
56
+ └─────────────────┘ RPC └─────────────────┘
57
+ ```
58
+
59
+ **Client**: Claude Desktop, Claude.ai
60
+ **Server**: 도구/데이터 제공자
61
+ **Transport**: stdio (로컬), HTTP (원격)
62
+
63
+ ### 2.2 메시지 형식
64
+
65
+ ```typescript
66
+ // 요청
67
+ {
68
+ "jsonrpc": "2.0",
69
+ "id": 1,
70
+ "method": "tools/call",
71
+ "params": {
72
+ "name": "mem-search",
73
+ "arguments": { "query": "..." }
74
+ }
75
+ }
76
+
77
+ // 응답
78
+ {
79
+ "jsonrpc": "2.0",
80
+ "id": 1,
81
+ "result": {
82
+ "content": [{ "type": "text", "text": "..." }]
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### 2.3 도구 정의
88
+
89
+ ```typescript
90
+ interface Tool {
91
+ name: string; // 도구 이름
92
+ description: string; // Claude에게 보여질 설명
93
+ inputSchema: JSONSchema; // 입력 스키마
94
+ }
95
+ ```
96
+
97
+ ## 3. 기존 코드와의 관계
98
+
99
+ ### 3.1 MemoryService 재사용
100
+
101
+ MCP 서버는 동일한 MemoryService 사용:
102
+
103
+ ```typescript
104
+ // CLI
105
+ const service = await MemoryService.getInstance();
106
+ await service.search(query);
107
+
108
+ // MCP Server
109
+ const service = await MemoryService.getInstance();
110
+ await service.search(query); // 동일한 코드
111
+ ```
112
+
113
+ ### 3.2 Progressive Retriever 재사용
114
+
115
+ ```typescript
116
+ // MCP mem-search → ProgressiveRetriever.smartSearch()
117
+ // MCP mem-timeline → ProgressiveRetriever.getTimeline()
118
+ // MCP mem-details → ProgressiveRetriever.getDetails()
119
+ ```
120
+
121
+ ### 3.3 저장소 공유
122
+
123
+ ```
124
+ ~/.claude-code/memory/
125
+ ├── events.duckdb ← CLI, MCP 모두 접근
126
+ └── vectors/ ← CLI, MCP 모두 접근
127
+ ```
128
+
129
+ ## 4. 설계 결정 사항
130
+
131
+ ### 4.1 패키지 구조
132
+
133
+ **옵션 1: 단일 패키지**
134
+ ```
135
+ code-memory/
136
+ ├── src/
137
+ │ ├── cli/
138
+ │ ├── core/
139
+ │ └── mcp/
140
+ ```
141
+
142
+ **옵션 2: 별도 패키지 (선택)**
143
+ ```
144
+ code-memory/
145
+ ├── packages/
146
+ │ ├── core/ # 공유 로직
147
+ │ ├── cli/ # CLI
148
+ │ └── mcp-server/ # MCP 서버
149
+ ```
150
+
151
+ **선택 이유**:
152
+ - 독립적 버전 관리
153
+ - npm 별도 배포 가능
154
+ - 의존성 분리
155
+
156
+ ### 4.2 전송 방식
157
+
158
+ **stdio (선택)**:
159
+ - Claude Desktop 기본 지원
160
+ - 로컬 실행, 보안 이점
161
+ - 설정 간단
162
+
163
+ **HTTP**:
164
+ - 원격 접근 가능
165
+ - 추가 보안 필요
166
+ - 포트 충돌 가능
167
+
168
+ ### 4.3 도구 설계
169
+
170
+ **Progressive Disclosure 패턴**:
171
+ 1. `mem-search`: Layer 1 (인덱스)
172
+ 2. `mem-timeline`: Layer 2 (타임라인)
173
+ 3. `mem-details`: Layer 3 (상세)
174
+
175
+ **이유**:
176
+ - 토큰 효율성
177
+ - 단계적 정보 제공
178
+ - 필요한 것만 조회
179
+
180
+ ## 5. Claude Desktop 설정
181
+
182
+ ### 5.1 설정 파일 위치
183
+
184
+ | OS | 경로 |
185
+ |------|------|
186
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
187
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
188
+ | Linux | `~/.config/claude/claude_desktop_config.json` |
189
+
190
+ ### 5.2 설정 형식
191
+
192
+ ```json
193
+ {
194
+ "mcpServers": {
195
+ "server-name": {
196
+ "command": "실행 명령",
197
+ "args": ["인자들"],
198
+ "env": {
199
+ "환경변수": "값"
200
+ }
201
+ }
202
+ }
203
+ }
204
+ ```
205
+
206
+ ### 5.3 자동 설치의 이점
207
+
208
+ ```bash
209
+ $ code-memory mcp install
210
+ ```
211
+
212
+ **수동 설정 시 문제**:
213
+ - JSON 문법 오류 가능
214
+ - 경로 오타
215
+ - 플랫폼별 차이
216
+
217
+ **자동 설치 이점**:
218
+ - 오류 방지
219
+ - 플랫폼 자동 감지
220
+ - 설정 검증
221
+
222
+ ## 6. 보안 고려사항
223
+
224
+ ### 6.1 로컬 전용
225
+
226
+ ```typescript
227
+ // stdio 전송만 사용 (네트워크 노출 없음)
228
+ const transport = new StdioServerTransport();
229
+ ```
230
+
231
+ ### 6.2 경로 제한
232
+
233
+ ```typescript
234
+ // 홈 디렉토리 외부 접근 차단
235
+ const memoryPath = process.env.MEMORY_PATH;
236
+ if (!memoryPath.startsWith(os.homedir())) {
237
+ throw new Error('Invalid memory path');
238
+ }
239
+ ```
240
+
241
+ ### 6.3 Privacy 필터 적용
242
+
243
+ ```typescript
244
+ // MCP 응답에도 privacy 필터 적용
245
+ const filtered = applyPrivacyFilter(content, config.privacy);
246
+ ```
247
+
248
+ ## 7. 사용 시나리오
249
+
250
+ ### 7.1 Claude Desktop에서 검색
251
+
252
+ ```
253
+ User: "지난번에 DuckDB 스키마 어떻게 설계했었지?"
254
+
255
+ Claude: [mem-search 도구 호출]
256
+ query: "DuckDB 스키마 설계"
257
+
258
+ Found 2 relevant memories:
259
+
260
+ 1. [mem:a7Bc3x] (0.94)
261
+ DuckDB를 사용하여 이벤트 소싱 패턴을...
262
+
263
+ 지난번에 이벤트 소싱 패턴으로 설계하셨네요.
264
+ 자세한 내용을 보시려면 말씀해주세요.
265
+ ```
266
+
267
+ ### 7.2 상세 조회
268
+
269
+ ```
270
+ User: "첫 번째 결과 자세히 보여줘"
271
+
272
+ Claude: [mem-details 도구 호출]
273
+ ids: ["a7Bc3x"]
274
+
275
+ [전체 내용 표시]
276
+ ```
277
+
278
+ ## 8. 참고 자료
279
+
280
+ - **MCP 공식 문서**: https://modelcontextprotocol.io/
281
+ - **claude-mem MCP**: Desktop integration via MCP
282
+ - **Anthropic SDK**: @modelcontextprotocol/sdk
283
+
284
+ ## 2026-02-25T12:31:26.337Z | e718c82b-3d4e-4d40-9f17-3f9e41a1c161
285
+ - type: session_summary
286
+ - session: import:organized
287
+ # MCP Desktop Integration Implementation Plan
288
+
289
+ > **Version**: 1.0.0
290
+ > **Status**: Draft
291
+ > **Created**: 2026-02-01
292
+
293
+ ## Phase 1: MCP 서버 기본 구조 (P0)
294
+
295
+ ### 1.1 프로젝트 설정
296
+
297
+ **파일**: `packages/mcp-server/package.json` (신규)
298
+
299
+ ```json
300
+ {
301
+ "name": "code-memory-mcp",
302
+ "version": "1.0.0",
303
+ "description": "MCP server for code-memory",
304
+ "main": "dist/index.js",
305
+ "bin": {
306
+ "code-memory-mcp": "./dist/index.js"
307
+ },
308
+ "scripts": {
309
+ "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
310
+ "dev": "tsx src/index.ts"
311
+ },
312
+ "dependencies": {
313
+ "@modelcontextprotocol/sdk": "^1.0.0",
314
+ "code-memory-core": "workspace:*"
315
+ }
316
+ }
317
+ ```
318
+
319
+ **작업 항목**:
320
+ - [ ] MCP 서버 패키지 생성
321
+ - [ ] dependencies 설정
322
+ - [ ] 빌드 스크립트 설정
323
+
324
+ ### 1.2 서버 진입점
325
+
326
+ **파일**: `packages/mcp-server/src/index.ts` (신규)
327
+
328
+ ```typescript
329
+ #!/usr/bin/env node
330
+ import { Server } from '@modelcontextprotocol/sdk/server';
331
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio';
332
+ import {
333
+ ListToolsRequestSchema,
334
+ CallToolRequestSchema
335
+ } from '@modelcontextprotocol/sdk/types';
336
+
337
+ import { tools } from './tools';
338
+ import { handleToolCall } from './handlers';
339
+
340
+ const server = new Server(
341
+ {
342
+ name: 'code-memory-mcp',
343
+ version: '1.0.0'
344
+ },
345
+ {
346
+ capabilities: {
347
+ tools: {}
348
+ }
349
+ }
350
+ );
351
+
352
+ // 도구 목록 핸들러
353
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
354
+ return { tools };
355
+ });
356
+
357
+ // 도구 호출 핸들러
358
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
359
+ const { name, arguments: args } = request.params;
360
+ return handleToolCall(name, args || {});
361
+ });
362
+
363
+ // stdio 연결 및 시작
364
+ async function main() {
365
+ const transport = new StdioServerTransport();
366
+ await server.connect(transport);
367
+ console.error('code-memory MCP server started');
368
+ }
369
+
370
+ main().catch(console.error);
371
+ ```
372
+
373
+ **작업 항목**:
374
+ - [ ] 서버 초기화
375
+ - [ ] 핸들러 등록
376
+ - [ ] stdio 연결
377
+
378
+ ### 1.3 도구 정의
379
+
380
+ **파일**: `packages/mcp-server/src/tools.ts` (신규)
381
+
382
+ ```typescript
383
+ import { Tool } from '@modelcontextprotocol/sdk/types';
384
+
385
+ export const tools: Tool[] = [
386
+ {
387
+ name: 'mem-search',
388
+ description: 'Search code-memory for relevant past conversations and insights. Returns a compact index of results - use mem-details to get full content.',
389
+ inputSchema: {
390
+ type: 'object',
391
+ properties: {
392
+ query: {
393
+ type: 'string',
394
+ description: 'Natural language search query'
395
+ },
396
+ topK: {
397
+ type: 'number',
398
+ description: 'Maximum number of results (default: 5, max: 20)'
399
+ },
400
+ sessionId: {
401
+ type: 'string',
402
+ description: 'Optional: filter by specific session ID'
403
+ },
404
+ eventType: {
405
+ type: 'string',
406
+ enum: ['prompt', 'response', 'tool', 'insight'],
407
+ description: 'Optional: filter by event type'
408
+ }
409
+ },
410
+ required: ['query']
411
+ }
412
+ },
413
+ {
414
+ name: 'mem-timeline',
415
+ description: 'Get chronological context around specific memories. Useful for understanding the conversation flow.',
416
+ inputSchema: {
417
+ type: 'object',
418
+ properties: {
419
+ ids: {
420
+ type: 'array',
421
+ items: { type: 'string' },
422
+ description: 'Memory IDs (from mem-search) to get timeline for'
423
+ },
424
+ windowSize: {
425
+ type: 'number',
426
+ description: 'Number of items before/after each ID (default: 3)'
427
+ }
428
+ },
429
+ required: ['ids']
430
+ }
431
+ },
432
+ {
433
+ name: 'mem-details',
434
+ description: 'Get full content of specific memories. Use after mem-search to get complete information.',
435
+ inputSchema: {
436
+ type: 'object',
437
+ properties: {
438
+ ids: {
439
+ type: 'array',
440
+ items: { type: 'string' },
441
+ description: 'Memory IDs to fetch full details for'
442
+ }
443
+ },
444
+ required: ['ids']
445
+ }
446
+ },
447
+ {
448
+ name: 'mem-stats',
449
+ description: 'Get statistics about the memory storage (total events, sessions, etc.)',
450
+ inputSchema: {
451
+ type: 'object',
452
+ properties: {}
453
+ }
454
+ }
455
+ ];
456
+ ```
457
+
458
+ **작업 항목**:
459
+ - [ ] mem-search 도구 정의
460
+ - [ ] mem-timeline 도구 정의
461
+ - [ ] mem-details 도구 정의
462
+ - [ ] mem-stats 도구 정의
463
+
464
+ ## Phase 2: 핸들러 구현 (P0)
465
+
466
+ ### 2.1 도구 핸들러
467
+
468
+ **파일**: `packages/mcp-server/src/handlers.ts` (신규)
469
+
470
+ ```typescript
471
+ import { ToolResult } from '@modelcontextprotocol/sdk/types';
472
+ import { MemoryService } from 'code-memory-core';
473
+ import { formatSearchResults, formatTimeline, formatDetails, formatStats } from './formatters';
474
+
475
+ let memoryService: MemoryService | null = null;
476
+
477
+ async function getMemoryService(): Promise<MemoryService> {
478
+ if (!memoryService) {
479
+ memoryService = await MemoryService.getInstance({
480
+ storagePath: process.env.MEMORY_PATH || '~/.claude-code/memory'
481
+ });
482
+ }
483
+ return memoryService;
484
+ }
485
+
486
+ export async function handleToolCall(
487
+ name: string,
488
+ args: Record<string, unknown>
489
+ ): Promise<ToolResult> {
490
+ try {
491
+ const service = await getMemoryService();
492
+
493
+ switch (name) {
494
+ case 'mem-search':
495
+ return await handleMemSearch(service, args);
496
+
497
+ case 'mem-timeline':
498
+ return await handleMemTimeline(service, args);
499
+
500
+ case 'mem-details':
501
+ return await handleMemDetails(service, args);
502
+
503
+ case 'mem-stats':
504
+ return await handleMemStats(service);
505
+
506
+ default:
507
+ return {
508
+ content: [{ type: 'text', text: `Unknown tool: ${name}` }],
509
+ isError: true
510
+ };
511
+ }
512
+ } catch (error) {
513
+ return {
514
+ content: [{ type: 'text', text: `Error: ${(error as Error).message}` }],
515
+ isError: true
516
+ };
517
+ }
518
+ }
519
+
520
+ async function handleMemSearch(
521
+ service: MemoryService,
522
+ args: Record<string, unknown>
523
+ ): Promise<ToolResult> {
524
+ const query = args.query as string;
525
+ const topK = Math.min((args.topK as number) || 5, 20);
526
+
527
+ const results = await service.progressiveSearch(query, {
528
+ topK,
529
+ filter: {
530
+ sessionId: args.sessionId as string,
531
+ eventType: args.eventType as string
532
+ }
533
+ });
534
+
535
+ return {
536
+ content: [{
537
+ type: 'text',
538
+ text: formatSearchResults(results)
539
+ }]
540
+ };
541
+ }
542
+
543
+ // 다른 핸들러들도 유사하게 구현
544
+ ```
545
+
546
+ **작업 항목**:
547
+ - [ ] handleMemSearch 구현
548
+ - [ ] handleMemTimeline 구현
549
+ - [ ] handleMemDetails 구현
550
+ - [ ] handleMemStats 구현
551
+ - [ ] 에러 처리
552
+
553
+ ### 2.2 포맷터
554
+
555
+ **파일**: `packages/mcp-server/src/formatters.ts` (신규)
556
+
557
+ ```typescript
558
+ import { ProgressiveSearchResult, TimelineItem, FullDetail, Stats } from 'code-memory-core';
559
+
560
+ export function formatSearchResults(results: ProgressiveSearchResult): string {
561
+ const lines: string[] = [
562
+ '## Memory Search Results',
563
+ '',
564
+ `Found ${results.index.length} relevant memories:`,
565
+ ''
566
+ ];
567
+
568
+ for (let i = 0; i < results.index.length; i++) {
569
+ const item = results.index[i];
570
+ const score = item.score.toFixed(2);
571
+ const date = new Date(item.timestamp).toLocaleDateString();
572
+
573
+ lines.push(`### ${i + 1}. [mem:${item.id}] (${score})`);
574
+ lines.push(`**Session**: ${item.sessionId.slice(0, 8)} | **Date**: ${date}`);
575
+ lines.push(`> ${item.summary}`);
576
+ lines.push('');
577
+ }
578
+
579
+ lines.push('---');
580
+ lines.push('*Use `mem-details` with IDs for full content.*');
581
+ lines.push('*Use `mem-timeline` for context around these memories.*');
582
+
583
+ return lines.join('\n');
584
+ }
585
+
586
+ export function formatTimeline(items: TimelineItem[]): string {
587
+ const lines: string[] = [
588
+ '## Timeline Context',
589
+ '',
590
+ '| Time | Type | Preview |',
591
+ '|------|------|---------|'
592
+ ];
593
+
594
+ for (const item of items) {
595
+ const time = new Date(item.timestamp).toLocaleTimeString();
596
+ const marker = item.isTarget ? '**' : '';
597
+ const preview = item.preview.slice(0, 50) + (item.preview.length > 50 ? '...' : '');
598
+
599
+ lines.push(`| ${marker}${time}${marker} | ${item.type} | ${marker}${preview}${marker} |`);
600
+ }
601
+
602
+ return lines.join('\n');
603
+ }
604
+
605
+ export function formatDetails(details: FullDetail[]): string {
606
+ return details.map(detail => {
607
+ const date = new Date(detail.timestamp).toLocaleString();
608
+
609
+ return [
610
+ `## Memory Details: [mem:${detail.id}]`,
611
+ '',
612
+ `**Session**: ${detail.sessionId}`,
613
+ `**Date**: ${date}`,
614
+ `**Type**: ${detail.type}`,
615
+ '',
616
+ '**Content**:',
617
+ '```',
618
+ detail.content,
619
+ '```',
620
+ ''
621
+ ].join('\n');
622
+ }).join('\n---\n\n');
623
+ }
624
+
625
+ export function formatStats(stats: Stats): string {
626
+ return [
627
+ '## Memory Statistics',
628
+ '',
629
+ `- **Total Events**: ${stats.eventCount}`,
630
+ `- **Total Vectors**: ${stats.vectorCount}`,
631
+ `- **Sessions**: ${stats.sessionCount}`,
632
+ `- **Storage Size**: ${(stats.storageSize / 1024 / 1024).toFixed(2)} MB`,
633
+ ''
634
+ ].join('\n');
635
+ }
636
+ ```
637
+
638
+ **작업 항목**:
639
+ - [ ] formatSearchResults 구현
640
+ - [ ] formatTimeline 구현
641
+ - [ ] formatDetails 구현
642
+ - [ ] formatStats 구현
643
+
644
+ ## Phase 3: 설치 CLI (P0)
645
+
646
+ ### 3.1 MCP 설치 명령
647
+
648
+ **파일**: `src/cli/commands/mcp.ts` (신규)
649
+
650
+ ```typescript
651
+ import { Command } from 'commander';
652
+ import * as fs from 'fs';
653
+ import * as path from 'path';
654
+ import * as os from 'os';
655
+
656
+ export const mcpCommand = new Command('mcp')
657
+ .description('Manage MCP server for Claude Desktop');
658
+
659
+ mcpCommand
660
+ .command('install')
661
+ .description('Install MCP server for Claude Desktop')
662
+ .action(async () => {
663
+ const configPath = getClaudeDesktopConfigPath();
664
+ const config = loadOrCreateConfig(configPath);
665
+
666
+ // MCP 서버 설정 추가
667
+ config.mcpServers = config.mcpServers || {};
668
+ config.mcpServers['code-memory'] = {
669
+ command: 'npx',
670
+ args: ['code-memory-mcp'],
671
+ env: {
672
+ MEMORY_PATH: path.join(os.homedir(), '.claude-code', 'memory')
673
+ }
674
+ };
675
+
676
+ // 설정 저장
677
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
678
+
679
+ console.log('✓ MCP server configuration added');
680
+ console.log('');
681
+ console.log('Restart Claude Desktop to use memory search.');
682
+ console.log('');
683
+ console.log('Available tools:');
684
+ console.log(' - mem-search: Search past conversations');
685
+ console.log(' - mem-timeline: Get context around memories');
686
+ console.log(' - mem-details: Get full memory content');
687
+ console.log(' - mem-stats: View storage statistics');
688
+ });
689
+
690
+ mcpCommand
691
+ .command('uninstall')
692
+ .description('Remove MCP server from Claude Desktop')
693
+ .action(async () => {
694
+ const configPath = getClaudeDesktopConfigPath();
695
+ const config = loadOrCreateConfig(configPath);
696
+
697
+ if (config.mcpServers?.['code-memory']) {
698
+ delete config.mcpServers['code-memory'];
699
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
700
+ console.log('✓ MCP server configuration removed');
701
+ } else {
702
+ console.log('MCP server was not installed');
703
+ }
704
+ });
705
+
706
+ mcpCommand
707
+ .command('status')
708
+ .description('Check MCP server installation status')
709
+ .action(async () => {
710
+ const configPath = getClaudeDesktopConfigPath();
711
+
712
+ if (!fs.existsSync(configPath)) {
713
+ console.log('Claude Desktop config not found');
714
+ return;
715
+ }
716
+
717
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
718
+
719
+ if (config.mcpServers?.['code-memory']) {
720
+ console.log('✓ MCP server is installed');
721
+ console.log('');
722
+ console.log('Configuration:');
723
+ console.log(JSON.stringify(config.mcpServers['code-memory'], null, 2));
724
+ } else {
725
+ console.log('✗ MCP server is not installed');
726
+ console.log('');
727
+ console.log('Run "code-memory mcp install" to install');
728
+ }
729
+ });
730
+
731
+ function getClaudeDesktopConfigPath(): string {
732
+ if (process.platform === 'darwin') {
733
+ return path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
734
+ } else if (process.platform === 'win32') {
735
+ return path.join(process.env.APPDATA || '', 'Claude', 'claude_desktop_config.json');
736
+ } else {
737
+ return path.join(os.homedir(), '.config', 'claude', 'claude_desktop_config.json');
738
+ }
739
+ }
740
+
741
+ function loadOrCreateConfig(configPath: string): any {
742
+ const dir = path.dirname(configPath);
743
+ if (!fs.existsSync(dir)) {
744
+ fs.mkdirSync(dir, { recursive: true });
745
+ }
746
+
747
+ if (fs.existsSync(configPath)) {
748
+ return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
749
+ }
750
+
751
+ return {};
752
+ }
753
+ ```
754
+
755
+ **작업 항목**:
756
+ - [ ] install 명령 구현
757
+ - [ ] uninstall 명령 구현
758
+ - [ ] status 명령 구현
759
+ - [ ] 플랫폼별 경로 처리
760
+
761
+ ## Phase 4: 테스트 및 문서 (P1)
762
+
763
+ ### 4.1 통합 테스트
764
+
765
+ **파일**: `packages/mcp-server/tests/integration.test.ts` (신규)
766
+
767
+ ```typescript
768
+ import { handleToolCall } from '../src/handlers';
769
+
770
+ describe('MCP Server', () => {
771
+ test('mem-search returns results', async () => {
772
+ const result = await handleToolCall('mem-search', {
773
+ query: 'test query'
774
+ });
775
+
776
+ expect(result.isError).toBeFalsy();
777
+ expect(result.content[0].type).toBe('text');
778
+ });
779
+
780
+ test('mem-details returns full content', async () => {
781
+ const result = await handleToolCall('mem-details', {
782
+ ids: ['test-id']
783
+ });
784
+
785
+ expect(result.isError).toBeFalsy();
786
+ });
787
+
788
+ test('invalid tool returns error', async () => {
789
+ const result = await handleToolCall('invalid-tool', {});
790
+
791
+ expect(result.isError).toBe(true);
792
+ });
793
+ });
794
+ ```
795
+
796
+ **작업 항목**:
797
+ - [ ] 도구별 테스트
798
+ - [ ] 에러 케이스 테스트
799
+ - [ ] E2E 테스트 (실제 Claude Desktop)
800
+
801
+ ## 파일 목록
802
+
803
+ ### 신규 파일
804
+ ```
805
+ packages/mcp-server/
806
+ ├── package.json
807
+ ├── tsconfig.json
808
+ ├── src/
809
+ │ ├── index.ts # 서버 진입점
810
+ │ ├── tools.ts # 도구 정의
811
+ │ ├── handlers.ts # 도구 핸들러
812
+ │ └── formatters.ts # 출력 포맷터
813
+ └── tests/
814
+ └── integration.test.ts
815
+
816
+ src/cli/commands/mcp.ts # CLI 명령
817
+ ```
818
+
819
+ ### 수정 파일
820
+ ```
821
+ package.json # 워크스페이스 설정
822
+ src/cli/index.ts # mcp 명령 등록
823
+ ```
824
+
825
+ ## 마일스톤
826
+
827
+ | 단계 | 완료 기준 |
828
+ |------|----------|
829
+ | M1 | MCP 서버 패키지 구조 |
830
+ | M2 | 도구 정의 |
831
+ | M3 | 핸들러 구현 |
832
+ | M4 | 포맷터 구현 |
833
+ | M5 | CLI 설치 명령 |
834
+ | M6 | 테스트 |
835
+ | M7 | 문서화 |
836
+ | M8 | npm 배포 |
837
+
838
+ ## 2026-02-25T12:31:26.344Z | c1410cb5-9d74-454b-a514-0b601bf3807d
839
+ - type: session_summary
840
+ - session: import:organized
841
+ # MCP Desktop Integration Specification
842
+
843
+ > **Version**: 1.0.0
844
+ > **Status**: Draft
845
+ > **Created**: 2026-02-01
846
+ > **Reference**: claude-mem (thedotmack/claude-mem)
847
+
848
+ ## 1. 개요
849
+
850
+ ### 1.1 문제 정의
851
+
852
+ 현재 code-memory는 Claude Code CLI 전용:
853
+
854
+ 1. **Claude Desktop 미지원**: 데스크톱 앱에서 메모리 검색 불가
855
+ 2. **환경 분리**: CLI와 Desktop 간 메모리 공유 안 됨
856
+ 3. **접근성 제한**: 터미널 없이는 메모리 활용 불가
857
+
858
+ ### 1.2 해결 방향
859
+
860
+ **MCP (Model Context Protocol) 서버**:
861
+ - Claude Desktop에서 메모리 검색 도구 제공
862
+ - CLI와 동일한 메모리 저장소 공유
863
+ - 표준 MCP 프로토콜 준수
864
+
865
+ ## 2. 핵심 개념
866
+
867
+ ### 2.1 MCP 아키텍처
868
+
869
+ ```
870
+ ┌─────────────────────────────────────────────────────────────┐
871
+ │ Claude Desktop │
872
+ │ ┌─────────────────────────────────────────────────────┐ │
873
+ │ │ MCP Client │ │
874
+ │ │ - Tool Discovery │ │
875
+ │ │ - Tool Invocation │ │
876
+ │ └────────────────────────┬────────────────────────────┘ │
877
+ └───────────────────────────┼─────────────────────────────────┘
878
+ │ stdio / HTTP
879
+
880
+ ┌─────────────────────────────────────────────────────────────┐
881
+ │ MCP Server │
882
+ │ ┌─────────────────────────────────────────────────────┐ │
883
+ │ │ code-memory-mcp │ │
884
+ │ │ - mem-search tool │ │
885
+ │ │ - mem-timeline tool │ │
886
+ │ │ - mem-details tool │ │
887
+ │ └────────────────────────┬────────────────────────────┘ │
888
+ └───────────────────────────┼─────────────────────────────────┘
889
+
890
+
891
+ ┌─────────────────────────────────────────────────────────────┐
892
+ │ Memory Storage │
893
+ │ ┌──────────────┐ ┌──────────────┐ │
894
+ │ │ DuckDB │ │ LanceDB │ │
895
+ │ │ Events │ │ Vectors │ │
896
+ │ └──────────────┘ └──────────────┘ │
897
+ └─────────────────────────────────────────────────────────────┘
898
+ ```
899
+
900
+ ### 2.2 제공할 MCP 도구
901
+
902
+ | 도구 | 설명 | 입력 |
903
+ |------|------|------|
904
+ | `mem-search` | 메모리 검색 | query, filters |
905
+ | `mem-timeline` | 타임라인 조회 | ids, windowSize |
906
+ | `mem-details` | 상세 정보 조회 | ids |
907
+ | `mem-stats` | 통계 조회 | - |
908
+
909
+ ### 2.3 MCP 프로토콜 버전
910
+
911
+ ```typescript
912
+ const MCP_VERSION = '2024-11-05'; // 최신 MCP 사양
913
+ ```
914
+
915
+ ## 3. MCP 서버 구현
916
+
917
+ ### 3.1 서버 메타데이터
918
+
919
+ ```typescript
920
+ const serverInfo = {
921
+ name: 'code-memory-mcp',
922
+ version: '1.0.0',
923
+ protocolVersion: MCP_VERSION,
924
+ capabilities: {
925
+ tools: {
926
+ listChanged: false
927
+ }
928
+ }
929
+ };
930
+ ```
931
+
932
+ ### 3.2 도구 정의
933
+
934
+ ```typescript
935
+ const tools = [
936
+ {
937
+ name: 'mem-search',
938
+ description: 'Search code-memory for relevant past conversations and insights',
939
+ inputSchema: {
940
+ type: 'object',
941
+ properties: {
942
+ query: {
943
+ type: 'string',
944
+ description: 'Search query'
945
+ },
946
+ topK: {
947
+ type: 'number',
948
+ description: 'Maximum results (default: 5)'
949
+ },
950
+ sessionId: {
951
+ type: 'string',
952
+ description: 'Filter by session ID'
953
+ },
954
+ eventType: {
955
+ type: 'string',
956
+ enum: ['prompt', 'response', 'tool', 'insight'],
957
+ description: 'Filter by event type'
958
+ }
959
+ },
960
+ required: ['query']
961
+ }
962
+ },
963
+ {
964
+ name: 'mem-timeline',
965
+ description: 'Get timeline context around specific memories',
966
+ inputSchema: {
967
+ type: 'object',
968
+ properties: {
969
+ ids: {
970
+ type: 'array',
971
+ items: { type: 'string' },
972
+ description: 'Memory IDs to get timeline for'
973
+ },
974
+ windowSize: {
975
+ type: 'number',
976
+ description: 'Number of items before/after (default: 3)'
977
+ }
978
+ },
979
+ required: ['ids']
980
+ }
981
+ },
982
+ {
983
+ name: 'mem-details',
984
+ description: 'Get full details of specific memories',
985
+ inputSchema: {
986
+ type: 'object',
987
+ properties: {
988
+ ids: {
989
+ type: 'array',
990
+ items: { type: 'string' },
991
+ description: 'Memory IDs to fetch'
992
+ }
993
+ },
994
+ required: ['ids']
995
+ }
996
+ },
997
+ {
998
+ name: 'mem-stats',
999
+ description: 'Get memory storage statistics',
1000
+ inputSchema: {
1001
+ type: 'object',
1002
+ properties: {}
1003
+ }
1004
+ }
1005
+ ];
1006
+ ```
1007
+
1008
+ ### 3.3 도구 실행
1009
+
1010
+ ```typescript
1011
+ async function handleToolCall(
1012
+ name: string,
1013
+ args: Record<string, unknown>
1014
+ ): Promise<ToolResult> {
1015
+ const memoryService = await MemoryService.getInstance();
1016
+
1017
+ switch (name) {
1018
+ case 'mem-search': {
1019
+ const results = await memoryService.progressiveSearch(
1020
+ args.query as string,
1021
+ {
1022
+ topK: args.topK as number,
1023
+ filter: {
1024
+ sessionId: args.sessionId as string,
1025
+ eventType: args.eventType as string
1026
+ }
1027
+ }
1028
+ );
1029
+
1030
+ return {
1031
+ content: [
1032
+ {
1033
+ type: 'text',
1034
+ text: formatSearchResults(results)
1035
+ }
1036
+ ]
1037
+ };
1038
+ }
1039
+
1040
+ case 'mem-timeline': {
1041
+ const timeline = await memoryService.getTimeline(
1042
+ args.ids as string[],
1043
+ { windowSize: args.windowSize as number }
1044
+ );
1045
+
1046
+ return {
1047
+ content: [
1048
+ {
1049
+ type: 'text',
1050
+ text: formatTimeline(timeline)
1051
+ }
1052
+ ]
1053
+ };
1054
+ }
1055
+
1056
+ case 'mem-details': {
1057
+ const details = await memoryService.getDetails(args.ids as string[]);
1058
+
1059
+ return {
1060
+ content: [
1061
+ {
1062
+ type: 'text',
1063
+ text: formatDetails(details)
1064
+ }
1065
+ ]
1066
+ };
1067
+ }
1068
+
1069
+ case 'mem-stats': {
1070
+ const stats = await memoryService.getStats();
1071
+
1072
+ return {
1073
+ content: [
1074
+ {
1075
+ type: 'text',
1076
+ text: formatStats(stats)
1077
+ }
1078
+ ]
1079
+ };
1080
+ }
1081
+
1082
+ default:
1083
+ throw new Error(`Unknown tool: ${name}`);
1084
+ }
1085
+ }
1086
+ ```
1087
+
1088
+ ## 4. 설치 및 설정
1089
+
1090
+ ### 4.1 Claude Desktop 설정
1091
+
1092
+ **파일**: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
1093
+
1094
+ ```json
1095
+ {
1096
+ "mcpServers": {
1097
+ "code-memory": {
1098
+ "command": "npx",
1099
+ "args": ["code-memory-mcp"],
1100
+ "env": {
1101
+ "MEMORY_PATH": "~/.claude-code/memory"
1102
+ }
1103
+ }
1104
+ }
1105
+ }
1106
+ ```
1107
+
1108
+ ### 4.2 Windows 설정
1109
+
1110
+ **파일**: `%APPDATA%\Claude\claude_desktop_config.json`
1111
+
1112
+ ```json
1113
+ {
1114
+ "mcpServers": {
1115
+ "code-memory": {
1116
+ "command": "npx.cmd",
1117
+ "args": ["code-memory-mcp"],
1118
+ "env": {
1119
+ "MEMORY_PATH": "%USERPROFILE%\\.claude-code\\memory"
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ ```
1125
+
1126
+ ### 4.3 자동 설치 CLI
1127
+
1128
+ ```bash
1129
+ # 설치 명령
1130
+ $ code-memory mcp install
1131
+
1132
+ Installing MCP server for Claude Desktop...
1133
+ ✓ Created MCP server configuration
1134
+ ✓ Updated Claude Desktop config
1135
+
1136
+ Restart Claude Desktop to use memory search.
1137
+
1138
+ # 제거 명령
1139
+ $ code-memory mcp uninstall
1140
+ ```
1141
+
1142
+ ## 5. 통신 프로토콜
1143
+
1144
+ ### 5.1 stdio 기반 통신
1145
+
1146
+ ```typescript
1147
+ // MCP 서버 진입점
1148
+ import { Server } from '@modelcontextprotocol/sdk/server';
1149
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio';
1150
+
1151
+ const server = new Server(serverInfo, {
1152
+ capabilities: {
1153
+ tools: {}
1154
+ }
1155
+ });
1156
+
1157
+ // 도구 핸들러 등록
1158
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
1159
+ return { tools };
1160
+ });
1161
+
1162
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1163
+ return handleToolCall(request.params.name, request.params.arguments);
1164
+ });
1165
+
1166
+ // stdio 연결
1167
+ const transport = new StdioServerTransport();
1168
+ await server.connect(transport);
1169
+ ```
1170
+
1171
+ ### 5.2 메시지 형식
1172
+
1173
+ ```typescript
1174
+ // 요청 예시
1175
+ {
1176
+ "jsonrpc": "2.0",
1177
+ "id": 1,
1178
+ "method": "tools/call",
1179
+ "params": {
1180
+ "name": "mem-search",
1181
+ "arguments": {
1182
+ "query": "DuckDB schema design"
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ // 응답 예시
1188
+ {
1189
+ "jsonrpc": "2.0",
1190
+ "id": 1,
1191
+ "result": {
1192
+ "content": [
1193
+ {
1194
+ "type": "text",
1195
+ "text": "Found 3 relevant memories:\n\n1. [mem:a7Bc3x] ..."
1196
+ }
1197
+ ]
1198
+ }
1199
+ }
1200
+ ```
1201
+
1202
+ ## 6. 출력 포맷
1203
+
1204
+ ### 6.1 검색 결과
1205
+
1206
+ ```markdown
1207
+ ## Memory Search Results
1208
+
1209
+ Found 3 relevant memories for "DuckDB schema":
1210
+
1211
+ ### 1. [mem:a7Bc3x] (0.94)
1212
+ **Session**: abc123 | **Date**: 2026-01-30
1213
+ > DuckDB를 사용하여 이벤트 소싱 패턴을 구현하는 것이 좋습니다...
1214
+
1215
+ ### 2. [mem:b8Xc2y] (0.87)
1216
+ **Session**: def456 | **Date**: 2026-01-29
1217
+ > 스키마 설계 시 인덱싱 전략을 고려해야 합니다...
1218
+
1219
+ ---
1220
+ Use `mem-details` with IDs for full content.
1221
+ Use `mem-timeline` for context around these memories.
1222
+ ```
1223
+
1224
+ ### 6.2 타임라인
1225
+
1226
+ ```markdown
1227
+ ## Timeline Context
1228
+
1229
+ ### Around [mem:a7Bc3x]
1230
+
1231
+ | Time | Type | Preview |
1232
+ |------|------|---------|
1233
+ | 14:00 | prompt | DB 스키마를 어떻게 설계할까요? |
1234
+ | **14:05** | **response** | **[mem:a7Bc3x] DuckDB를 사용하여...** |
1235
+ | 14:10 | prompt | 인덱스는 어떻게? |
1236
+ | 14:15 | response | 다음 인덱스들을 추천합니다... |
1237
+ ```
1238
+
1239
+ ### 6.3 상세 정보
1240
+
1241
+ ```markdown
1242
+ ## Memory Details
1243
+
1244
+ ### [mem:a7Bc3x]
1245
+
1246
+ **Session**: abc123
1247
+ **Date**: 2026-01-30 14:05
1248
+ **Type**: assistant_response
1249
+
1250
+ **Content**:
1251
+ ```
1252
+ DuckDB를 사용하여 이벤트 소싱 패턴을 구현하는 것이 좋습니다.
1253
+
1254
+ 이벤트는 불변이어야 하며, append-only 방식으로 저장합니다.
1255
+
1256
+ 스키마 예시:
1257
+ CREATE TABLE events (
1258
+ event_id VARCHAR PRIMARY KEY,
1259
+ event_type VARCHAR NOT NULL,
1260
+ ...
1261
+ );
1262
+ ```
1263
+
1264
+ **Related Files**: src/core/event-store.ts
1265
+ **Tools Used**: Read, Write
1266
+ ```
1267
+
1268
+ ## 7. 보안
1269
+
1270
+ ### 7.1 로컬 전용
1271
+
1272
+ ```typescript
1273
+ // MCP 서버는 로컬에서만 실행
1274
+ // 네트워크 노출 없음
1275
+ const server = new Server(serverInfo);
1276
+ const transport = new StdioServerTransport(); // stdio만 사용
1277
+ ```
1278
+
1279
+ ### 7.2 경로 검증
1280
+
1281
+ ```typescript
1282
+ function validateMemoryPath(path: string): boolean {
1283
+ const resolved = path.resolve(path);
1284
+
1285
+ // 홈 디렉토리 하위만 허용
1286
+ const home = os.homedir();
1287
+ if (!resolved.startsWith(home)) {
1288
+ throw new Error('Memory path must be under home directory');
1289
+ }
1290
+
1291
+ return true;
1292
+ }
1293
+ ```
1294
+
1295
+ ### 7.3 민감 정보 필터링
1296
+
1297
+ ```typescript
1298
+ // MCP 응답에서도 privacy 필터 적용
1299
+ function formatForMCP(content: string): string {
1300
+ return applyPrivacyFilter(content, config.privacy).content;
1301
+ }
1302
+ ```
1303
+
1304
+ ## 8. 에러 처리
1305
+
1306
+ ```typescript
1307
+ // MCP 에러 응답
1308
+ function handleError(error: Error): ToolResult {
1309
+ return {
1310
+ content: [
1311
+ {
1312
+ type: 'text',
1313
+ text: `Error: ${error.message}`
1314
+ }
1315
+ ],
1316
+ isError: true
1317
+ };
1318
+ }
1319
+
1320
+ // 일반적인 에러 케이스
1321
+ - Memory storage not found
1322
+ - Invalid query parameters
1323
+ - Permission denied
1324
+ - Storage corrupted
1325
+ ```
1326
+
1327
+ ## 9. 성공 기준
1328
+
1329
+ - [ ] `code-memory mcp install` 명령 동작
1330
+ - [ ] Claude Desktop에서 `mem-search` 도구 사용 가능
1331
+ - [ ] Progressive disclosure (search → timeline → details) 동작
1332
+ - [ ] CLI와 동일한 메모리 저장소 공유
1333
+ - [ ] Privacy 필터 적용
1334
+ - [ ] 에러 시 적절한 메시지 반환