Skip to content

Commit c671915

Browse files
enesakarclaude
andcommitted
Initial commit
MCP server for saving and retrieving AI conversation context. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
0 parents  commit c671915

File tree

10 files changed

+6859
-0
lines changed

10 files changed

+6859
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
2+
UPSTASH_REDIS_REST_TOKEN=your-redis-token

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.vercel
4+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Upstash
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.

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Memo MCP
2+
3+
An MCP server that saves and retrieves AI conversation context. Hand off conversations between AI agents seamlessly. Free and no account required.
4+
5+
## What it does
6+
7+
When you're working with an AI agent and need to:
8+
9+
- **Switch agents** - Claude can't fix your bug? Try Cursor or Copilot with dense context
10+
- **Continue later** - Save progress and pick up where you left off
11+
- **Move machines** - Start on laptop, continue on desktop
12+
13+
Just say `memo set` and the agent will save structured context (goal, completed tasks, pending tasks, decisions, relevant files). Get a short ID back, use `memo get <id>` anywhere to restore context.
14+
15+
## Installation
16+
17+
### Claude Code
18+
19+
```bash
20+
claude mcp add memo -- npx -y @upstash/memo
21+
```
22+
23+
### Open Code
24+
25+
```bash
26+
opencode mcp add memo -- npx -y @upstash/memo
27+
```
28+
29+
### Claude Desktop / Cursor
30+
31+
Add to your MCP config:
32+
33+
```json
34+
{
35+
"mcpServers": {
36+
"memo": {
37+
"command": "npx",
38+
"args": ["-y", "@upstash/memo"]
39+
}
40+
}
41+
}
42+
```
43+
44+
## Usage
45+
46+
### Save context
47+
48+
```
49+
memo set
50+
```
51+
52+
The AI will summarize the conversation and return an ID like `4tJ630XqhCV5gQelx98pu`.
53+
54+
### Restore context
55+
56+
```
57+
memo get 4tJ630XqhCV5gQelx98pu
58+
```
59+
60+
The AI will load the previous context and continue where you left off.
61+
62+
## What gets saved
63+
64+
When you run `memo set`, the agent stores a structured snapshot, for example:
65+
66+
- Goal
67+
- Completed tasks
68+
- Pending tasks
69+
- Key decisions
70+
- Relevant files (paths only) or references
71+
72+
This keeps restored conversations focused and avoids reloading raw chat history.
73+
74+
## Security
75+
76+
Your conversation context is stored in Upstash Redis with encryption enabled at rest and in transit. Data expires automatically after 24 hours (configurable via `--ttl-mins`).
77+
78+
If you prefer full control over your data, you can self-host both the API and storage using your own infrastructure. See the Self-hosting section below.
79+
80+
## Self-hosting
81+
82+
The repo includes both the MCP server and the API. To self-host:
83+
84+
### 1. Set up environment
85+
86+
Create a `.env` file with your Upstash Redis credentials:
87+
88+
```
89+
UPSTASH_REDIS_REST_URL=your-redis-url
90+
UPSTASH_REDIS_REST_TOKEN=your-redis-token
91+
```
92+
93+
### 2. Run locally
94+
95+
```bash
96+
npx vercel dev
97+
```
98+
99+
### 3. Deploy to Vercel
100+
101+
```bash
102+
vercel
103+
```
104+
105+
Set the same environment variables in your Vercel project settings.
106+
107+
### 4. Point MCP to your API
108+
109+
The MCP server uses `https://memo.upstash.com` by default. To use your own API, modify `index.ts`:
110+
111+
```typescript
112+
const GET_URL = "https://your-api.vercel.app/api/get";
113+
const SET_URL = "https://your-api.vercel.app/api/set";
114+
```
115+
116+
## Options
117+
118+
### `--ttl-mins`
119+
120+
Set expiration time in minutes. Default is 1440 (24 hours).
121+
122+
```json
123+
{
124+
"mcpServers": {
125+
"memo": {
126+
"command": "npx",
127+
"args": ["-y", "@upstash/memo", "--ttl-mins", "4320"]
128+
}
129+
}
130+
}
131+
```
132+
133+
## License
134+
135+
MIT

api/index.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Hono } from "hono";
2+
import { Redis } from "@upstash/redis";
3+
import { Ratelimit } from "@upstash/ratelimit";
4+
import { nanoid } from "nanoid";
5+
6+
const redis = new Redis({
7+
url: process.env.UPSTASH_REDIS_REST_URL!,
8+
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
9+
});
10+
11+
const ratelimit = new Ratelimit({
12+
redis,
13+
limiter: Ratelimit.slidingWindow(60, "1 m"),
14+
});
15+
16+
const app = new Hono().basePath("/api");
17+
18+
// Rate limit middleware
19+
app.use(async (c, next) => {
20+
const ip = c.req.header("x-forwarded-for")?.split(",")[0] || "anonymous";
21+
const { success, remaining } = await ratelimit.limit(ip);
22+
c.header("X-RateLimit-Remaining", remaining.toString());
23+
if (!success) {
24+
return c.json({ error: "Rate limit exceeded" }, 429);
25+
}
26+
return next();
27+
});
28+
29+
// Accept id from query params, path, or body
30+
app.all("/get/:id?", async (c) => {
31+
let id = c.req.param("id") || c.req.query("id");
32+
33+
// Try body if not in query/path
34+
if (!id) {
35+
try {
36+
const body = await c.req.json();
37+
id = body.id;
38+
} catch {
39+
// No body or invalid JSON
40+
}
41+
}
42+
43+
if (!id) {
44+
return c.json({ error: "Missing id parameter" }, 400);
45+
}
46+
const summary = await redis.get(id);
47+
if (!summary) {
48+
return c.json({ error: "Summary not found" }, 404);
49+
}
50+
// Upstash auto-parses JSON, so stringify if we got an object back
51+
const summaryStr = typeof summary === "string" ? summary : JSON.stringify(summary);
52+
return c.json({ summary: summaryStr });
53+
});
54+
55+
app.post("/set", async (c) => {
56+
const body = await c.req.json();
57+
// Accept summary, context, or data field
58+
const summary = body.summary || body.context || body.data;
59+
if (!summary) {
60+
return c.json({ error: "Missing summary/context/data field" }, 400);
61+
}
62+
const ttlMins = body.ttlMins || 1440; // 24 hours
63+
const id = nanoid();
64+
await redis.set(id, summary, { ex: ttlMins * 60 });
65+
return c.json({ id, message: "Data received" });
66+
});
67+
68+
export default app;

0 commit comments

Comments
 (0)