smritea mcp
MCP(模型上下文协议)服务器 smritea --让AI助手(Claude Code、Cursor等)直接访问您的smritea内存存储。
______________________________________________________________________
安装
步骤1--运行init
npx -y smritea-mcp init此交互式向导提示输入三个值:
API base URL [https://api.smritea.ai]:按Enter键使用默认值(https://api.smritea.ai).如果您是自托管smritea,请在此处输入您的自定义URL。
API key:粘贴您的smritea API密钥(必需)。您可以在API键下的smritea仪表板中找到它。
Your name or user ID (used when you say "I prefer…", "I like…") [optional]:可选。如果设置,此值将自动用作 user_id 当你在对话中提到自己时(“我更喜欢黑暗模式”,“我喜欢Python”),所以关于你的记忆会存储在一个一致的ID下,而无需传递 user_id 每次都明确。
成功后,凭据将保存到 ~/.smritea/mcp-config.json.
步骤2——在AI客户端注册服务器
克劳德代码 --添加到 ~/.claude.json 在...之下 mcpServers 按键:
{
"mcpServers": {
"smritea": {
"command": "npx",
"args": ["-y", "smritea-mcp", "serve"]
}
}
}光标/网络连接客户端(SSE模式) --首先启动服务器,然后将光标指向它:
# Start the SSE server (default port 3000, runs in background)
npx -y smritea-mcp serve-sse &
# Custom port
npx -y smritea-mcp serve-sse 8080 &然后添加到 ~/.cursor/mcp.json (或光标设置→ MCP):
{
"mcpServers": {
"smritea": {
"url": "http://localhost:3000/sse"
}
}
}备注: serve-sse 必须在启动Cursor之前运行。每个客户端连接都有自己的隔离会话——您可以在同一端口上同时连接多个客户端。步骤3——设置活动应用程序(每个项目一次)
在与Claude Code的对话中,运行:
Use the select_app tool with app_id ""这写道 .smritea/config.json 在您的项目目录中(自动gitignored),以便该项目中的所有内存操作都适用于正确的应用程序。
______________________________________________________________________
配置
smritea-mcp使用两层配置系统。
用户范围(~/.smritea/mcp-config.json)
创建一次 npx smritea-mcp init。存储跨所有项目共享的凭据。
{
"api_key": "sk-...",
"base_url": "https://api.smritea.ai",
"first_person_user_id": "alice"
}first_person_user_id 是可选的。设置后,它会自动用作 user_id 对于用户引用自己(“我更喜欢…”、“我喜欢…”)而不显式传递 user_id.
项目范围(.smritea/config.json)
由按项目创建 select_app 工具。确定哪个smritea应用程序在此项目中接收内存操作。自动识别。
{
"app_id": "app_abc123",
"app_name": "My App"
}环境变量覆盖
| 变量 | 覆盖 |
|---|---|
SMRITEA_API_KEY | api_key 在用户配置中 |
SMRITEA_BASE_URL | base_url 在用户配置中 |
SMRITEA_APP_ID | app_id 在项目配置中 |
SMRITEA_FIRST_PERSON_USER_ID | first_person_user_id 在用户配置中 |
______________________________________________________________________
工具
select_app
为当前项目设置活动的smritea应用程序。此项目中的所有后续内存操作都将使用指定的应用程序。
写入 .smritea/config.json 在当前工作目录中,并创建 .smritea/.gitignore 因此,配置永远不会被意外提交。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
app_id | string | Yes | smritea应用程序ID(例如。 app_abc123) |
app_name | string | 否 | 应用程序的可选显示名称 |
示例
Use the select_app tool with app_id "app_abc123" and app_name "My Project"______________________________________________________________________
list_apps
显示此项目的当前活动应用程序。
备注:通过API密钥身份验证列出所有应用程序尚不可用。API密钥的作用域为单个应用程序。使用 select_app 切换应用程序。参数:无
______________________________________________________________________
add_memory
为活动的smritea应用程序添加新内存。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
content | string | 是 | 要存储的内存内容 |
actor_id | string | 否 | 与此内存关联的演员UUID。默认为已配置 first_person_user_id 当省略时。 |
actor_type | string | 否 | 演员类型: user, agent,或 system.需要时 actor_id 提供。默认为 user 当旁边省略时 actor_id. |
metadata | object | 否 | 可选键值元数据 |
示例
Add a memory: "User prefers dark mode and uses vim keybindings" for actor_id "550e8400-e29b-41d4-a716-446655440000" actor_type "user"______________________________________________________________________
search_memories
从语义上搜索记忆。返回按相关性得分排序的结果。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
query | string | 是 | 自然语言搜索查询 |
actor_id | string | 否 | 将结果筛选到特定参与者(UUID)。默认为已配置 first_person_user_id 当省略时。 |
actor_type | string | 否 | 按演员类型筛选: user, agent,或 system.默认为 user 当旁边省略时 actor_id. |
limit | number | 否 | 返回的最大结果数 |
method | string | 否 | 搜索方法: quick_search, deep_search, context_aware_search |
threshold | number | No | 最小相关性得分(0.0–1.0) |
graph_depth | number | 否 | 图形遍历深度覆盖 |
conversation_id | string | 否 | 筛选到特定对话 |
示例
Search memories for "editor preferences" for actor_id "550e8400-e29b-41d4-a716-446655440000" actor_type "user", limit 5______________________________________________________________________
get_memory
按ID检索单个内存。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
memory_id | string | Yes | 内存ID(例如。 mem_abc123) |
______________________________________________________________________
delete_memory
按ID删除内存。此操作是不可逆的。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
memory_id | string | 是 | 要删除的内存ID |
______________________________________________________________________
运作原理
smritea-mcp是一个TypeScript mcp服务器,它封装了 smritea TypeScript SDK 并将存储器操作作为MCP工具公开。
它支持两种传输方式:
标准 (默认值,适用于Claude Code和本地客户端):
所有JSON-RPC通信都通过stdout进行。所有日志记录都会进入stderr,因此它永远不会干扰MCP协议流。
AI assistant (Claude Code)
↕ JSON-RPC over stdio
smritea-mcp serve
↕ HTTPS
smritea TypeScript SDK → smritea Cloud API上海证券交易所 (适用于Cursor和网络连接的客户端):
服务器作为HTTP服务器运行。客户端打开持久 GET /sse EventStream连接,用于接收服务器消息,并通过以下方式发送消息 POST /messages?sessionId=每个客户端连接都有自己的隔离McpServer实例。
AI assistant (Cursor / other)
↕ SSE stream (GET /sse) + POST /messages
smritea-mcp serve-sse
↕ HTTPS
smritea TypeScript SDK → smritea Cloud API