MCP 智能体集成
VecminDB 为 Cursor、Claude Code 等所有兼容 MCP(Model Context Protocol)的智能体工具提供零代码接入:配置一次连接,说一句话安装记忆规则,之后智能体自动把有价值的对话沉淀为长期记忆,并在每次回答前先检索你的记忆库。
1. 添加 MCP 连接(唯一的手工步骤)
所有工具的连接参数都一样:http://<host>:5520/api/v1/mcp/sse + 认证头 x-api-key。差异只在「在哪里填」:
Cursor —— 在项目根目录创建 .cursor/mcp.json(或 ~/.cursor/mcp.json 全局生效),重启 Cursor:
{
"mcpServers": {
"vecmindb": {
"url": "http://localhost:5520/api/v1/mcp/sse",
"headers": { "x-api-key": "<你的 Admin API Key>" }
}
}
}
Claude Code —— 在项目根目录创建 .mcp.json:
{
"mcpServers": {
"vecmindb": {
"url": "http://localhost:5520/api/v1/mcp/sse",
"headers": { "x-api-key": "<你的 Admin API Key>" }
}
}
}
或用 CLI 一条命令:
claude mcp add vecmindb --transport sse \
--url http://localhost:5520/api/v1/mcp/sse \
--header "x-api-key: <你的 Admin API Key>"
Admin API Key 在容器首次启动时自动生成并打印在日志中(docker logs vecmindb | grep "Your Admin API Key"),或在启动时通过 VECMIN__SECURITY__ADMIN_KEY 环境变量指定。远程部署请启用 TLS(见安装部署文档)。
2. 一句话安装记忆规则
连接配好后,对智能体说一句话:
安装 vecmindb 记忆规则
智能体会调用内置的 get_memory_rules 工具,服务器返回修正版规则块 + 确切写入路径(Claude Code → CLAUDE.md;Cursor → .cursor/rules/vecmindb-memory.mdc)。智能体先把内容展示给你确认,再写入文件——只替换标记段,不碰文件其它内容;重复执行逐字一致、不产生重复块。写入后开一个新会话即可生效。规则由服务器生成、随产品版本升级,支持中英双语(lang=en / lang=zh)。
立即体验:60 秒见证「它记住了」
① 存一条——对智能体说:「记住:客户 Acme 要求私有化部署,数据不能出内网。」→ 它会调用 store_memory(长期约束自动打上 is_factual 强锚定)。
② 验证没丢——开一个新会话,问:「Acme 对部署有什么要求?」→ 它调用 search_memory,用你上一会话存的事实作答——本会话本来对此一无所知。
③ 亲眼看它工作——在服务器上实时观察每一次记忆读写:
docker logs -f vecmindb 2>&1 | grep "tools/call"
3. 规则生效后智能体会做什么
- 每次回答前先检索:调用
search_memory(top_k 3~5)检索相关记忆,不分主题——项目约束、客户偏好、菜谱都是记忆。服务端有相关性门槛(memory.search_min_score,默认 0.70),无关话题返回"无相关记忆",智能体直接回答。 - 有信息量的对话自动落库:调用
store_memory,正文为蒸馏摘要,关键原文/数据/承诺挂在metadata.detail;长期约束、客户要求、架构决策标记is_factual:true(强锚定,豁免遗忘)。纯寒暄不写。 - 投射守卫:回答与 VecminDB 无关的问题时,不套用 VecminDB 项目语境——记忆按主题使用。
- 诚实条款:读写失败时如实报告,不假装成功。
4. 可用工具
接入后可见 10 个核心工具:store_memory、search_memory、list_memories、get_memory、forget、update_memory、memory_status、consolidate、register_factuality_template / remove_factuality_template、get_memory_rules。多模态工具(store_media / get_media / search_media_by_image)默认关闭,需在配置中开启 media.clip_collection。
5. 验证自动读写
服务端记录每一次 MCP 工具调用,部署后可实时观察:
docker logs -f vecmindb 2>&1 | grep "tools/call"
6. 团队与多租户 —— 每个团队一份共享记忆
每个 API key 对应一个租户和一个记忆集合(mem_<租户名>)。同一团队的成员共用一个 key,即共享同一记忆空间;不同租户默认相互隔离。按团队开租户得到共享大脑,按项目开租户得到硬隔离。
① 创建租户(管理员一条命令;引擎自动建集合、签发 key 并持久化到 config.yml,重启不丢;key 只返回一次):
curl -X POST http://<host>:5520/api/v1/tenants \
-H "x-api-key: <ADMIN_KEY>" -H "Content-Type: application/json" \
-d '{"name": "acme-team"}'
# → {"tenant":"acme-team","collection":"mem_acme-team","key":"<uuid>"}
② 分发 key——成员把 key 填进各自 MCP 配置的 x-api-key(见第 1 节),即接入同一份共享记忆。
③ 跨团队共享(可选)——租户所有者可用 set_tenant_grant 工具把自己的集合授予另一个已存在的租户只读访问(或在 config.yml 声明 tenant_grants:)。两条硬保证:写入永远留在调用方自己的租户集合;只能授予自己拥有的集合,无法代他人授权。
Agent Integration (MCP)
VecminDB plugs into Cursor, Claude Code, and any MCP-compatible agent tool with zero code: configure the connection once, install the memory rules with a single sentence, and your agent automatically distills valuable conversation turns into long-term memory — and searches that memory before every answer.
1. Add the MCP connection (the only manual step)
Every tool takes the same two parameters: http://<host>:5520/api/v1/mcp/sse plus the x-api-key header. Only the location differs:
Cursor — create .cursor/mcp.json in the project (or ~/.cursor/mcp.json for all projects), then restart Cursor:
{
"mcpServers": {
"vecmindb": {
"url": "http://localhost:5520/api/v1/mcp/sse",
"headers": { "x-api-key": "<your Admin API Key>" }
}
}
}
Claude Code — create .mcp.json in the project root:
{
"mcpServers": {
"vecmindb": {
"url": "http://localhost:5520/api/v1/mcp/sse",
"headers": { "x-api-key": "<your Admin API Key>" }
}
}
}
…or add it from the CLI:
claude mcp add vecmindb --transport sse \
--url http://localhost:5520/api/v1/mcp/sse \
--header "x-api-key: <your Admin API Key>"
The Admin API Key is generated on first start and printed to the container logs (docker logs vecmindb | grep "Your Admin API Key"), or pinned via the VECMIN__SECURITY__ADMIN_KEY environment variable. For remote deployments, enable TLS (see the Installation & Ops guide).
2. Install the memory rules with one sentence
Once connected, tell your agent:
Install vecmindb memory rules
The agent calls the built-in get_memory_rules tool; the server returns the corrected rule block plus the exact file to write (Claude Code → CLAUDE.md; Cursor → .cursor/rules/vecmindb-memory.mdc). The agent shows you the block first and writes it only after your confirmation — just the marked section is replaced, nothing else in the file is touched, and re-running never duplicates the block. Then start a new session. Rules are server-generated, upgrade with the product, and ship in both English and Chinese (lang=en / lang=zh).
Try it now: 60 seconds to your first "it remembered!"
① Store something — tell your agent: "Remember: customer Acme requires on-prem deployment and data must never leave our intranet." → it calls store_memory (long-term constraints automatically get the is_factual strong anchor).
② Prove it survived — open a new session and ask: "What are Acme's deployment requirements?" → it calls search_memory and answers with the fact you stored, even though this session knew nothing about it.
③ Watch it live — observe every memory read & write on the server in real time:
docker logs -f vecmindb 2>&1 | grep "tools/call"
3. What your agent does once the rules are active
- Search before every answer: calls
search_memory(top_k 3–5) for relevant memories — all topics qualify (project constraints, client preferences, recipes). A server-side relevance floor (memory.search_min_score, default 0.70) returns "no relevant memory" for unrelated topics, so the agent answers directly. - Store after informative turns: calls
store_memorywith a distilled summary as the text, key excerpts/data/commitments attached inmetadata.detail; long-term constraints, client requirements, and architecture decisions are flaggedis_factual:true(strong anchor, exempt from forgetting). Pure greetings are skipped. - Projection guard: when answering questions unrelated to VecminDB, the agent does not import VecminDB project context — memories are used by topic.
- Honesty clause: failed reads or writes are reported honestly, never faked.
4. Available tools
10 core tools are visible after integration: store_memory, search_memory, list_memories, get_memory, forget, update_memory, memory_status, consolidate, register_factuality_template / remove_factuality_template, and get_memory_rules. Multimodal tools (store_media / get_media / search_media_by_image) are disabled by default and require media.clip_collection in the configuration.
5. Verify automatic reads & writes
The server logs every MCP tool call. Watch it live after deployment:
docker logs -f vecmindb 2>&1 | grep "tools/call"
6. Teams & multi-tenant — one memory per team
Every API key maps to one tenant and one memory collection (mem_<tenant>). Team members sharing a key work in the same memory space; different tenants are isolated by default. One tenant per team gives the team a shared brain; one tenant per project gives hard isolation.
① Create a tenant (admin, one command; the engine provisions the collection, issues the key and persists it into config.yml — restarts survive; the key is returned once):
curl -X POST http://<host>:5520/api/v1/tenants \
-H "x-api-key: <ADMIN_KEY>" -H "Content-Type: application/json" \
-d '{"name": "acme-team"}'
# → {"tenant":"acme-team","collection":"mem_acme-team","key":"<uuid>"}
② Distribute the key — each member pastes it as the x-api-key in their MCP config (see section 1) and connects to the same shared memory.
③ Cross-team sharing (optional) — a tenant owner can grant another existing tenant read-only access to their own collection with the set_tenant_grant tool (or declare tenant_grants: in config.yml). Two hard guarantees: writes always stay in the caller's own tenant collection, and you can only ever grant a collection you own.