Skip to main content
Glama
panhy1215-sys

mcp-http-diary-server

💞 虚拟恋人 AI 长期记忆 MCP Server

基于 MCP Streamable HTTP 的 AI 虚拟恋人长期记忆系统。让 AI 助手拥有长期陪伴能力: 认识用户、记住信息、理解偏好、学习人格、保存经历、记录关系变化,并在未来聊天中调用历史记忆。

核心流程:聊天 → AI 判断信息价值 → 提取记忆 → 分类保存 → 未来聊天读取。

技术栈(禁止更换)

  • Node.js + TypeScript

  • Express(HTTP 服务)

  • MCP SDK(Streamable HTTP,@modelcontextprotocol/sdk

  • Supabase(@supabase/supabase-js,anon 发布密钥)

  • Zod(参数校验)

仅读取高价值记忆,不保存全部聊天:用户主动要求记住的、长期偏好、身份信息、长期目标、稳定人格、重要关系事件才落库;普通闲聊、一次性内容、无意义消息不保存。

Related MCP server: memory-mcp

项目结构

mcp-http-diary-server/
├── package.json
├── tsconfig.json
├── .env.example            # 环境变量模板(复制为 .env 填写)
├── Dockerfile              # 已支持公网部署(Render / Railway / 云服务器)
├── README.md
├── src/
│   └── index.ts            # MCP HTTP Server 主入口(全部逻辑)
├── scripts/
│   ├── setup-db.mjs        # 按顺序应用 supabase/migrations 下所有迁移
│   ├── check-schema.mjs    # 检查 diaries.content 列
│   └── test_new_tools.mjs  # 走真实 HTTP 链路的自检脚本
├── supabase/
│   └── migrations/
│       ├── 001_add_content_column.sql   # diaries.content
│       └── 002_companion_memory_columns.sql  # 新增记忆表细分列
└── test-*.js               # 旧版手写测试(可选)

快速开始

1. 安装

cd mcp-http-diary-server
npm install

2. 配置环境变量

cp .env.example .env

编辑 .env

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your_supabase_anon_key
PORT=3000
HOST=0.0.0.0
# USER_ID=test_couple        # 可选,记忆归属用户,默认 test_couple
# DATABASE_URL=postgresql://...  # 仅 db:setup 需要(Supabase 数据库连接串)

3. 应用数据库迁移(必须)

新工具依赖 companion_daily_logsshared_memories 的扩展列,需先应用迁移 (本地 .env 需额外提供 DATABASE_URL,即 Supabase Dashboard → Settings → Database → Connection string):

npm run db:setup

或直接在 Supabase SQL Editor 执行:

-- 注意:shared_memories 表在控制台建表时已自带 `event` 列(NOT NULL,存共同经历内容),
--       无需新增 content 列,save_shared_memory 直接写入 event。

ALTER TABLE public.companion_daily_logs
  ADD COLUMN IF NOT EXISTS events TEXT,
  ADD COLUMN IF NOT EXISTS user_state TEXT,
  ADD COLUMN IF NOT EXISTS mood_changes TEXT,
  ADD COLUMN IF NOT EXISTS topics TEXT;

NOTIFY pgrst, 'reload schema';

4. 编译运行

npm run build
npm start          # 生产:node dist/index.js
# 或开发模式(热重载源码)
npm run dev        # tsx src/index.ts

健康检查:

curl http://localhost:3000/health

可用工具(7 个)

保留 write_diary / get_diaries 用于兼容旧测试。新增 5 个长期记忆工具。

工具

写入表

说明

write_diary(content, mood?)

diaries

兼容旧接口:保存一篇日志

get_diaries(limit?)

diaries

兼容旧接口:获取最近日志(默认 10,最大 100)

save_memory

companion_memories

保存一条长期记忆

recall_memory

companion_memories

按分类 / 关键词召回历史记忆

save_daily_log

companion_daily_logs

保存每日聊天总结

save_shared_memory

shared_memories

保存共同经历

update_memory

companion_memories

按 id 更新已有记忆(避免重复累积)

save_memory(category, content, importance?, confidence?, source?)

  • category(必填,枚举):user_profile(用户信息) / preference(用户偏好) / personality(人格特点) / goal(长期目标) / skill(技能能力) / relationship(关系模式) / emotional_pattern(情绪模式) / conversation_style(聊天习惯)

  • content(必填):记忆正文

  • importance(可选,1–5,默认 3)

  • confidence(可选,0–1,默认 0.8)

  • source(可选,默认 conversation,如 user_stated

recall_memory(category?, keyword?, limit?)

  • category:按分类过滤

  • keyword:对 content 做不区分大小写的模糊匹配(ILIKE

  • limit(1–100,默认 20)

  • 返回按时间倒序的记忆列表,用于回复前获取用户信息

save_daily_log(log_date?, events?, user_state?, mood_changes?, topics?, relationship_state?)

  • log_date(可选,YYYY-MM-DD,默认今天)

  • events:当天重要事件

  • user_state:用户状态

  • mood_changes:情绪变化

  • topics:重要话题

  • relationship_state:关系状态

  • 代码会把各字段汇总进 summary 文本,同时落入各自的细分列

save_shared_memory(title, event, importance?)

  • title(必填):共同经历的标题

  • event(必填):经历的核心内容 / 描述(映射到 shared_memories.event,该列 NOT NULL)

  • importance(可选,1–5,默认 3)

update_memory(id, category?, content?, importance?, confidence?, source?)

  • id(必填,UUID 字符串):要更新的记忆 id(来自 recall_memory 返回)

  • 其余字段按需提供,仅更新传入的字段

  • 用于修正过期记忆(如"喜欢猫"→"喜欢狗"),避免无限累积重复记忆


数据库映射关系(实测真实 schema)

工具

真实列(已确认存在)

companion_memories

companion_memories

id(uuid), created_at, updated_at, user_id, category, content, importance, confidence, source

companion_daily_logs

companion_daily_logs

id(uuid), created_at, user_id, log_date, summary, relationship_state, events, user_state, mood_changes, topics

shared_memories

shared_memories

id(uuid), user_id, title, importance, event(NOT NULL,存经历正文;content 为早期误加的遗留列,未使用)

diaries(兼容)

diaries

id, created_at, user_id, mood, content

companion_daily_logs 的扩展列(events/user_state/mood_changes/topics)由迁移 002 添加。shared_memories 使用建表时已有的 event 列(NOT NULL),未新增列。 注意:shared_memories 原始表没有 created_at 列,时间以插入为准。 save_daily_log(user_id, log_date) 做 upsert:同一天重复保存会更新当天记录,不会触发唯一约束报错。


本地自检

# 先启动服务(另开终端)
npm run dev

# 再运行自检(自动等待服务就绪,覆盖 tools/list + 全部新工具写读)
node scripts/test_new_tools.mjs

自检会真实写入/读取 Supabase,结束后可手动清理测试产生的记忆行。


部署到公网

服务已支持 HOST / PORT 环境变量,可直接部署到公网,MCP 端点为:

https://你的域名/mcp

部署到 Render(推荐,详细步骤)

项目根目录已提供 render.yaml(Blueprint),可一键部署;也可在 Dashboard 手动创建。

A. 用 render.yaml 一键部署

  1. 把本项目推到 GitHub(.env 已被 .gitignore 忽略,密钥不会上传)。

  2. Render Dashboard → NewBlueprint → 连接该 GitHub 仓库 → Apply

  3. 在创建的服务里,给 SUPABASE_URL / SUPABASE_KEY 填入真实值(这两个在 render.yaml 中标记为 sync:false,需手动填;其余变量已带默认值)。

  4. 部署完成后,公网 MCP 端点即:

    https://<你的服务名>.onrender.com/mcp

B. 手动在 Dashboard 创建 Web Service

  1. NewWeb Service → 连接 GitHub 仓库。

  2. Runtime: Node;Build Command: npm install && npm run buildStart Command: npm start

  3. Health Check Path: /health(代码已提供 GET /health)。

  4. Environment Variables

    Key

    Value

    说明

    SUPABASE_URL

    你的 Supabase 项目 URL

    必填

    SUPABASE_KEY

    你的 Supabase anon key

    必填

    HOST

    0.0.0.0

    必填(公网监听)

    PORT

    不填

    Render 运行时自动注入,app 已读取

    USER_ID

    可选

    记忆归属用户,默认 test_couple

    CORS_ORIGIN

    可选

    默认允许所有来源

  5. 免费版(Free)有冷启动(约 30–50s),首次调用可能超时属正常;付费版无此问题。

Railway / Fly.io 配置类似:构建 npm install && npm run build、启动 npm start、设上述环境变量即可。

方式二:云服务器(VPS)

上传项目,安装依赖并构建后运行 npm start,确保 HOST=0.0.0.0PORT 对外开放。通过 http://你的公网IP:3000/mcp 访问。

方式三:Cloudflare Tunnel(免费临时域名)

cloudflared tunnel --url http://localhost:3000

得到 https://xxx.trycloudflare.com/mcp

方式四:ngrok

ngrok http 3000

得到 https://xxx.ngrok.io/mcp


MCP 协议支持

  • ✅ initialize / ping / tools/list / tools/call / notifications/

  • ✅ 兼容 POST /POST /mcp 两个入口

环境变量

变量

必填

说明

默认值

SUPABASE_URL

Supabase 项目 URL

-

SUPABASE_KEY

Supabase anon key

-

PORT

HTTP 监听端口

3000

HOST

监听地址

0.0.0.0

USER_ID

记忆归属用户

test_couple

DATABASE_URL

仅 db:setup

Supabase 数据库连接串

-

CORS_ORIGIN

CORS 来源(true 表示允许全部)

true

技术栈

  • Express.js + TypeScript

  • Supabase JS Client

  • MCP Streamable HTTP(无状态,每次请求新建 Server 实例)

  • Zod 参数校验

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    C
    maintenance
    An MCP server that stores project memory in Supabase, allowing AI tools to persist context, notes, and decisions across sessions. Enables Claude Code, Codex, and similar assistants to maintain long-term project continuity through persistent memory storage.
    Last updated
    2
  • A
    license
    -
    quality
    D
    maintenance
    MCP server for JournalOwl that enables AI-powered journaling integration, allowing users to create, search, and browse journal entries, access weekly reviews, and get personalized suggestions directly from their AI assistant.
    Last updated
    14
    MIT

View all related MCP servers

Related MCP Connectors

  • MCP-native open-source Notion alternative: read & write pages, databases and kanban boards.

  • Person-owned, portable AI memory as a remote MCP server, readable and writable by any MCP client.

  • MCP-native collaborative markdown editor with real-time AI document editing

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/panhy1215-sys/mcp-http-diary-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server