@memoryrelay/mcp-server 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MemoryRelay Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,583 @@
1
+ # @memoryrelay/mcp-server
2
+
3
+ **MCP server for MemoryRelay** - Give your AI agents persistent memory across sessions.
4
+
5
+ [![CI/CD](https://github.com/memoryrelay/mcp-server/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/memoryrelay/mcp-server/actions)
6
+ [![npm version](https://badge.fury.io/js/@memoryrelay%2Fmcp-server.svg)](https://www.npmjs.com/package/@memoryrelay/mcp-server)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## 🚀 Features
10
+
11
+ - **Persistent Memory**: Store and retrieve memories across conversations
12
+ - **Semantic Search**: Find relevant memories using natural language queries
13
+ - **Entity Management**: Create and link entities (people, projects, concepts) for knowledge graphs
14
+ - **Security Hardened**: API key masking, input validation, sanitized errors
15
+ - **MCP Compliant**: Works with Claude Desktop, OpenClaw, and any MCP client
16
+ - **Fully Tested**: 102+ test cases covering all functionality
17
+
18
+ ---
19
+
20
+ ## 📦 Installation
21
+
22
+ ### Using npx (recommended)
23
+
24
+ No installation needed - run directly:
25
+
26
+ ```bash
27
+ npx @memoryrelay/mcp-server
28
+ ```
29
+
30
+ ### Global Installation
31
+
32
+ ```bash
33
+ npm install -g @memoryrelay/mcp-server
34
+ ```
35
+
36
+ ### Local Project Installation
37
+
38
+ ```bash
39
+ npm install @memoryrelay/mcp-server
40
+ ```
41
+
42
+ ---
43
+
44
+ ## ⚡ Quick Start
45
+
46
+ ### 1. Get Your API Key
47
+
48
+ Get your API key from the [MemoryRelay API](https://api.memoryrelay.net) - contact support for beta access (format: `mem_prod_xxxxx`).
49
+
50
+ ### 2. Configure Your MCP Client
51
+
52
+ #### For OpenClaw
53
+
54
+ Edit `~/.openclaw/openclaw.json`:
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "memoryrelay": {
60
+ "command": "npx",
61
+ "args": ["-y", "@memoryrelay/mcp-server"],
62
+ "env": {
63
+ "MEMORYRELAY_API_KEY": "mem_prod_xxxxx",
64
+ "MEMORYRELAY_AGENT_ID": "iris"
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ #### For Claude Desktop
72
+
73
+ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "memoryrelay": {
79
+ "command": "npx",
80
+ "args": ["-y", "@memoryrelay/mcp-server"],
81
+ "env": {
82
+ "MEMORYRELAY_API_KEY": "mem_prod_xxxxx"
83
+ }
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### 3. Restart Your Client
90
+
91
+ Restart OpenClaw or Claude Desktop to load the MCP server.
92
+
93
+ ### 4. Test It Out
94
+
95
+ Try asking:
96
+ - "Remember that I prefer Python over JavaScript"
97
+ - "What programming languages do I like?"
98
+ - "Create an entity for the MemoryRelay project"
99
+
100
+ ---
101
+
102
+ ## 🔧 Configuration
103
+
104
+ ### Environment Variables
105
+
106
+ | Variable | Required | Default | Description |
107
+ |----------|----------|---------|-------------|
108
+ | `MEMORYRELAY_API_KEY` | ✅ Yes | - | Your API key (starts with `mem_`) |
109
+ | `MEMORYRELAY_API_URL` | No | `https://api.memoryrelay.net` | API base URL (for custom deployments) |
110
+ | `MEMORYRELAY_AGENT_ID` | No | Auto-detected | Agent identifier (auto-generated if not set) |
111
+ | `MEMORYRELAY_TIMEOUT` | No | `30000` | Request timeout in milliseconds |
112
+ | `MEMORYRELAY_LOG_LEVEL` | No | `info` | Logging level (`debug`, `info`, `warn`, `error`) |
113
+
114
+ ### Agent ID Detection
115
+
116
+ The server automatically detects your agent ID from:
117
+ 1. `MEMORYRELAY_AGENT_ID` environment variable
118
+ 2. `OPENCLAW_AGENT_NAME` environment variable (OpenClaw)
119
+ 3. Hostname-based generation (if neither is set)
120
+
121
+ ---
122
+
123
+ ## 🛠️ Available Tools
124
+
125
+ The MCP server provides 9 tools for memory and entity management:
126
+
127
+ ### Memory Management Tools
128
+
129
+ #### `memory_store`
130
+
131
+ Store a new memory with optional metadata.
132
+
133
+ **Parameters:**
134
+ - `content` (string, required) - The memory content to store
135
+ - `metadata` (object, optional) - Key-value metadata to attach
136
+
137
+ **Example:**
138
+ ```json
139
+ {
140
+ "content": "User prefers Python for data analysis projects",
141
+ "metadata": {
142
+ "category": "preference",
143
+ "topic": "programming"
144
+ }
145
+ }
146
+ ```
147
+
148
+ **Returns:** Memory object with `id`, `content`, `metadata`, `created_at`, `updated_at`
149
+
150
+ ---
151
+
152
+ #### `memory_search`
153
+
154
+ Search memories using semantic similarity.
155
+
156
+ **Parameters:**
157
+ - `query` (string, required) - Natural language search query
158
+ - `limit` (number, optional, default: 10) - Maximum results (1-50)
159
+ - `threshold` (number, optional, default: 0.5) - Minimum similarity score (0-1)
160
+
161
+ **Example:**
162
+ ```json
163
+ {
164
+ "query": "What are the user's programming preferences?",
165
+ "limit": 5,
166
+ "threshold": 0.7
167
+ }
168
+ ```
169
+
170
+ **Returns:** Array of memory objects with similarity scores
171
+
172
+ ---
173
+
174
+ #### `memory_list`
175
+
176
+ List recent memories chronologically.
177
+
178
+ **Parameters:**
179
+ - `limit` (number, optional, default: 20) - Number of memories to return (1-100)
180
+ - `offset` (number, optional, default: 0) - Pagination offset
181
+
182
+ **Example:**
183
+ ```json
184
+ {
185
+ "limit": 10,
186
+ "offset": 0
187
+ }
188
+ ```
189
+
190
+ **Returns:** Object with `memories` array, `total`, `limit`, `offset`
191
+
192
+ ---
193
+
194
+ #### `memory_get`
195
+
196
+ Retrieve a specific memory by ID.
197
+
198
+ **Parameters:**
199
+ - `id` (string, required) - Memory UUID
200
+
201
+ **Example:**
202
+ ```json
203
+ {
204
+ "id": "550e8400-e29b-41d4-a716-446655440000"
205
+ }
206
+ ```
207
+
208
+ **Returns:** Memory object
209
+
210
+ ---
211
+
212
+ #### `memory_update`
213
+
214
+ Update an existing memory's content or metadata.
215
+
216
+ **Parameters:**
217
+ - `id` (string, required) - Memory UUID
218
+ - `content` (string, required) - New content
219
+ - `metadata` (object, optional) - Updated metadata (replaces existing)
220
+
221
+ **Example:**
222
+ ```json
223
+ {
224
+ "id": "550e8400-e29b-41d4-a716-446655440000",
225
+ "content": "Updated: User prefers Python and TypeScript for data analysis",
226
+ "metadata": {
227
+ "category": "preference",
228
+ "updated": "2026-02-12"
229
+ }
230
+ }
231
+ ```
232
+
233
+ **Returns:** Updated memory object
234
+
235
+ ---
236
+
237
+ #### `memory_delete`
238
+
239
+ Permanently delete a memory.
240
+
241
+ **Parameters:**
242
+ - `id` (string, required) - Memory UUID
243
+
244
+ **Example:**
245
+ ```json
246
+ {
247
+ "id": "550e8400-e29b-41d4-a716-446655440000"
248
+ }
249
+ ```
250
+
251
+ **Returns:** Success confirmation
252
+
253
+ ---
254
+
255
+ ### Entity Management Tools
256
+
257
+ #### `entity_create`
258
+
259
+ Create a named entity for the knowledge graph.
260
+
261
+ **Parameters:**
262
+ - `name` (string, required) - Entity name (1-200 characters)
263
+ - `type` (enum, required) - One of: `person`, `place`, `organization`, `project`, `concept`, `other`
264
+ - `metadata` (object, optional) - Key-value metadata
265
+
266
+ **Example:**
267
+ ```json
268
+ {
269
+ "name": "MemoryRelay Project",
270
+ "type": "project",
271
+ "metadata": {
272
+ "status": "active",
273
+ "started": "2026-01"
274
+ }
275
+ }
276
+ ```
277
+
278
+ **Returns:** Entity object with `id`, `name`, `type`, `metadata`, `created_at`
279
+
280
+ ---
281
+
282
+ #### `entity_link`
283
+
284
+ Link an entity to a memory to establish relationships.
285
+
286
+ **Parameters:**
287
+ - `entity_id` (string, required) - Entity UUID
288
+ - `memory_id` (string, required) - Memory UUID
289
+ - `relationship` (string, optional, default: "mentioned_in") - Relationship type
290
+
291
+ **Example:**
292
+ ```json
293
+ {
294
+ "entity_id": "650e8400-e29b-41d4-a716-446655440001",
295
+ "memory_id": "550e8400-e29b-41d4-a716-446655440000",
296
+ "relationship": "relates_to"
297
+ }
298
+ ```
299
+
300
+ **Returns:** Success confirmation with link details
301
+
302
+ ---
303
+
304
+ ### Health Check Tool
305
+
306
+ #### `memory_health`
307
+
308
+ Check API connectivity and server health.
309
+
310
+ **Parameters:** None
311
+
312
+ **Example:**
313
+ ```json
314
+ {}
315
+ ```
316
+
317
+ **Returns:** Health status object with `status`, `version`, `latency`
318
+
319
+ ---
320
+
321
+ ## 🔒 Security
322
+
323
+ This MCP server is designed with security best practices:
324
+
325
+ ### API Key Protection
326
+ - API keys starting with `mem_` are automatically masked in all logs
327
+ - Keys are never exposed in error messages or debug output
328
+ - Environment variables are the only supported authentication method
329
+
330
+ ### Input Validation
331
+ - All inputs validated using Zod schemas before processing
332
+ - UUIDs validated for format correctness
333
+ - Entity names sanitized to prevent XSS attacks
334
+ - String lengths enforced (e.g., entity names max 200 characters)
335
+
336
+ ### Error Handling
337
+ - Errors sanitized to prevent information leakage
338
+ - No internal paths or stack traces exposed to clients
339
+ - All errors logged to stderr (stdout reserved for MCP protocol)
340
+
341
+ ### STDIO Safety
342
+ - All logging strictly to stderr
343
+ - STDIO transport properly isolated per MCP specification
344
+
345
+ For detailed security information, see [SECURITY.md](./docs/SECURITY.md).
346
+
347
+ ---
348
+
349
+ ## 🧪 Development
350
+
351
+ ### Prerequisites
352
+
353
+ - Node.js 18+ (22+ recommended)
354
+ - npm or yarn
355
+
356
+ ### Setup
357
+
358
+ ```bash
359
+ # Clone the repository
360
+ git clone https://github.com/memoryrelay/mcp-server.git
361
+ cd ai-memory-service/mcp
362
+
363
+ # Install dependencies
364
+ npm install
365
+
366
+ # Build the project
367
+ npm run build
368
+
369
+ # Run tests
370
+ npm test
371
+
372
+ # Run all tests (including integration)
373
+ npm run test:all
374
+
375
+ # Generate coverage report
376
+ npm run test:coverage
377
+
378
+ # Type checking
379
+ npm run type-check
380
+ ```
381
+
382
+ ### Available Scripts
383
+
384
+ - `npm run build` - Build for production
385
+ - `npm run dev` - Build in watch mode
386
+ - `npm test` - Run unit tests
387
+ - `npm run test:watch` - Run tests in watch mode
388
+ - `npm run test:integration` - Run integration tests (requires API key)
389
+ - `npm run test:server` - Run server-specific tests
390
+ - `npm run test:security` - Run security-focused tests
391
+ - `npm run test:all` - Run all tests
392
+ - `npm run test:coverage` - Generate coverage report
393
+ - `npm run type-check` - Run TypeScript type checking
394
+
395
+ ### Project Structure
396
+
397
+ ```
398
+ mcp/
399
+ ├── src/
400
+ │ ├── index.ts # Entry point
401
+ │ ├── server.ts # MCP server implementation
402
+ │ ├── client.ts # MemoryRelay API client
403
+ │ ├── config.ts # Configuration loader
404
+ │ ├── logger.ts # Logging utilities
405
+ │ └── types.ts # TypeScript types
406
+ ├── tests/
407
+ │ ├── server.test.ts # Server tests
408
+ │ ├── client.test.ts # Client tests
409
+ │ ├── config.test.ts # Config tests
410
+ │ ├── security.test.ts # Security tests
411
+ │ └── integration.test.ts # Integration tests
412
+ ├── docs/
413
+ │ └── SECURITY.md # Security documentation
414
+ ├── package.json
415
+ ├── tsconfig.json
416
+ ├── vitest.config.ts
417
+ └── README.md
418
+ ```
419
+
420
+ ---
421
+
422
+ ## 🐛 Troubleshooting
423
+
424
+ ### Server Won't Start
425
+
426
+ **Problem:** `Failed to start MemoryRelay MCP server`
427
+
428
+ **Solutions:**
429
+ 1. Verify your API key is set correctly:
430
+ ```bash
431
+ echo $MEMORYRELAY_API_KEY
432
+ ```
433
+ 2. Check the API key format (should start with `mem_`)
434
+ 3. Ensure Node.js version is 18+ (`node --version`)
435
+ 4. Try running with debug logging:
436
+ ```json
437
+ {
438
+ "env": {
439
+ "MEMORYRELAY_LOG_LEVEL": "debug"
440
+ }
441
+ }
442
+ ```
443
+
444
+ ### Connection Errors
445
+
446
+ **Problem:** `API request failed` or timeout errors
447
+
448
+ **Solutions:**
449
+ 1. Check internet connectivity
450
+ 2. Verify API URL (if using custom deployment)
451
+ 3. Increase timeout:
452
+ ```json
453
+ {
454
+ "env": {
455
+ "MEMORYRELAY_TIMEOUT": "60000"
456
+ }
457
+ }
458
+ ```
459
+ 4. Check firewall/proxy settings
460
+
461
+ ### Tools Not Showing Up
462
+
463
+ **Problem:** MCP tools not available in client
464
+
465
+ **Solutions:**
466
+ 1. Restart your MCP client (Claude Desktop, OpenClaw)
467
+ 2. Check configuration file syntax (valid JSON)
468
+ 3. Verify the `command` path is correct
469
+ 4. Check client logs for MCP server connection errors
470
+
471
+ ### Authentication Errors
472
+
473
+ **Problem:** `401 Unauthorized` errors
474
+
475
+ **Solutions:**
476
+ 1. Verify API key is correct and active
477
+ 2. Check for extra spaces in environment variable
478
+ 3. Ensure key hasn't expired
479
+ 4. Contact support if key should be valid
480
+
481
+ ### Validation Errors
482
+
483
+ **Problem:** `Validation error` when calling tools
484
+
485
+ **Solutions:**
486
+ 1. Check parameter types match schema (e.g., `limit` should be number, not string)
487
+ 2. Verify required parameters are provided
488
+ 3. Check UUID format for ID parameters
489
+ 4. Ensure string lengths are within limits (e.g., entity names max 200 chars)
490
+
491
+ ### Debug Mode
492
+
493
+ Enable debug logging to see detailed information:
494
+
495
+ ```json
496
+ {
497
+ "env": {
498
+ "MEMORYRELAY_LOG_LEVEL": "debug"
499
+ }
500
+ }
501
+ ```
502
+
503
+ Debug logs go to stderr and include:
504
+ - API request/response details (with masked API keys)
505
+ - Tool invocation parameters
506
+ - Validation errors
507
+ - Connection status
508
+
509
+ ### Getting Help
510
+
511
+ - 📖 [Full Documentation](https://github.com/memoryrelay/mcp-server/tree/main/mcp)
512
+ - 🐛 [Report Issues](https://github.com/memoryrelay/mcp-server/issues)
513
+ - 💬 [Discussions](https://github.com/memoryrelay/mcp-server/discussions)
514
+ - 🔒 [Security Policy](./docs/SECURITY.md)
515
+
516
+ ---
517
+
518
+ ## 📊 Testing
519
+
520
+ The project has comprehensive test coverage:
521
+
522
+ - **102+ test cases** covering all functionality
523
+ - Unit tests for each component
524
+ - Integration tests against live API
525
+ - Security-focused tests for API key masking and input validation
526
+ - Server protocol tests
527
+
528
+ Run tests:
529
+
530
+ ```bash
531
+ # All unit tests
532
+ npm test
533
+
534
+ # With coverage
535
+ npm run test:coverage
536
+
537
+ # Integration tests (requires API key)
538
+ MEMORYRELAY_API_KEY=mem_prod_xxx npm run test:integration
539
+
540
+ # Specific test suites
541
+ npm run test:server # Server tests only
542
+ npm run test:security # Security tests only
543
+ ```
544
+
545
+ ---
546
+
547
+ ## 📄 License
548
+
549
+ MIT License - see [LICENSE](../LICENSE) for details
550
+
551
+ ---
552
+
553
+ ## 🔗 Links
554
+
555
+ - **Documentation**: [GitHub Repository](https://github.com/memoryrelay/mcp-server)
556
+ - **npm Package**: [@memoryrelay/mcp-server](https://www.npmjs.com/package/@memoryrelay/mcp-server)
557
+ - **MemoryRelay API**: [api.memoryrelay.net](https://api.memoryrelay.net)
558
+ - **Model Context Protocol**: [modelcontextprotocol.io](https://modelcontextprotocol.io)
559
+ - **OpenClaw**: [openclaw.org](https://openclaw.org)
560
+
561
+ ---
562
+
563
+ ## 🙏 Contributing
564
+
565
+ Contributions welcome! Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines.
566
+
567
+ ---
568
+
569
+ ## 📝 Changelog
570
+
571
+ ### v0.1.0 (2026-02-12)
572
+
573
+ - Initial release
574
+ - 9 MCP tools for memory and entity management
575
+ - Semantic search with configurable thresholds
576
+ - Entity linking for knowledge graphs
577
+ - Security hardened with API key masking and input validation
578
+ - 102+ test cases with full coverage
579
+ - Support for OpenClaw and Claude Desktop
580
+
581
+ ---
582
+
583
+ Made with ❤️ by the [MemoryRelay Team](https://github.com/memoryrelay)
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node