Skip to content

Commit fce38b3

Browse files
authored
feat: Mem0 Memory MCP Server (with npx command)
2 parents eb8c436 + 0f60a8f commit fce38b3

File tree

8 files changed

+4368
-4414
lines changed

8 files changed

+4368
-4414
lines changed

node/mem0/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
node_modules
1010
build
11+
dist

node/mem0/README.md

Lines changed: 157 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Mem0 Memory Tool
1+
# Mem0 Memory MCP Server
22

33
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.
44

@@ -8,101 +8,221 @@ A Model Context Protocol (MCP) server that provides memory storage and retrieval
88
- Search through stored memories with relevance scoring
99
- Simple and intuitive API
1010
- 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
1613

1714
## Installation
1815

19-
1. Clone the repository
20-
2. Install dependencies:
16+
### Running with npx
17+
2118
```bash
22-
npm install
19+
env MEM0_API_KEY=your-api-key-here npx -y @mem0/mcp
2320
```
2421

25-
3. Create a `.env` file in the root directory and add your Mem0 API key:
22+
### Manual Installation
23+
2624
```bash
27-
MEM0_API_KEY=your-api-key-here
25+
npm install -g @mem0/mcp
2826
```
2927

30-
## Usage
28+
## Configuration for AI Tools
3129

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+
```
3359

34-
### 1. Adding Memories
60+
### Running on VS Code
3561

36-
Store new memories with user-specific context:
62+
Add the following JSON block to your User Settings (JSON) file in VS Code:
3763

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+
}
4386
```
4487

45-
### 2. Searching Memories
88+
## Available Tools
4689

47-
Search through stored memories to retrieve relevant information:
90+
### 1. Add Memory Tool (add-memory)
4891

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+
}
54102
```
55103

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+
```
60117

61118
## Response Format
62119

63120
### Add Memory Response
121+
64122
```json
65123
{
66124
"content": [
67125
{
68126
"type": "text",
69127
"text": "Memory added successfully"
70128
}
71-
]
129+
],
130+
"isError": false
72131
}
73132
```
74133

75134
### Search Memory Response
135+
76136
```json
77137
{
78138
"content": [
79139
{
80140
"type": "text",
81-
"text": "Memory: User prefers dark mode interface\nRelevance: 0.95\n---"
141+
"text": "Memory: User prefers dark mode interface\nRelevance: 0.95\n---\nMemory: User mentioned liking minimal UI\nRelevance: 0.82\n---"
82142
}
83-
]
143+
],
144+
"isError": false
84145
}
85146
```
86147

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+
87156
## Development
88157

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+
89178
To run the server in development mode:
90179

91180
```bash
92181
npm run dev
93182
```
94183

95-
## Building
184+
### Building
96185

97186
To build the project:
98187

99188
```bash
100189
npm run build
101190
```
102191

103-
## Environment Variables
192+
### Starting the Server
104193

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.
106226

107227
## License
108228

0 commit comments

Comments
 (0)