spatial-memory-mcp 1.9.1__py3-none-any.whl

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 (55) hide show
  1. spatial_memory/__init__.py +97 -0
  2. spatial_memory/__main__.py +271 -0
  3. spatial_memory/adapters/__init__.py +7 -0
  4. spatial_memory/adapters/lancedb_repository.py +880 -0
  5. spatial_memory/config.py +769 -0
  6. spatial_memory/core/__init__.py +118 -0
  7. spatial_memory/core/cache.py +317 -0
  8. spatial_memory/core/circuit_breaker.py +297 -0
  9. spatial_memory/core/connection_pool.py +220 -0
  10. spatial_memory/core/consolidation_strategies.py +401 -0
  11. spatial_memory/core/database.py +3072 -0
  12. spatial_memory/core/db_idempotency.py +242 -0
  13. spatial_memory/core/db_indexes.py +576 -0
  14. spatial_memory/core/db_migrations.py +588 -0
  15. spatial_memory/core/db_search.py +512 -0
  16. spatial_memory/core/db_versioning.py +178 -0
  17. spatial_memory/core/embeddings.py +558 -0
  18. spatial_memory/core/errors.py +317 -0
  19. spatial_memory/core/file_security.py +701 -0
  20. spatial_memory/core/filesystem.py +178 -0
  21. spatial_memory/core/health.py +289 -0
  22. spatial_memory/core/helpers.py +79 -0
  23. spatial_memory/core/import_security.py +433 -0
  24. spatial_memory/core/lifecycle_ops.py +1067 -0
  25. spatial_memory/core/logging.py +194 -0
  26. spatial_memory/core/metrics.py +192 -0
  27. spatial_memory/core/models.py +660 -0
  28. spatial_memory/core/rate_limiter.py +326 -0
  29. spatial_memory/core/response_types.py +500 -0
  30. spatial_memory/core/security.py +588 -0
  31. spatial_memory/core/spatial_ops.py +430 -0
  32. spatial_memory/core/tracing.py +300 -0
  33. spatial_memory/core/utils.py +110 -0
  34. spatial_memory/core/validation.py +406 -0
  35. spatial_memory/factory.py +444 -0
  36. spatial_memory/migrations/__init__.py +40 -0
  37. spatial_memory/ports/__init__.py +11 -0
  38. spatial_memory/ports/repositories.py +630 -0
  39. spatial_memory/py.typed +0 -0
  40. spatial_memory/server.py +1214 -0
  41. spatial_memory/services/__init__.py +70 -0
  42. spatial_memory/services/decay_manager.py +411 -0
  43. spatial_memory/services/export_import.py +1031 -0
  44. spatial_memory/services/lifecycle.py +1139 -0
  45. spatial_memory/services/memory.py +412 -0
  46. spatial_memory/services/spatial.py +1152 -0
  47. spatial_memory/services/utility.py +429 -0
  48. spatial_memory/tools/__init__.py +5 -0
  49. spatial_memory/tools/definitions.py +695 -0
  50. spatial_memory/verify.py +140 -0
  51. spatial_memory_mcp-1.9.1.dist-info/METADATA +509 -0
  52. spatial_memory_mcp-1.9.1.dist-info/RECORD +55 -0
  53. spatial_memory_mcp-1.9.1.dist-info/WHEEL +4 -0
  54. spatial_memory_mcp-1.9.1.dist-info/entry_points.txt +2 -0
  55. spatial_memory_mcp-1.9.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,500 @@
1
+ """TypedDict response types for MCP handler responses.
2
+
3
+ This module provides compile-time type checking for all 22 handler responses
4
+ in the Spatial Memory MCP server. Using TypedDicts enables mypy to catch
5
+ type mismatches in handler implementations.
6
+
7
+ Usage in server.py:
8
+ def _handle_recall(self, arguments: dict[str, Any]) -> RecallResponse:
9
+ ...
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Any, TypedDict
15
+
16
+ from typing_extensions import NotRequired
17
+
18
+ # =============================================================================
19
+ # Nested TypedDicts (shared across multiple responses)
20
+ # =============================================================================
21
+
22
+
23
+ class MemoryResultDict(TypedDict):
24
+ """Memory with similarity score from search operations."""
25
+
26
+ id: str
27
+ content: str
28
+ similarity: float
29
+ namespace: str
30
+ tags: list[str]
31
+ importance: float
32
+ created_at: str # ISO 8601 format
33
+ metadata: dict[str, Any]
34
+ effective_importance: NotRequired[float] # Time-decayed importance (auto-decay)
35
+
36
+
37
+ class MemoryReferenceDict(TypedDict):
38
+ """Minimal memory reference for nearby operations."""
39
+
40
+ id: str
41
+ content: str
42
+ namespace: str
43
+
44
+
45
+ class NeighborDict(TypedDict):
46
+ """Neighbor memory with similarity for nearby operations."""
47
+
48
+ id: str
49
+ content: str
50
+ similarity: float
51
+ namespace: str
52
+
53
+
54
+ class JourneyMemoryDict(TypedDict):
55
+ """Memory found along a journey path."""
56
+
57
+ id: str
58
+ content: str
59
+ similarity: float
60
+
61
+
62
+ class JourneyStepDict(TypedDict):
63
+ """A step along the journey path."""
64
+
65
+ step: int
66
+ t: float
67
+ nearby_memories: list[JourneyMemoryDict]
68
+ distance_to_path: float
69
+
70
+
71
+ class WanderMemoryDict(TypedDict):
72
+ """Memory at a wander step."""
73
+
74
+ id: str
75
+ content: str
76
+ namespace: str
77
+ tags: list[str]
78
+ similarity: float
79
+
80
+
81
+ class WanderStepDict(TypedDict):
82
+ """A step in a random walk."""
83
+
84
+ step: int
85
+ memory: WanderMemoryDict
86
+ similarity_to_previous: float
87
+ selection_probability: float
88
+
89
+
90
+ class RepresentativeMemoryDict(TypedDict):
91
+ """Representative memory for a cluster."""
92
+
93
+ id: str
94
+ content: str
95
+
96
+
97
+ class SampleMemoryDict(TypedDict):
98
+ """Sample memory from a cluster."""
99
+
100
+ id: str
101
+ content: str
102
+ similarity: float
103
+
104
+
105
+ class ClusterDict(TypedDict):
106
+ """A discovered cluster in regions analysis."""
107
+
108
+ cluster_id: int
109
+ size: int
110
+ keywords: list[str]
111
+ representative_memory: RepresentativeMemoryDict
112
+ sample_memories: list[SampleMemoryDict]
113
+ coherence: float
114
+
115
+
116
+ class VisualizationNodeDict(TypedDict):
117
+ """A node in the visualization."""
118
+
119
+ id: str
120
+ x: float
121
+ y: float
122
+ label: str
123
+ cluster: int
124
+ importance: float
125
+
126
+
127
+ class VisualizationEdgeDict(TypedDict):
128
+ """An edge in the visualization."""
129
+
130
+ from_id: str
131
+ to_id: str
132
+ weight: float
133
+
134
+
135
+ class DecayedMemoryDict(TypedDict):
136
+ """A memory with calculated decay."""
137
+
138
+ id: str
139
+ content_preview: str
140
+ old_importance: float
141
+ new_importance: float
142
+ decay_factor: float
143
+ days_since_access: int
144
+ access_count: int
145
+
146
+
147
+ class ReinforcedMemoryDict(TypedDict):
148
+ """A memory that was reinforced."""
149
+
150
+ id: str
151
+ content_preview: str
152
+ old_importance: float
153
+ new_importance: float
154
+ boost_applied: float
155
+
156
+
157
+ class ExtractionDict(TypedDict):
158
+ """An extracted memory from text."""
159
+
160
+ content: str
161
+ confidence: float
162
+ pattern_matched: str
163
+ start_pos: int
164
+ end_pos: int
165
+ stored: bool
166
+ memory_id: str | None
167
+
168
+
169
+ class ConsolidationGroupDict(TypedDict):
170
+ """A group of similar memories for consolidation."""
171
+
172
+ representative_id: str
173
+ member_ids: list[str]
174
+ avg_similarity: float
175
+ action_taken: str
176
+
177
+
178
+ class IndexInfoDict(TypedDict):
179
+ """Information about a database index."""
180
+
181
+ name: str
182
+ index_type: str
183
+ column: str
184
+ num_indexed_rows: int
185
+ status: str
186
+
187
+
188
+ class NamespaceInfoDict(TypedDict):
189
+ """Information about a namespace."""
190
+
191
+ name: str
192
+ memory_count: int
193
+ oldest_memory: str | None # ISO 8601 format
194
+ newest_memory: str | None # ISO 8601 format
195
+
196
+
197
+ class HealthCheckDict(TypedDict):
198
+ """A single health check result."""
199
+
200
+ name: str
201
+ status: str
202
+ message: str | None
203
+ latency_ms: float | None
204
+
205
+
206
+ class ImportValidationErrorDict(TypedDict):
207
+ """A validation error during import."""
208
+
209
+ row_number: int
210
+ field: str
211
+ error: str
212
+ value: str | None
213
+
214
+
215
+ class ImportedMemoryDict(TypedDict):
216
+ """Information about an imported memory."""
217
+
218
+ id: str
219
+ content_preview: str
220
+ namespace: str
221
+
222
+
223
+ class HybridMemoryDict(TypedDict):
224
+ """A memory matched by hybrid search."""
225
+
226
+ id: str
227
+ content: str
228
+ similarity: float
229
+ namespace: str
230
+ tags: list[str]
231
+ importance: float
232
+ created_at: str | None # ISO 8601 format
233
+ metadata: dict[str, Any]
234
+ vector_score: float | None
235
+ fts_score: float | None
236
+ effective_importance: NotRequired[float] # Time-decayed importance (auto-decay)
237
+
238
+
239
+ # =============================================================================
240
+ # Handler Response TypedDicts (22 total)
241
+ # =============================================================================
242
+
243
+
244
+ class RememberResponse(TypedDict):
245
+ """Response for remember handler."""
246
+
247
+ id: str
248
+ content: str
249
+ namespace: str
250
+ deduplicated: bool
251
+
252
+
253
+ class RememberBatchResponse(TypedDict):
254
+ """Response for remember_batch handler."""
255
+
256
+ ids: list[str]
257
+ count: int
258
+
259
+
260
+ class RecallResponse(TypedDict):
261
+ """Response for recall handler."""
262
+
263
+ memories: list[MemoryResultDict]
264
+ total: int
265
+
266
+
267
+ class NearbyResponse(TypedDict):
268
+ """Response for nearby handler."""
269
+
270
+ reference: MemoryReferenceDict
271
+ neighbors: list[NeighborDict]
272
+
273
+
274
+ class ForgetResponse(TypedDict):
275
+ """Response for forget handler."""
276
+
277
+ deleted: int
278
+ ids: list[str]
279
+
280
+
281
+ class ForgetBatchResponse(TypedDict):
282
+ """Response for forget_batch handler."""
283
+
284
+ deleted: int
285
+ ids: list[str]
286
+
287
+
288
+ class HealthResponse(TypedDict, total=False):
289
+ """Response for health handler.
290
+
291
+ Uses total=False for optional 'checks' field.
292
+ """
293
+
294
+ version: str
295
+ status: str
296
+ timestamp: str # ISO 8601 format
297
+ ready: bool
298
+ alive: bool
299
+ checks: list[HealthCheckDict] # Optional, only with verbose=True
300
+
301
+
302
+ class JourneyResponse(TypedDict):
303
+ """Response for journey handler."""
304
+
305
+ start_id: str
306
+ end_id: str
307
+ steps: list[JourneyStepDict]
308
+ path_coverage: float
309
+
310
+
311
+ class WanderResponse(TypedDict):
312
+ """Response for wander handler."""
313
+
314
+ start_id: str
315
+ steps: list[WanderStepDict]
316
+ total_distance: float
317
+
318
+
319
+ class RegionsResponse(TypedDict):
320
+ """Response for regions handler."""
321
+
322
+ clusters: list[ClusterDict]
323
+ total_memories: int
324
+ noise_count: int
325
+ clustering_quality: float
326
+
327
+
328
+ class VisualizeJsonResponse(TypedDict):
329
+ """Response for visualize handler with JSON format."""
330
+
331
+ nodes: list[VisualizationNodeDict]
332
+ edges: list[VisualizationEdgeDict]
333
+ bounds: dict[str, float]
334
+ format: str
335
+
336
+
337
+ class VisualizeTextResponse(TypedDict):
338
+ """Response for visualize handler with mermaid/svg format."""
339
+
340
+ format: str
341
+ output: str
342
+ node_count: int
343
+
344
+
345
+ # Union type for visualize response
346
+ VisualizeResponse = VisualizeJsonResponse | VisualizeTextResponse
347
+
348
+
349
+ class DecayResponse(TypedDict):
350
+ """Response for decay handler."""
351
+
352
+ memories_analyzed: int
353
+ memories_decayed: int
354
+ avg_decay_factor: float
355
+ decayed_memories: list[DecayedMemoryDict]
356
+ dry_run: bool
357
+
358
+
359
+ class ReinforceResponse(TypedDict):
360
+ """Response for reinforce handler."""
361
+
362
+ memories_reinforced: int
363
+ avg_boost: float
364
+ reinforced: list[ReinforcedMemoryDict]
365
+ not_found: list[str]
366
+
367
+
368
+ class ExtractResponse(TypedDict):
369
+ """Response for extract handler."""
370
+
371
+ candidates_found: int
372
+ memories_created: int
373
+ deduplicated_count: int
374
+ extractions: list[ExtractionDict]
375
+
376
+
377
+ class ConsolidateResponse(TypedDict):
378
+ """Response for consolidate handler."""
379
+
380
+ groups_found: int
381
+ memories_merged: int
382
+ memories_deleted: int
383
+ groups: list[ConsolidationGroupDict]
384
+ dry_run: bool
385
+
386
+
387
+ class StatsResponse(TypedDict):
388
+ """Response for stats handler."""
389
+
390
+ total_memories: int
391
+ memories_by_namespace: dict[str, int]
392
+ storage_bytes: int
393
+ storage_mb: float
394
+ estimated_vector_bytes: int
395
+ has_vector_index: bool
396
+ has_fts_index: bool
397
+ indices: list[IndexInfoDict]
398
+ num_fragments: int
399
+ needs_compaction: bool
400
+ table_version: int
401
+ oldest_memory_date: str | None # ISO 8601 format
402
+ newest_memory_date: str | None # ISO 8601 format
403
+ avg_content_length: float | None
404
+
405
+
406
+ class NamespacesResponse(TypedDict):
407
+ """Response for namespaces handler."""
408
+
409
+ namespaces: list[NamespaceInfoDict]
410
+ total_namespaces: int
411
+ total_memories: int
412
+
413
+
414
+ class DeleteNamespaceResponse(TypedDict):
415
+ """Response for delete_namespace handler."""
416
+
417
+ namespace: str
418
+ memories_deleted: int
419
+ success: bool
420
+ message: str
421
+ dry_run: bool
422
+
423
+
424
+ class RenameNamespaceResponse(TypedDict):
425
+ """Response for rename_namespace handler."""
426
+
427
+ old_namespace: str
428
+ new_namespace: str
429
+ memories_renamed: int
430
+ success: bool
431
+ message: str
432
+
433
+
434
+ class ExportResponse(TypedDict):
435
+ """Response for export_memories handler."""
436
+
437
+ format: str
438
+ output_path: str
439
+ memories_exported: int
440
+ file_size_bytes: int
441
+ file_size_mb: float
442
+ namespaces_included: list[str]
443
+ duration_seconds: float
444
+ compression: str | None
445
+
446
+
447
+ class ImportResponse(TypedDict):
448
+ """Response for import_memories handler."""
449
+
450
+ source_path: str
451
+ format: str
452
+ total_records_in_file: int
453
+ memories_imported: int
454
+ memories_skipped: int
455
+ memories_failed: int
456
+ validation_errors: list[ImportValidationErrorDict]
457
+ namespace_override: str | None
458
+ duration_seconds: float
459
+ dry_run: bool
460
+ imported_memories: list[ImportedMemoryDict]
461
+
462
+
463
+ class HybridRecallResponse(TypedDict):
464
+ """Response for hybrid_recall handler."""
465
+
466
+ query: str
467
+ alpha: float
468
+ memories: list[HybridMemoryDict]
469
+ total: int
470
+ search_type: str
471
+
472
+
473
+ # =============================================================================
474
+ # Type alias for any handler response
475
+ # =============================================================================
476
+
477
+ HandlerResponse = (
478
+ RememberResponse
479
+ | RememberBatchResponse
480
+ | RecallResponse
481
+ | NearbyResponse
482
+ | ForgetResponse
483
+ | ForgetBatchResponse
484
+ | HealthResponse
485
+ | JourneyResponse
486
+ | WanderResponse
487
+ | RegionsResponse
488
+ | VisualizeResponse
489
+ | DecayResponse
490
+ | ReinforceResponse
491
+ | ExtractResponse
492
+ | ConsolidateResponse
493
+ | StatsResponse
494
+ | NamespacesResponse
495
+ | DeleteNamespaceResponse
496
+ | RenameNamespaceResponse
497
+ | ExportResponse
498
+ | ImportResponse
499
+ | HybridRecallResponse
500
+ )