spatial-memory-mcp 1.6.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.

Potentially problematic release.


This version of spatial-memory-mcp might be problematic. Click here for more details.

Files changed (54) hide show
  1. spatial_memory/__init__.py +97 -0
  2. spatial_memory/__main__.py +270 -0
  3. spatial_memory/adapters/__init__.py +7 -0
  4. spatial_memory/adapters/lancedb_repository.py +878 -0
  5. spatial_memory/config.py +728 -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 +402 -0
  11. spatial_memory/core/database.py +3069 -0
  12. spatial_memory/core/db_idempotency.py +242 -0
  13. spatial_memory/core/db_indexes.py +575 -0
  14. spatial_memory/core/db_migrations.py +584 -0
  15. spatial_memory/core/db_search.py +509 -0
  16. spatial_memory/core/db_versioning.py +177 -0
  17. spatial_memory/core/embeddings.py +557 -0
  18. spatial_memory/core/errors.py +317 -0
  19. spatial_memory/core/file_security.py +702 -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 +432 -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 +628 -0
  28. spatial_memory/core/rate_limiter.py +326 -0
  29. spatial_memory/core/response_types.py +497 -0
  30. spatial_memory/core/security.py +588 -0
  31. spatial_memory/core/spatial_ops.py +426 -0
  32. spatial_memory/core/tracing.py +300 -0
  33. spatial_memory/core/utils.py +110 -0
  34. spatial_memory/core/validation.py +403 -0
  35. spatial_memory/factory.py +407 -0
  36. spatial_memory/migrations/__init__.py +40 -0
  37. spatial_memory/ports/__init__.py +11 -0
  38. spatial_memory/ports/repositories.py +631 -0
  39. spatial_memory/py.typed +0 -0
  40. spatial_memory/server.py +1141 -0
  41. spatial_memory/services/__init__.py +70 -0
  42. spatial_memory/services/export_import.py +1023 -0
  43. spatial_memory/services/lifecycle.py +1120 -0
  44. spatial_memory/services/memory.py +412 -0
  45. spatial_memory/services/spatial.py +1147 -0
  46. spatial_memory/services/utility.py +409 -0
  47. spatial_memory/tools/__init__.py +5 -0
  48. spatial_memory/tools/definitions.py +695 -0
  49. spatial_memory/verify.py +140 -0
  50. spatial_memory_mcp-1.6.1.dist-info/METADATA +499 -0
  51. spatial_memory_mcp-1.6.1.dist-info/RECORD +54 -0
  52. spatial_memory_mcp-1.6.1.dist-info/WHEEL +4 -0
  53. spatial_memory_mcp-1.6.1.dist-info/entry_points.txt +2 -0
  54. spatial_memory_mcp-1.6.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,97 @@
1
+ """Spatial Memory MCP Server - Vector-based semantic memory for LLMs."""
2
+
3
+ __version__ = "1.6.1"
4
+ __author__ = "arman-tech"
5
+
6
+ # Re-export core components for convenience
7
+ # Adapters
8
+ from spatial_memory.adapters.lancedb_repository import LanceDBMemoryRepository
9
+ from spatial_memory.config import Settings, get_settings
10
+ from spatial_memory.core import (
11
+ ClusterInfo,
12
+ ClusteringError,
13
+ ConfigurationError,
14
+ # Core services
15
+ Database,
16
+ EmbeddingError,
17
+ EmbeddingService,
18
+ Filter,
19
+ FilterGroup,
20
+ FilterOperator,
21
+ JourneyStep,
22
+ # Models
23
+ Memory,
24
+ MemoryNotFoundError,
25
+ MemoryResult,
26
+ MemorySource,
27
+ NamespaceNotFoundError,
28
+ # Errors
29
+ SpatialMemoryError,
30
+ StorageError,
31
+ ValidationError,
32
+ VisualizationCluster,
33
+ VisualizationData,
34
+ VisualizationEdge,
35
+ VisualizationError,
36
+ VisualizationNode,
37
+ )
38
+
39
+ # Server
40
+ from spatial_memory.server import SpatialMemoryServer, create_server
41
+
42
+ # Services
43
+ from spatial_memory.services.memory import (
44
+ ForgetResult,
45
+ MemoryService,
46
+ NearbyResult,
47
+ RecallResult,
48
+ RememberBatchResult,
49
+ RememberResult,
50
+ )
51
+
52
+ __all__ = [
53
+ # Version info
54
+ "__version__",
55
+ "__author__",
56
+ # Configuration
57
+ "Settings",
58
+ "get_settings",
59
+ # Errors
60
+ "SpatialMemoryError",
61
+ "MemoryNotFoundError",
62
+ "NamespaceNotFoundError",
63
+ "EmbeddingError",
64
+ "StorageError",
65
+ "ValidationError",
66
+ "ConfigurationError",
67
+ "ClusteringError",
68
+ "VisualizationError",
69
+ # Models
70
+ "Memory",
71
+ "MemorySource",
72
+ "MemoryResult",
73
+ "ClusterInfo",
74
+ "JourneyStep",
75
+ "VisualizationNode",
76
+ "VisualizationEdge",
77
+ "VisualizationCluster",
78
+ "VisualizationData",
79
+ "Filter",
80
+ "FilterOperator",
81
+ "FilterGroup",
82
+ # Core services
83
+ "Database",
84
+ "EmbeddingService",
85
+ # Services
86
+ "MemoryService",
87
+ "RememberResult",
88
+ "RememberBatchResult",
89
+ "RecallResult",
90
+ "NearbyResult",
91
+ "ForgetResult",
92
+ # Adapters
93
+ "LanceDBMemoryRepository",
94
+ # Server
95
+ "SpatialMemoryServer",
96
+ "create_server",
97
+ ]
@@ -0,0 +1,270 @@
1
+ """Entry point for running the Spatial Memory MCP Server and CLI commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import asyncio
7
+ import logging
8
+ import sys
9
+ from typing import NoReturn
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ def run_server() -> None:
15
+ """Run the Spatial Memory MCP Server."""
16
+ from spatial_memory.server import main as server_main
17
+
18
+ asyncio.run(server_main())
19
+
20
+
21
+ def run_migrate(args: argparse.Namespace) -> int:
22
+ """Run database migrations.
23
+
24
+ Args:
25
+ args: Parsed command line arguments.
26
+
27
+ Returns:
28
+ Exit code (0 for success, 1 for error).
29
+ """
30
+ from spatial_memory.config import get_settings
31
+ from spatial_memory.core.database import Database
32
+ from spatial_memory.core.db_migrations import (
33
+ CURRENT_SCHEMA_VERSION,
34
+ MigrationManager,
35
+ )
36
+ from spatial_memory.core.embeddings import EmbeddingService
37
+
38
+ settings = get_settings()
39
+
40
+ # Set up logging based on verbosity
41
+ log_level = logging.DEBUG if args.verbose else logging.INFO
42
+ logging.basicConfig(
43
+ level=log_level,
44
+ format="%(levelname)s: %(message)s",
45
+ )
46
+
47
+ print(f"Spatial Memory Migration Tool")
48
+ print(f"Target schema version: {CURRENT_SCHEMA_VERSION}")
49
+ print(f"Database path: {settings.memory_path}")
50
+ print()
51
+
52
+ try:
53
+ # Create embedding service if needed for migrations
54
+ embeddings = None
55
+ if not args.dry_run:
56
+ # Only load embeddings for actual migrations (some may need re-embedding)
57
+ print("Loading embedding service...")
58
+ embeddings = EmbeddingService(
59
+ model_name=settings.embedding_model,
60
+ openai_api_key=settings.openai_api_key,
61
+ backend=settings.embedding_backend,
62
+ )
63
+
64
+ # Connect to database
65
+ print("Connecting to database...")
66
+ db = Database(
67
+ storage_path=settings.memory_path,
68
+ embedding_dim=embeddings.dimensions if embeddings else 384,
69
+ auto_create_indexes=settings.auto_create_indexes,
70
+ )
71
+ db.connect()
72
+
73
+ # Create migration manager
74
+ manager = MigrationManager(db, embeddings)
75
+ manager.register_builtin_migrations()
76
+
77
+ current_version = manager.get_current_version()
78
+ print(f"Current schema version: {current_version}")
79
+
80
+ if args.status:
81
+ # Just show status, don't run migrations
82
+ pending = manager.get_pending_migrations()
83
+ if pending:
84
+ print(f"\nPending migrations ({len(pending)}):")
85
+ for m in pending:
86
+ print(f" - {m.version}: {m.description}")
87
+ else:
88
+ print("\nNo pending migrations. Database is up to date.")
89
+
90
+ applied = manager.get_applied_migrations()
91
+ if applied:
92
+ print(f"\nApplied migrations ({len(applied)}):")
93
+ for m in applied:
94
+ print(f" - {m.version}: {m.description} (applied: {m.applied_at})")
95
+
96
+ db.close()
97
+ return 0
98
+
99
+ if args.rollback:
100
+ # Rollback to specified version
101
+ print(f"\nRolling back to version {args.rollback}...")
102
+ result = manager.rollback(args.rollback)
103
+
104
+ if result.errors:
105
+ print("\nRollback failed with errors:")
106
+ for error in result.errors:
107
+ print(f" - {error}")
108
+ db.close()
109
+ return 1
110
+
111
+ if result.migrations_applied:
112
+ print(f"\nRolled back migrations:")
113
+ for v in result.migrations_applied:
114
+ print(f" - {v}")
115
+ print(f"\nCurrent version: {result.current_version}")
116
+ else:
117
+ print("\nNo migrations to rollback.")
118
+
119
+ db.close()
120
+ return 0
121
+
122
+ # Run pending migrations
123
+ pending = manager.get_pending_migrations()
124
+ if not pending:
125
+ print("\nNo pending migrations. Database is up to date.")
126
+ db.close()
127
+ return 0
128
+
129
+ print(f"\nPending migrations ({len(pending)}):")
130
+ for m in pending:
131
+ print(f" - {m.version}: {m.description}")
132
+
133
+ if args.dry_run:
134
+ print("\n[DRY RUN] Would apply the above migrations.")
135
+ print("Run without --dry-run to apply.")
136
+ db.close()
137
+ return 0
138
+
139
+ # Confirm before applying
140
+ if not args.yes:
141
+ print()
142
+ response = input("Apply these migrations? [y/N] ").strip().lower()
143
+ if response not in ("y", "yes"):
144
+ print("Aborted.")
145
+ db.close()
146
+ return 0
147
+
148
+ print("\nApplying migrations...")
149
+ result = manager.run_pending(dry_run=False)
150
+
151
+ if result.errors:
152
+ print("\nMigration failed with errors:")
153
+ for error in result.errors:
154
+ print(f" - {error}")
155
+ print("\nSome migrations may have been applied. Check database state.")
156
+ db.close()
157
+ return 1
158
+
159
+ print(f"\nSuccessfully applied {len(result.migrations_applied)} migration(s):")
160
+ for v in result.migrations_applied:
161
+ print(f" - {v}")
162
+ print(f"\nCurrent version: {result.current_version}")
163
+
164
+ db.close()
165
+ return 0
166
+
167
+ except Exception as e:
168
+ logger.error(f"Migration failed: {e}", exc_info=args.verbose)
169
+ print(f"\nError: {e}")
170
+ return 1
171
+
172
+
173
+ def run_version() -> None:
174
+ """Print version information."""
175
+ from spatial_memory import __version__
176
+
177
+ print(f"spatial-memory {__version__}")
178
+
179
+
180
+ def run_instructions() -> None:
181
+ """Print the MCP server instructions that are auto-injected into Claude's context."""
182
+ from spatial_memory.server import SpatialMemoryServer
183
+
184
+ instructions = SpatialMemoryServer._get_server_instructions()
185
+ print(instructions)
186
+
187
+
188
+ def main() -> NoReturn:
189
+ """Main entry point with subcommand support."""
190
+ parser = argparse.ArgumentParser(
191
+ prog="spatial-memory",
192
+ description="Spatial Memory MCP Server and CLI tools",
193
+ )
194
+ parser.add_argument(
195
+ "--version", "-V",
196
+ action="store_true",
197
+ help="Show version and exit",
198
+ )
199
+
200
+ subparsers = parser.add_subparsers(
201
+ dest="command",
202
+ title="commands",
203
+ description="Available commands",
204
+ )
205
+
206
+ # Server command (default)
207
+ server_parser = subparsers.add_parser(
208
+ "serve",
209
+ help="Start the MCP server (default if no command given)",
210
+ )
211
+
212
+ # Instructions command
213
+ subparsers.add_parser(
214
+ "instructions",
215
+ help="Show the MCP instructions injected into Claude's context",
216
+ )
217
+
218
+ # Migrate command
219
+ migrate_parser = subparsers.add_parser(
220
+ "migrate",
221
+ help="Run database migrations",
222
+ )
223
+ migrate_parser.add_argument(
224
+ "--dry-run",
225
+ action="store_true",
226
+ help="Preview migrations without applying",
227
+ )
228
+ migrate_parser.add_argument(
229
+ "--status",
230
+ action="store_true",
231
+ help="Show migration status and exit",
232
+ )
233
+ migrate_parser.add_argument(
234
+ "--rollback",
235
+ metavar="VERSION",
236
+ help="Rollback to specified version (e.g., 1.0.0)",
237
+ )
238
+ migrate_parser.add_argument(
239
+ "-y", "--yes",
240
+ action="store_true",
241
+ help="Skip confirmation prompt",
242
+ )
243
+ migrate_parser.add_argument(
244
+ "-v", "--verbose",
245
+ action="store_true",
246
+ help="Enable verbose output",
247
+ )
248
+
249
+ args = parser.parse_args()
250
+
251
+ if args.version:
252
+ run_version()
253
+ sys.exit(0)
254
+
255
+ if args.command == "instructions":
256
+ run_instructions()
257
+ sys.exit(0)
258
+ elif args.command == "migrate":
259
+ sys.exit(run_migrate(args))
260
+ elif args.command == "serve" or args.command is None:
261
+ # Default to running the server
262
+ run_server()
263
+ sys.exit(0)
264
+ else:
265
+ parser.print_help()
266
+ sys.exit(1)
267
+
268
+
269
+ if __name__ == "__main__":
270
+ main()
@@ -0,0 +1,7 @@
1
+ """Infrastructure adapters for Spatial Memory MCP Server."""
2
+
3
+ from spatial_memory.adapters.lancedb_repository import LanceDBMemoryRepository
4
+
5
+ __all__ = [
6
+ "LanceDBMemoryRepository",
7
+ ]