1
- # Mem0 Memory Tool
1
+ # Mem0 Memory MCP Server
2
2
3
3
A Model Context Protocol (MCP) server that provides memory storage and retrieval capabilities using [ Mem0] ( https://github.com/mem0ai/mem0 ) . This tool allows you to store and search through memories, making it useful for maintaining context and making informed decisions based on past interactions.
4
4
@@ -8,101 +8,221 @@ A Model Context Protocol (MCP) server that provides memory storage and retrieval
8
8
- Search through stored memories with relevance scoring
9
9
- Simple and intuitive API
10
10
- Built on the Model Context Protocol
11
-
12
- ## Prerequisites
13
-
14
- - Node.js (v14 or higher)
15
- - A Mem0 API key [ (Get Here)] ( https://app.mem0.ai/dashboard/api-keys )
11
+ - Automatic error handling
12
+ - Support for multiple user contexts
16
13
17
14
## Installation
18
15
19
- 1 . Clone the repository
20
- 2 . Install dependencies:
16
+ ### Running with npx
17
+
21
18
``` bash
22
- npm install
19
+ env MEM0_API_KEY=your-api-key-here npx -y @mem0/mcp
23
20
```
24
21
25
- 3 . Create a ` .env ` file in the root directory and add your Mem0 API key:
22
+ ### Manual Installation
23
+
26
24
``` bash
27
- MEM0_API_KEY=your-api-key-here
25
+ npm install -g @mem0/mcp
28
26
```
29
27
30
- ## Usage
28
+ ## Configuration for AI Tools
31
29
32
- The server provides two main tools:
30
+ ### Running on Cursor
31
+
32
+ #### Configuring Cursor 🖥️
33
+
34
+ To configure Mem0 MCP in Cursor:
35
+
36
+ 1 . Open Cursor Settings
37
+ 2 . Go to Features > MCP Servers
38
+ 3 . Click "+ Add New MCP Server"
39
+ 4 . Enter the following:
40
+ - Name: "mem0-mcp" (or your preferred name)
41
+ - Type: "command"
42
+ - Command: ` env MEM0_API_KEY=your-api-key-here npx -y @mem0/mcp `
43
+
44
+ To configure Mem0 MCP using JSON configuration:
45
+
46
+ ``` json
47
+ {
48
+ "mcpServers" : {
49
+ "mem0-mcp" : {
50
+ "command" : " npx" ,
51
+ "args" : [" -y" , " @mem0/mcp" ],
52
+ "env" : {
53
+ "MEM0_API_KEY" : " YOUR-API-KEY-HERE"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
33
59
34
- ### 1. Adding Memories
60
+ ### Running on VS Code
35
61
36
- Store new memories with user-specific context :
62
+ Add the following JSON block to your User Settings (JSON) file in VS Code :
37
63
38
- ``` typescript
39
- await server .tool (" add-memory" , {
40
- content: " User prefers dark mode interface" ,
41
- userId: " alice"
42
- });
64
+ ``` json
65
+ {
66
+ "mcp" : {
67
+ "inputs" : [
68
+ {
69
+ "type" : " promptString" ,
70
+ "id" : " apiKey" ,
71
+ "description" : " Mem0 API Key" ,
72
+ "password" : true
73
+ }
74
+ ],
75
+ "servers" : {
76
+ "mem0-memory" : {
77
+ "command" : " npx" ,
78
+ "args" : [" -y" , " @mem0/mcp" ],
79
+ "env" : {
80
+ "MEM0_API_KEY" : " ${input:apiKey}"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
43
86
```
44
87
45
- ### 2. Searching Memories
88
+ ## Available Tools
46
89
47
- Search through stored memories to retrieve relevant information:
90
+ ### 1. Add Memory Tool (add-memory)
48
91
49
- ``` typescript
50
- const results = await server .tool (" search-memories" , {
51
- query: " What are the user's interface preferences?" ,
52
- userId: " alice"
53
- });
92
+ Store new memories with user-specific context.
93
+
94
+ ``` json
95
+ {
96
+ "name" : " add-memory" ,
97
+ "arguments" : {
98
+ "content" : " User prefers dark mode interface" ,
99
+ "userId" : " user123"
100
+ }
101
+ }
54
102
```
55
103
56
- The search results will include:
57
- - Memory content
58
- - Relevance score
59
- - Formatted output for easy integration
104
+ ### 2. Search Memories Tool (search-memories)
105
+
106
+ Search through stored memories to retrieve relevant information.
107
+
108
+ ``` json
109
+ {
110
+ "name" : " search-memories" ,
111
+ "arguments" : {
112
+ "query" : " What are the user's interface preferences?" ,
113
+ "userId" : " user123"
114
+ }
115
+ }
116
+ ```
60
117
61
118
## Response Format
62
119
63
120
### Add Memory Response
121
+
64
122
``` json
65
123
{
66
124
"content" : [
67
125
{
68
126
"type" : " text" ,
69
127
"text" : " Memory added successfully"
70
128
}
71
- ]
129
+ ],
130
+ "isError" : false
72
131
}
73
132
```
74
133
75
134
### Search Memory Response
135
+
76
136
``` json
77
137
{
78
138
"content" : [
79
139
{
80
140
"type" : " text" ,
81
- "text" : " Memory: User prefers dark mode interface\n Relevance: 0.95\n ---"
141
+ "text" : " Memory: User prefers dark mode interface\n Relevance: 0.95\n ---\n Memory: User mentioned liking minimal UI \n Relevance: 0.82 \n --- "
82
142
}
83
- ]
143
+ ],
144
+ "isError" : false
84
145
}
85
146
```
86
147
148
+ ## Configuration
149
+
150
+ ### Environment Variables
151
+
152
+ - ` MEM0_API_KEY ` : Your Mem0 API key (required)
153
+ - Required for operation
154
+ - Can be obtained from [ Mem0 Dashboard] ( https://app.mem0.ai/dashboard/api-keys )
155
+
87
156
## Development
88
157
158
+ ### Prerequisites
159
+
160
+ - Node.js (v14 or higher)
161
+ - A Mem0 API key
162
+
163
+ ### Setup
164
+
165
+ 1 . Clone the repository
166
+ 2 . Install dependencies:
167
+ ``` bash
168
+ npm install
169
+ ```
170
+
171
+ 3 . Create a ` .env ` file in the root directory and add your Mem0 API key:
172
+ ``` bash
173
+ MEM0_API_KEY=your-api-key-here
174
+ ```
175
+
176
+ ### Running Development Server
177
+
89
178
To run the server in development mode:
90
179
91
180
``` bash
92
181
npm run dev
93
182
```
94
183
95
- ## Building
184
+ ### Building
96
185
97
186
To build the project:
98
187
99
188
``` bash
100
189
npm run build
101
190
```
102
191
103
- ## Environment Variables
192
+ ### Starting the Server
104
193
105
- - ` MEM0_API_KEY ` : Your Mem0 API key (required)
194
+ To start the server after building:
195
+
196
+ ``` bash
197
+ npm start
198
+ ```
199
+
200
+ ## Error Handling
201
+
202
+ The server includes error handling for:
203
+
204
+ - API connection issues
205
+ - Invalid memory operations
206
+ - Search errors
207
+ - Authentication failures
208
+
209
+ Example error response:
210
+
211
+ ``` json
212
+ {
213
+ "content" : [
214
+ {
215
+ "type" : " text" ,
216
+ "text" : " Error: Failed to search memories: Invalid API key"
217
+ }
218
+ ],
219
+ "isError" : true
220
+ }
221
+ ```
222
+
223
+ ## Contributing
224
+
225
+ Contributions are welcome! Please feel free to submit a Pull Request.
106
226
107
227
## License
108
228
0 commit comments