htm 0.0.14 → 0.0.17

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/CHANGELOG.md +100 -0
  4. data/README.md +107 -1412
  5. data/bin/htm_mcp +31 -0
  6. data/config/database.yml +7 -4
  7. data/db/migrate/00003_create_file_sources.rb +5 -0
  8. data/db/migrate/00004_create_nodes.rb +17 -0
  9. data/db/migrate/00005_create_tags.rb +7 -0
  10. data/db/migrate/00006_create_node_tags.rb +2 -0
  11. data/db/migrate/00007_create_robot_nodes.rb +7 -0
  12. data/db/schema.sql +41 -29
  13. data/docs/api/yard/HTM/Configuration.md +54 -0
  14. data/docs/api/yard/HTM/Database.md +13 -10
  15. data/docs/api/yard/HTM/EmbeddingService.md +5 -1
  16. data/docs/api/yard/HTM/LongTermMemory.md +18 -277
  17. data/docs/api/yard/HTM/PropositionError.md +18 -0
  18. data/docs/api/yard/HTM/PropositionService.md +66 -0
  19. data/docs/api/yard/HTM/QueryCache.md +88 -0
  20. data/docs/api/yard/HTM/RobotGroup.md +481 -0
  21. data/docs/api/yard/HTM/SqlBuilder.md +108 -0
  22. data/docs/api/yard/HTM/TagService.md +4 -0
  23. data/docs/api/yard/HTM/Telemetry/NullInstrument.md +13 -0
  24. data/docs/api/yard/HTM/Telemetry/NullMeter.md +15 -0
  25. data/docs/api/yard/HTM/Telemetry.md +109 -0
  26. data/docs/api/yard/HTM/WorkingMemoryChannel.md +176 -0
  27. data/docs/api/yard/HTM.md +11 -23
  28. data/docs/api/yard/index.csv +102 -25
  29. data/docs/api/yard-reference.md +8 -0
  30. data/docs/assets/images/multi-provider-failover.svg +51 -0
  31. data/docs/assets/images/robot-group-architecture.svg +65 -0
  32. data/docs/database/README.md +3 -3
  33. data/docs/database/public.file_sources.svg +29 -21
  34. data/docs/database/public.node_tags.md +2 -0
  35. data/docs/database/public.node_tags.svg +53 -41
  36. data/docs/database/public.nodes.md +2 -0
  37. data/docs/database/public.nodes.svg +52 -40
  38. data/docs/database/public.robot_nodes.md +2 -0
  39. data/docs/database/public.robot_nodes.svg +30 -22
  40. data/docs/database/public.robots.svg +16 -12
  41. data/docs/database/public.tags.md +3 -0
  42. data/docs/database/public.tags.svg +41 -33
  43. data/docs/database/schema.json +66 -0
  44. data/docs/database/schema.svg +60 -48
  45. data/docs/development/index.md +13 -0
  46. data/docs/development/rake-tasks.md +1068 -0
  47. data/docs/getting-started/installation.md +31 -11
  48. data/docs/getting-started/quick-start.md +144 -155
  49. data/docs/guides/adding-memories.md +2 -3
  50. data/docs/guides/context-assembly.md +185 -184
  51. data/docs/guides/getting-started.md +154 -148
  52. data/docs/guides/index.md +7 -0
  53. data/docs/guides/long-term-memory.md +60 -92
  54. data/docs/guides/mcp-server.md +1052 -0
  55. data/docs/guides/multi-robot.md +249 -345
  56. data/docs/guides/recalling-memories.md +153 -163
  57. data/docs/guides/robot-groups.md +604 -0
  58. data/docs/guides/search-strategies.md +61 -58
  59. data/docs/guides/working-memory.md +103 -136
  60. data/docs/index.md +30 -26
  61. data/docs/multi_framework_support.md +2 -2
  62. data/examples/mcp_client.rb +2 -2
  63. data/examples/rails_app/.gitignore +2 -0
  64. data/examples/rails_app/Gemfile +22 -0
  65. data/examples/rails_app/Gemfile.lock +438 -0
  66. data/examples/rails_app/Procfile.dev +1 -0
  67. data/examples/rails_app/README.md +98 -0
  68. data/examples/rails_app/Rakefile +5 -0
  69. data/examples/rails_app/app/assets/stylesheets/application.css +83 -0
  70. data/examples/rails_app/app/assets/stylesheets/inter-font.css +6 -0
  71. data/examples/rails_app/app/controllers/application_controller.rb +19 -0
  72. data/examples/rails_app/app/controllers/dashboard_controller.rb +27 -0
  73. data/examples/rails_app/app/controllers/files_controller.rb +205 -0
  74. data/examples/rails_app/app/controllers/memories_controller.rb +102 -0
  75. data/examples/rails_app/app/controllers/robots_controller.rb +44 -0
  76. data/examples/rails_app/app/controllers/search_controller.rb +46 -0
  77. data/examples/rails_app/app/controllers/tags_controller.rb +30 -0
  78. data/examples/rails_app/app/javascript/application.js +4 -0
  79. data/examples/rails_app/app/javascript/controllers/application.js +9 -0
  80. data/examples/rails_app/app/javascript/controllers/index.js +6 -0
  81. data/examples/rails_app/app/views/dashboard/index.html.erb +123 -0
  82. data/examples/rails_app/app/views/files/index.html.erb +108 -0
  83. data/examples/rails_app/app/views/files/new.html.erb +321 -0
  84. data/examples/rails_app/app/views/files/show.html.erb +130 -0
  85. data/examples/rails_app/app/views/layouts/application.html.erb +124 -0
  86. data/examples/rails_app/app/views/memories/_memory_card.html.erb +51 -0
  87. data/examples/rails_app/app/views/memories/deleted.html.erb +62 -0
  88. data/examples/rails_app/app/views/memories/edit.html.erb +35 -0
  89. data/examples/rails_app/app/views/memories/index.html.erb +81 -0
  90. data/examples/rails_app/app/views/memories/new.html.erb +71 -0
  91. data/examples/rails_app/app/views/memories/show.html.erb +126 -0
  92. data/examples/rails_app/app/views/robots/index.html.erb +106 -0
  93. data/examples/rails_app/app/views/robots/new.html.erb +36 -0
  94. data/examples/rails_app/app/views/robots/show.html.erb +79 -0
  95. data/examples/rails_app/app/views/search/index.html.erb +184 -0
  96. data/examples/rails_app/app/views/shared/_navbar.html.erb +52 -0
  97. data/examples/rails_app/app/views/shared/_stat_card.html.erb +52 -0
  98. data/examples/rails_app/app/views/tags/index.html.erb +131 -0
  99. data/examples/rails_app/app/views/tags/show.html.erb +67 -0
  100. data/examples/rails_app/bin/dev +8 -0
  101. data/examples/rails_app/bin/rails +4 -0
  102. data/examples/rails_app/bin/rake +4 -0
  103. data/examples/rails_app/config/application.rb +33 -0
  104. data/examples/rails_app/config/boot.rb +5 -0
  105. data/examples/rails_app/config/database.yml +15 -0
  106. data/examples/rails_app/config/environment.rb +5 -0
  107. data/examples/rails_app/config/importmap.rb +7 -0
  108. data/examples/rails_app/config/routes.rb +38 -0
  109. data/examples/rails_app/config/tailwind.config.js +35 -0
  110. data/examples/rails_app/config.ru +5 -0
  111. data/examples/rails_app/log/.keep +0 -0
  112. data/examples/rails_app/tmp/local_secret.txt +1 -0
  113. data/examples/robot_groups/robot_worker.rb +1 -2
  114. data/examples/robot_groups/same_process.rb +1 -4
  115. data/lib/htm/active_record_config.rb +2 -5
  116. data/lib/htm/configuration.rb +35 -2
  117. data/lib/htm/database.rb +3 -6
  118. data/lib/htm/mcp/cli.rb +333 -0
  119. data/lib/htm/mcp/group_tools.rb +476 -0
  120. data/lib/htm/mcp/resources.rb +89 -0
  121. data/lib/htm/mcp/server.rb +98 -0
  122. data/lib/htm/mcp/tools.rb +488 -0
  123. data/lib/htm/models/file_source.rb +5 -3
  124. data/lib/htm/railtie.rb +0 -4
  125. data/lib/htm/robot_group.rb +721 -0
  126. data/lib/htm/tasks.rb +7 -4
  127. data/lib/htm/version.rb +1 -1
  128. data/lib/htm/working_memory_channel.rb +250 -0
  129. data/lib/htm.rb +2 -0
  130. data/lib/tasks/htm.rake +6 -9
  131. data/mkdocs.yml +2 -0
  132. metadata +75 -11
  133. data/bin/htm_mcp.rb +0 -621
  134. data/db/migrate/00009_add_working_memory_to_robot_nodes.rb +0 -12
  135. data/db/migrate/00010_add_soft_delete_to_associations.rb +0 -29
  136. data/db/migrate/00011_add_performance_indexes.rb +0 -21
  137. data/db/migrate/00012_add_tags_trigram_index.rb +0 -18
  138. data/db/migrate/00013_enable_lz4_compression.rb +0 -43
  139. data/examples/robot_groups/lib/robot_group.rb +0 -419
  140. data/examples/robot_groups/lib/working_memory_channel.rb +0 -140
@@ -0,0 +1,1052 @@
1
+ # MCP Server Guide
2
+
3
+ HTM includes a Model Context Protocol (MCP) server that exposes memory capabilities to AI assistants. This enables tools like Claude Desktop, Claude Code, and AIA to store, recall, and manage memories through a standardized protocol.
4
+
5
+ ## Overview
6
+
7
+ The MCP server (`bin/htm_mcp`) uses [FastMCP](https://github.com/yjacket/fast-mcp) to expose HTM's memory operations as MCP tools and resources. Any MCP-compatible client can connect to the server and use HTM's memory capabilities.
8
+
9
+ ### Key Features
10
+
11
+ - **Session-based robot identity**: Each client session has its own robot identity
12
+ - **Full HTM API access**: Remember, recall, forget, restore, and manage tags
13
+ - **Session restore**: Restore previous session context from working memory
14
+ - **Fuzzy search**: Typo-tolerant tag and topic search
15
+ - **Resource access**: Query statistics, tag hierarchy, and recent memories
16
+ - **Robot Groups (High-Availability)**: Coordinate multiple robots with shared working memory, failover, and real-time sync
17
+
18
+ ## Prerequisites
19
+
20
+ Before using the MCP server, ensure you have:
21
+
22
+ 1. **HTM installed and configured**
23
+ ```bash
24
+ gem install htm
25
+ ```
26
+
27
+ 2. **PostgreSQL database set up**
28
+ ```bash
29
+ export HTM_DBURL="postgresql://user@localhost:5432/htm_development"
30
+ htm_mcp setup
31
+ ```
32
+
33
+ 3. **Ollama running** (for embeddings and tag extraction)
34
+ ```bash
35
+ ollama serve
36
+ ollama pull nomic-embed-text
37
+ ollama pull llama3
38
+ ```
39
+
40
+ ## Starting the Server
41
+
42
+ The MCP server uses STDIO transport which is compatible with most MCP clients. When you do a `gem install htm`, the `htm_mcp` executable is placed on your $PATH.
43
+
44
+ ```bash
45
+ htm_mcp
46
+ ```
47
+
48
+ The server logs to STDERR to avoid corrupting the JSON-RPC protocol on STDOUT.
49
+
50
+ ## CLI Commands
51
+
52
+ The `htm_mcp` executable includes management commands for database setup and diagnostics:
53
+
54
+ | Command | Description |
55
+ |---------|-------------|
56
+ | `htm_mcp` | Start the MCP server (default) |
57
+ | `htm_mcp server` | Start the MCP server (explicit) |
58
+ | `htm_mcp setup` | Initialize database schema and run migrations |
59
+ | `htm_mcp init` | Alias for setup |
60
+ | `htm_mcp verify` | Verify database connection, extensions, and migration status |
61
+ | `htm_mcp stats` | Show memory statistics (nodes, tags, robots, database size) |
62
+ | `htm_mcp version` | Show HTM version |
63
+ | `htm_mcp help` | Show help with all environment variables |
64
+
65
+ ### First-Time Setup
66
+
67
+ ```bash
68
+ # Set your database URL
69
+ export HTM_DBURL="postgresql://user@localhost:5432/htm_development"
70
+
71
+ # Initialize the database
72
+ htm_mcp setup
73
+
74
+ # Verify everything is working
75
+ htm_mcp verify
76
+
77
+ # Check memory statistics
78
+ htm_mcp stats
79
+ ```
80
+
81
+ ### Migration Status
82
+
83
+ The `verify` command shows migration status with `+` (applied) and `-` (pending) indicators:
84
+
85
+ ```
86
+ Migration Status
87
+ --------------------------------------------------------------------------------
88
+ + 20250101000001_create_schema_migrations
89
+ + 20250101000002_create_robots
90
+ + 20250101000003_create_nodes
91
+ - 20250612000001_add_new_feature
92
+ --------------------------------------------------------------------------------
93
+ 3 applied, 1 pending
94
+ ```
95
+
96
+ ## Tools Reference
97
+
98
+ ### SetRobotTool
99
+
100
+ Set the robot identity for this session. **Call this first** to establish your robot name.
101
+
102
+ **Parameters:**
103
+ - `name` (String, required): The robot name (will be created if it doesn't exist)
104
+
105
+ **Returns:**
106
+ ```json
107
+ {
108
+ "success": true,
109
+ "robot_id": 5,
110
+ "robot_name": "my-assistant",
111
+ "node_count": 12,
112
+ "message": "Robot 'my-assistant' is now active for this session"
113
+ }
114
+ ```
115
+
116
+ **Example usage:**
117
+ ```
118
+ Set robot name to "research-bot"
119
+ ```
120
+
121
+ ---
122
+
123
+ ### GetRobotTool
124
+
125
+ Get information about the current robot for this session.
126
+
127
+ **Parameters:** None
128
+
129
+ **Returns:**
130
+ ```json
131
+ {
132
+ "success": true,
133
+ "robot_id": 5,
134
+ "robot_name": "my-assistant",
135
+ "initialized": true,
136
+ "memory_summary": {
137
+ "total_nodes": 150,
138
+ "working_memory_nodes": 25
139
+ }
140
+ }
141
+ ```
142
+
143
+ ---
144
+
145
+ ### GetWorkingMemoryTool
146
+
147
+ Get all working memory contents for the current robot. Use this to restore a previous session.
148
+
149
+ **Parameters:** None
150
+
151
+ **Returns:**
152
+ ```json
153
+ {
154
+ "success": true,
155
+ "robot_id": 5,
156
+ "robot_name": "my-assistant",
157
+ "count": 3,
158
+ "working_memory": [
159
+ {
160
+ "id": 123,
161
+ "content": "User prefers dark mode",
162
+ "tags": ["user:preference", "ui"],
163
+ "remember_count": 5,
164
+ "last_remembered_at": "2024-01-15T10:30:00Z",
165
+ "created_at": "2024-01-10T08:00:00Z"
166
+ }
167
+ ]
168
+ }
169
+ ```
170
+
171
+ ---
172
+
173
+ ### RememberTool
174
+
175
+ Store information in HTM long-term memory with optional tags.
176
+
177
+ **Parameters:**
178
+ - `content` (String, required): The content to remember
179
+ - `tags` (Array<String>, optional): Tags for categorization (e.g., `["database:postgresql", "config"]`)
180
+ - `metadata` (Hash, optional): Key-value metadata pairs
181
+
182
+ **Returns:**
183
+ ```json
184
+ {
185
+ "success": true,
186
+ "node_id": 456,
187
+ "robot_id": 5,
188
+ "robot_name": "my-assistant",
189
+ "content": "PostgreSQL uses pgvector for similarity search",
190
+ "tags": ["database:postgresql", "vector-search"],
191
+ "created_at": "2024-01-15T14:30:00Z"
192
+ }
193
+ ```
194
+
195
+ **Example usage:**
196
+ ```
197
+ Remember that the user prefers Ruby over Python for scripting tasks
198
+ ```
199
+
200
+ ---
201
+
202
+ ### RecallTool
203
+
204
+ Search and retrieve memories from HTM using semantic, full-text, or hybrid search.
205
+
206
+ **Parameters:**
207
+ - `query` (String, required): Search query (natural language or keywords)
208
+ - `limit` (Integer, optional): Maximum results (default: 10)
209
+ - `strategy` (String, optional): Search strategy - `"vector"`, `"fulltext"`, or `"hybrid"` (default: `"hybrid"`)
210
+ - `timeframe` (String, optional): Time filter - `"today"`, `"this week"`, `"this month"`, or ISO8601 date range
211
+
212
+ **Returns:**
213
+ ```json
214
+ {
215
+ "success": true,
216
+ "query": "database decisions",
217
+ "strategy": "hybrid",
218
+ "robot_name": "my-assistant",
219
+ "count": 3,
220
+ "results": [
221
+ {
222
+ "id": 123,
223
+ "content": "Decided to use PostgreSQL for vector search",
224
+ "tags": ["database:postgresql", "decision"],
225
+ "created_at": "2024-01-10T08:00:00Z",
226
+ "score": 0.89
227
+ }
228
+ ]
229
+ }
230
+ ```
231
+
232
+ **Example usage:**
233
+ ```
234
+ Recall what we discussed about database architecture last week
235
+ ```
236
+
237
+ ---
238
+
239
+ ### ForgetTool
240
+
241
+ Soft-delete a memory from HTM (can be restored later).
242
+
243
+ **Parameters:**
244
+ - `node_id` (Integer, required): The ID of the node to forget
245
+
246
+ **Returns:**
247
+ ```json
248
+ {
249
+ "success": true,
250
+ "node_id": 123,
251
+ "robot_name": "my-assistant",
252
+ "message": "Memory soft-deleted. Use restore to recover."
253
+ }
254
+ ```
255
+
256
+ ---
257
+
258
+ ### RestoreTool
259
+
260
+ Restore a soft-deleted memory.
261
+
262
+ **Parameters:**
263
+ - `node_id` (Integer, required): The ID of the node to restore
264
+
265
+ **Returns:**
266
+ ```json
267
+ {
268
+ "success": true,
269
+ "node_id": 123,
270
+ "robot_name": "my-assistant",
271
+ "message": "Memory restored successfully"
272
+ }
273
+ ```
274
+
275
+ ---
276
+
277
+ ### ListTagsTool
278
+
279
+ List all tags in HTM, optionally filtered by prefix.
280
+
281
+ **Parameters:**
282
+ - `prefix` (String, optional): Filter tags by prefix (e.g., `"database"` returns `"database:postgresql"`, etc.)
283
+
284
+ **Returns:**
285
+ ```json
286
+ {
287
+ "success": true,
288
+ "prefix": "database",
289
+ "count": 5,
290
+ "tags": [
291
+ { "name": "database", "node_count": 15 },
292
+ { "name": "database:postgresql", "node_count": 10 },
293
+ { "name": "database:postgresql:extensions", "node_count": 3 }
294
+ ]
295
+ }
296
+ ```
297
+
298
+ ---
299
+
300
+ ### SearchTagsTool
301
+
302
+ Search for tags using fuzzy matching (typo-tolerant). Use this when you're unsure of exact tag names.
303
+
304
+ **Parameters:**
305
+ - `query` (String, required): Search query (can contain typos, e.g., `"postgrsql"` finds `"database:postgresql"`)
306
+ - `limit` (Integer, optional): Maximum results (default: 20)
307
+ - `min_similarity` (Float, optional): Minimum similarity threshold 0.0-1.0 (default: 0.3, lower = more fuzzy)
308
+
309
+ **Returns:**
310
+ ```json
311
+ {
312
+ "success": true,
313
+ "query": "postgrsql",
314
+ "min_similarity": 0.3,
315
+ "count": 2,
316
+ "tags": [
317
+ { "name": "database:postgresql", "similarity": 0.857, "node_count": 10 },
318
+ { "name": "database:postgresql:extensions", "similarity": 0.714, "node_count": 3 }
319
+ ]
320
+ }
321
+ ```
322
+
323
+ ---
324
+
325
+ ### FindByTopicTool
326
+
327
+ Find memory nodes by topic/tag with optional fuzzy matching for typo tolerance.
328
+
329
+ **Parameters:**
330
+ - `topic` (String, required): Topic or tag to search for
331
+ - `fuzzy` (Boolean, optional): Enable fuzzy matching for typo tolerance (default: false)
332
+ - `exact` (Boolean, optional): Require exact tag match (default: false, uses prefix matching)
333
+ - `limit` (Integer, optional): Maximum results (default: 20)
334
+ - `min_similarity` (Float, optional): Minimum similarity for fuzzy mode (default: 0.3)
335
+
336
+ **Returns:**
337
+ ```json
338
+ {
339
+ "success": true,
340
+ "topic": "database:postgresql",
341
+ "fuzzy": false,
342
+ "exact": false,
343
+ "count": 5,
344
+ "results": [
345
+ {
346
+ "id": 123,
347
+ "content": "PostgreSQL uses pgvector for similarity search...",
348
+ "tags": ["database:postgresql", "vector-search"],
349
+ "created_at": "2024-01-10T08:00:00Z"
350
+ }
351
+ ]
352
+ }
353
+ ```
354
+
355
+ ---
356
+
357
+ ### StatsTool
358
+
359
+ Get statistics about HTM memory usage.
360
+
361
+ **Parameters:** None
362
+
363
+ **Returns:**
364
+ ```json
365
+ {
366
+ "success": true,
367
+ "current_robot": {
368
+ "name": "my-assistant",
369
+ "id": 5,
370
+ "memory_summary": { "total_nodes": 150, "working_memory_nodes": 25 }
371
+ },
372
+ "statistics": {
373
+ "nodes": {
374
+ "active": 500,
375
+ "deleted": 20,
376
+ "with_embeddings": 495,
377
+ "with_tags": 480
378
+ },
379
+ "tags": { "total": 75 },
380
+ "robots": { "total": 3 }
381
+ }
382
+ }
383
+ ```
384
+
385
+ ## Robot Group Tools
386
+
387
+ Robot Groups enable high-availability configurations with multiple robots sharing working memory. Groups support active/passive roles, automatic failover, and real-time synchronization via PostgreSQL LISTEN/NOTIFY.
388
+
389
+ ### CreateGroupTool
390
+
391
+ Create a new robot group with shared working memory.
392
+
393
+ **Parameters:**
394
+ - `name` (String, required): Unique name for the group
395
+ - `sync_interval` (Integer, optional): Sync interval in seconds (default: 30)
396
+ - `max_members` (Integer, optional): Maximum group members (default: 10)
397
+ - `token_budget` (Integer, optional): Shared working memory token limit (default: 4000)
398
+
399
+ **Returns:**
400
+ ```json
401
+ {
402
+ "success": true,
403
+ "group_name": "research-team",
404
+ "sync_interval": 30,
405
+ "max_members": 10,
406
+ "token_budget": 4000,
407
+ "message": "Robot group 'research-team' created successfully"
408
+ }
409
+ ```
410
+
411
+ ---
412
+
413
+ ### ListGroupsTool
414
+
415
+ List all active robot groups in the current MCP session.
416
+
417
+ **Parameters:** None
418
+
419
+ **Returns:**
420
+ ```json
421
+ {
422
+ "success": true,
423
+ "count": 2,
424
+ "groups": [
425
+ {
426
+ "name": "research-team",
427
+ "member_count": 3,
428
+ "active_robot": "researcher-1"
429
+ },
430
+ {
431
+ "name": "support-team",
432
+ "member_count": 2,
433
+ "active_robot": "support-bot"
434
+ }
435
+ ]
436
+ }
437
+ ```
438
+
439
+ ---
440
+
441
+ ### GetGroupStatusTool
442
+
443
+ Get detailed status of a robot group.
444
+
445
+ **Parameters:**
446
+ - `name` (String, required): The group name
447
+
448
+ **Returns:**
449
+ ```json
450
+ {
451
+ "success": true,
452
+ "group_name": "research-team",
453
+ "status": {
454
+ "active_robot": "researcher-1",
455
+ "member_count": 3,
456
+ "members": [
457
+ { "name": "researcher-1", "role": "active", "last_seen": "2024-01-15T10:30:00Z" },
458
+ { "name": "researcher-2", "role": "passive", "last_seen": "2024-01-15T10:29:55Z" },
459
+ { "name": "researcher-3", "role": "passive", "last_seen": "2024-01-15T10:29:50Z" }
460
+ ],
461
+ "working_memory_tokens": 2500,
462
+ "token_budget": 4000,
463
+ "sync_interval": 30
464
+ }
465
+ }
466
+ ```
467
+
468
+ ---
469
+
470
+ ### JoinGroupTool
471
+
472
+ Add a robot to an existing group.
473
+
474
+ **Parameters:**
475
+ - `group_name` (String, required): The group to join
476
+ - `robot_name` (String, required): The robot name to add
477
+ - `role` (String, optional): `"active"` or `"passive"` (default: `"passive"`)
478
+
479
+ **Returns:**
480
+ ```json
481
+ {
482
+ "success": true,
483
+ "group_name": "research-team",
484
+ "robot_name": "researcher-4",
485
+ "role": "passive",
486
+ "message": "Robot 'researcher-4' joined group 'research-team' as passive"
487
+ }
488
+ ```
489
+
490
+ ---
491
+
492
+ ### LeaveGroupTool
493
+
494
+ Remove a robot from a group.
495
+
496
+ **Parameters:**
497
+ - `group_name` (String, required): The group to leave
498
+ - `robot_name` (String, required): The robot to remove
499
+
500
+ **Returns:**
501
+ ```json
502
+ {
503
+ "success": true,
504
+ "group_name": "research-team",
505
+ "robot_name": "researcher-4",
506
+ "message": "Robot 'researcher-4' left group 'research-team'"
507
+ }
508
+ ```
509
+
510
+ ---
511
+
512
+ ### GroupRememberTool
513
+
514
+ Store memory shared across all group members. Only the active robot can write to group memory.
515
+
516
+ **Parameters:**
517
+ - `group_name` (String, required): The target group
518
+ - `content` (String, required): The content to remember
519
+ - `tags` (Array<String>, optional): Tags for categorization
520
+ - `metadata` (Hash, optional): Key-value metadata
521
+
522
+ **Returns:**
523
+ ```json
524
+ {
525
+ "success": true,
526
+ "group_name": "research-team",
527
+ "node_id": 789,
528
+ "content": "Found relevant paper on embeddings",
529
+ "tags": ["research:papers", "ai:embeddings"],
530
+ "message": "Memory stored in group working memory"
531
+ }
532
+ ```
533
+
534
+ ---
535
+
536
+ ### GroupRecallTool
537
+
538
+ Recall memories from a group's shared context.
539
+
540
+ **Parameters:**
541
+ - `group_name` (String, required): The target group
542
+ - `query` (String, required): Search query
543
+ - `limit` (Integer, optional): Maximum results (default: 10)
544
+ - `strategy` (String, optional): `"vector"`, `"fulltext"`, or `"hybrid"` (default: `"hybrid"`)
545
+
546
+ **Returns:**
547
+ ```json
548
+ {
549
+ "success": true,
550
+ "group_name": "research-team",
551
+ "query": "embeddings",
552
+ "count": 3,
553
+ "results": [
554
+ {
555
+ "id": 789,
556
+ "content": "Found relevant paper on embeddings",
557
+ "tags": ["research:papers", "ai:embeddings"],
558
+ "score": 0.92
559
+ }
560
+ ]
561
+ }
562
+ ```
563
+
564
+ ---
565
+
566
+ ### GetGroupWorkingMemoryTool
567
+
568
+ Get a group's working memory contents.
569
+
570
+ **Parameters:**
571
+ - `group_name` (String, required): The target group
572
+
573
+ **Returns:**
574
+ ```json
575
+ {
576
+ "success": true,
577
+ "group_name": "research-team",
578
+ "token_usage": 2500,
579
+ "token_budget": 4000,
580
+ "count": 15,
581
+ "working_memory": [
582
+ {
583
+ "id": 789,
584
+ "content": "Found relevant paper on embeddings",
585
+ "tags": ["research:papers"],
586
+ "added_at": "2024-01-15T10:30:00Z"
587
+ }
588
+ ]
589
+ }
590
+ ```
591
+
592
+ ---
593
+
594
+ ### PromoteRobotTool
595
+
596
+ Promote a passive robot to active role. The current active robot becomes passive.
597
+
598
+ **Parameters:**
599
+ - `group_name` (String, required): The target group
600
+ - `robot_name` (String, required): The robot to promote
601
+
602
+ **Returns:**
603
+ ```json
604
+ {
605
+ "success": true,
606
+ "group_name": "research-team",
607
+ "promoted_robot": "researcher-2",
608
+ "previous_active": "researcher-1",
609
+ "message": "Robot 'researcher-2' is now active. 'researcher-1' is now passive."
610
+ }
611
+ ```
612
+
613
+ ---
614
+
615
+ ### FailoverTool
616
+
617
+ Trigger failover to the next available robot in the group.
618
+
619
+ **Parameters:**
620
+ - `group_name` (String, required): The target group
621
+
622
+ **Returns:**
623
+ ```json
624
+ {
625
+ "success": true,
626
+ "group_name": "research-team",
627
+ "new_active": "researcher-2",
628
+ "previous_active": "researcher-1",
629
+ "message": "Failover complete. 'researcher-2' is now active."
630
+ }
631
+ ```
632
+
633
+ ---
634
+
635
+ ### SyncGroupTool
636
+
637
+ Manually synchronize group state across all members.
638
+
639
+ **Parameters:**
640
+ - `group_name` (String, required): The target group
641
+
642
+ **Returns:**
643
+ ```json
644
+ {
645
+ "success": true,
646
+ "group_name": "research-team",
647
+ "synced_members": 3,
648
+ "message": "Group state synchronized across 3 members"
649
+ }
650
+ ```
651
+
652
+ ---
653
+
654
+ ### ShutdownGroupTool
655
+
656
+ Gracefully shutdown a robot group, removing all members.
657
+
658
+ **Parameters:**
659
+ - `group_name` (String, required): The group to shutdown
660
+
661
+ **Returns:**
662
+ ```json
663
+ {
664
+ "success": true,
665
+ "group_name": "research-team",
666
+ "message": "Robot group 'research-team' has been shut down"
667
+ }
668
+ ```
669
+
670
+ ## Resources Reference
671
+
672
+ ### htm://statistics
673
+
674
+ Memory statistics as JSON.
675
+
676
+ ```json
677
+ {
678
+ "total_nodes": 500,
679
+ "total_tags": 75,
680
+ "total_robots": 3,
681
+ "current_robot": "my-assistant",
682
+ "robot_id": 5,
683
+ "robot_initialized": true,
684
+ "embedding_provider": "ollama",
685
+ "embedding_model": "nomic-embed-text"
686
+ }
687
+ ```
688
+
689
+ ### htm://tags/hierarchy
690
+
691
+ Tag hierarchy as a text tree:
692
+
693
+ ```
694
+ database
695
+ ├── postgresql
696
+ │ ├── extensions
697
+ │ └── performance
698
+ └── mysql
699
+ ai
700
+ ├── llm
701
+ │ ├── embeddings
702
+ │ └── prompts
703
+ └── rag
704
+ ```
705
+
706
+ ### htm://memories/recent
707
+
708
+ Last 20 memories as JSON array.
709
+
710
+ ### htm://groups
711
+
712
+ Active robot groups and their status:
713
+
714
+ ```json
715
+ {
716
+ "count": 2,
717
+ "groups": [
718
+ {
719
+ "name": "research-team",
720
+ "member_count": 3,
721
+ "active_robot": "researcher-1",
722
+ "token_usage": 2500,
723
+ "token_budget": 4000
724
+ },
725
+ {
726
+ "name": "support-team",
727
+ "member_count": 2,
728
+ "active_robot": "support-bot",
729
+ "token_usage": 1200,
730
+ "token_budget": 4000
731
+ }
732
+ ]
733
+ }
734
+ ```
735
+
736
+ ## Client Configuration
737
+
738
+ ### Claude Desktop
739
+
740
+ Add to `~/.config/claude/claude_desktop_config.json` (Linux/macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
741
+
742
+ ```json
743
+ {
744
+ "mcpServers": {
745
+ "htm-memory": {
746
+ "command": "htm_mcp",
747
+ "env": {
748
+ "HTM_DBURL": "postgresql://user@localhost:5432/htm_development"
749
+ }
750
+ }
751
+ }
752
+ }
753
+ ```
754
+
755
+ If `htm_mcp` is not in your PATH, use the absolute path:
756
+
757
+ ```json
758
+ {
759
+ "mcpServers": {
760
+ "htm-memory": {
761
+ "command": "/path/to/htm_mcp",
762
+ "env": {
763
+ "HTM_DBURL": "postgresql://user@localhost:5432/htm_development"
764
+ }
765
+ }
766
+ }
767
+ }
768
+ ```
769
+
770
+ After adding the configuration:
771
+ 1. Restart Claude Desktop
772
+ 2. Look for the HTM tools in the tools menu (hammer icon)
773
+ 3. Start a conversation and ask Claude to remember something
774
+
775
+ ### Claude Code
776
+
777
+ Add to `~/.claude/claude_code_config.json`:
778
+
779
+ ```json
780
+ {
781
+ "mcpServers": {
782
+ "htm-memory": {
783
+ "command": "htm_mcp",
784
+ "env": {
785
+ "HTM_DBURL": "postgresql://user@localhost:5432/htm_development"
786
+ }
787
+ }
788
+ }
789
+ }
790
+ ```
791
+
792
+ After adding the configuration:
793
+ 1. Restart Claude Code or run `/mcp` to refresh
794
+ 2. The HTM tools will appear with the `mcp__htm-memory__` prefix
795
+ 3. Claude Code will automatically use HTM tools when appropriate
796
+
797
+ **Example prompts for Claude Code:**
798
+ ```
799
+ Remember that this project uses PostgreSQL with pgvector for similarity search
800
+
801
+ Recall what architecture decisions we made for this project
802
+
803
+ What tags do we have related to database configuration?
804
+ ```
805
+
806
+ ### AIA (AI Assistant)
807
+
808
+ Add to `~/.config/aia/config.yml`:
809
+
810
+ ```yaml
811
+ mcp_servers:
812
+ htm-memory:
813
+ command: htm_mcp
814
+ env:
815
+ HTM_DBURL: postgresql://user@localhost:5432/htm_development
816
+ ```
817
+
818
+ For project-specific configuration, add to `.aia/config.yml` in your project root:
819
+
820
+ ```yaml
821
+ mcp_servers:
822
+ htm-memory:
823
+ command: htm_mcp
824
+ env:
825
+ HTM_DBURL: postgresql://user@localhost:5432/my_project_htm
826
+ ```
827
+
828
+ ## Usage Examples
829
+
830
+ ### Basic Workflow
831
+
832
+ 1. **Set your robot identity** (do this first in each session):
833
+ ```
834
+ Set my robot name to "project-assistant"
835
+ ```
836
+
837
+ 2. **Store information as you work**:
838
+ ```
839
+ Remember that we decided to use Redis for caching with a 1-hour TTL
840
+ ```
841
+
842
+ 3. **Recall relevant context**:
843
+ ```
844
+ What caching decisions have we made?
845
+ ```
846
+
847
+ 4. **Browse by topic**:
848
+ ```
849
+ Show me all memories tagged with "architecture"
850
+ ```
851
+
852
+ ### Session Restoration
853
+
854
+ When starting a new session, you can restore context from a previous session:
855
+
856
+ 1. **Set robot identity** (same name as before):
857
+ ```
858
+ Set robot name to "project-assistant"
859
+ ```
860
+
861
+ 2. **Get working memory**:
862
+ ```
863
+ Get my working memory contents
864
+ ```
865
+
866
+ 3. **Review and continue**:
867
+ The AI assistant will have access to your previous session's context.
868
+
869
+ ### Project-Specific Memory
870
+
871
+ Use different robot names for different projects:
872
+
873
+ ```
874
+ # For project A
875
+ Set robot name to "project-a-assistant"
876
+ Remember that project A uses React with TypeScript
877
+
878
+ # For project B
879
+ Set robot name to "project-b-assistant"
880
+ Remember that project B uses Vue with JavaScript
881
+ ```
882
+
883
+ Each robot has its own working memory but shares the global long-term memory (hive mind).
884
+
885
+ ### Using Robot Groups
886
+
887
+ Robot Groups enable high-availability configurations where multiple robots share working memory:
888
+
889
+ 1. **Create a group**:
890
+ ```
891
+ Create a robot group called "research-team" with 3 max members
892
+ ```
893
+
894
+ 2. **Join robots to the group**:
895
+ ```
896
+ Join robot "researcher-1" to group "research-team" as active
897
+ Join robot "researcher-2" to group "research-team" as passive
898
+ ```
899
+
900
+ 3. **Store shared memories**:
901
+ ```
902
+ Remember in group "research-team" that we found a relevant paper on embeddings
903
+ ```
904
+
905
+ 4. **Recall from group context**:
906
+ ```
907
+ Recall from group "research-team" what we know about embeddings
908
+ ```
909
+
910
+ 5. **Handle failover**:
911
+ ```
912
+ Trigger failover for group "research-team"
913
+ ```
914
+
915
+ 6. **Check group status**:
916
+ ```
917
+ Show status of group "research-team"
918
+ ```
919
+
920
+ ### Searching with Typo Tolerance
921
+
922
+ Use fuzzy search when you're not sure of exact tag names:
923
+
924
+ ```
925
+ Search for tags similar to "postgrsql"
926
+ ```
927
+
928
+ This will find `database:postgresql` even with the typo.
929
+
930
+ ## Session Management
931
+
932
+ ### How Sessions Work
933
+
934
+ 1. **Per-client isolation**: Each MCP client spawns its own server process
935
+ 2. **Robot identity**: The `SetRobotTool` establishes which robot you're using
936
+ 3. **Working memory**: Each robot has its own working memory tracked in the database
937
+ 4. **Hive mind**: All robots share the same long-term memory
938
+
939
+ ### Best Practices
940
+
941
+ 1. **Always set robot identity first**: Call `SetRobotTool` at the start of each session
942
+ 2. **Use consistent robot names**: Use the same name to maintain continuity
943
+ 3. **Restore previous sessions**: Use `GetWorkingMemoryTool` to restore context
944
+ 4. **Use descriptive robot names**: e.g., `"code-review-assistant"`, `"project-x-helper"`
945
+
946
+ ## Troubleshooting
947
+
948
+ ### Server Won't Start
949
+
950
+ **Error: `fast-mcp gem not found`**
951
+ ```bash
952
+ gem install fast-mcp
953
+ ```
954
+
955
+ **Error: `HTM_DBURL not set`**
956
+ ```bash
957
+ export HTM_DBURL="postgresql://user@localhost:5432/htm_development"
958
+ ```
959
+
960
+ ### Database Connection Issues
961
+
962
+ **Error: `could not connect to server`**
963
+ 1. Verify PostgreSQL is running
964
+ 2. Check your connection URL
965
+ 3. Test with: `rake htm:db:test`
966
+
967
+ **Error: `extension "vector" does not exist`**
968
+ ```bash
969
+ # Install pgvector extension
970
+ psql htm_development -c "CREATE EXTENSION IF NOT EXISTS vector;"
971
+ psql htm_development -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
972
+ ```
973
+
974
+ ### Client Can't Connect
975
+
976
+ **Claude Desktop doesn't show HTM tools:**
977
+ 1. Verify the config file path is correct for your OS
978
+ 2. Check that `htm_mcp` is in your PATH or use an absolute path
979
+ 3. Restart Claude Desktop completely
980
+ 4. Check Claude Desktop logs for errors
981
+
982
+ **Claude Code doesn't recognize tools:**
983
+ 1. Run `/mcp` to refresh MCP connections
984
+ 2. Verify config is valid JSON
985
+ 3. Check that HTM_DBURL is set in the env section
986
+
987
+ ### Embedding/Tag Errors
988
+
989
+ **Error: `Connection refused` (Ollama)**
990
+ 1. Start Ollama: `ollama serve`
991
+ 2. Pull required models:
992
+ ```bash
993
+ ollama pull nomic-embed-text
994
+ ollama pull llama3
995
+ ```
996
+
997
+ ### Debugging
998
+
999
+ Enable verbose logging by checking STDERR output:
1000
+ ```bash
1001
+ htm_mcp 2>&1 | tee mcp_debug.log
1002
+ ```
1003
+
1004
+ The server logs all tool calls and errors to STDERR.
1005
+
1006
+ ## Environment Variables
1007
+
1008
+ Run `htm_mcp help` for a complete list. Key variables:
1009
+
1010
+ ### Database (required)
1011
+
1012
+ | Variable | Description |
1013
+ |----------|-------------|
1014
+ | `HTM_DBURL` | PostgreSQL connection URL (e.g., `postgresql://user:pass@localhost:5432/htm_development`) |
1015
+
1016
+ ### Database (alternative to HTM_DBURL)
1017
+
1018
+ | Variable | Description | Default |
1019
+ |----------|-------------|---------|
1020
+ | `HTM_DBNAME` | Database name | - |
1021
+ | `HTM_DBHOST` | Database host | `localhost` |
1022
+ | `HTM_DBPORT` | Database port | `5432` |
1023
+ | `HTM_DBUSER` | Database username | - |
1024
+ | `HTM_DBPASS` | Database password | - |
1025
+ | `HTM_DBSSLMODE` | SSL mode | `prefer` |
1026
+
1027
+ ### LLM Providers
1028
+
1029
+ | Variable | Description | Default |
1030
+ |----------|-------------|---------|
1031
+ | `HTM_EMBEDDING_PROVIDER` | Embedding provider | `ollama` |
1032
+ | `HTM_EMBEDDING_MODEL` | Embedding model | `nomic-embed-text:latest` |
1033
+ | `HTM_TAG_PROVIDER` | Tag extraction provider | `ollama` |
1034
+ | `HTM_TAG_MODEL` | Tag model | `gemma3:latest` |
1035
+ | `HTM_OLLAMA_URL` | Ollama server URL | `http://localhost:11434` |
1036
+
1037
+ ### Other Providers (set API keys as needed)
1038
+
1039
+ | Variable | Description |
1040
+ |----------|-------------|
1041
+ | `HTM_OPENAI_API_KEY` | OpenAI API key |
1042
+ | `HTM_ANTHROPIC_API_KEY` | Anthropic API key |
1043
+ | `HTM_GEMINI_API_KEY` | Google Gemini API key |
1044
+ | `HTM_AZURE_API_KEY` | Azure OpenAI API key |
1045
+ | `HTM_AZURE_ENDPOINT` | Azure OpenAI endpoint |
1046
+
1047
+ ## Next Steps
1048
+
1049
+ - [Getting Started](getting-started.md) - HTM basics
1050
+ - [Adding Memories](adding-memories.md) - Learn about tags and metadata
1051
+ - [Recalling Memories](recalling-memories.md) - Search strategies
1052
+ - [Multi-Robot Systems](multi-robot.md) - Working with multiple robots