feat(memory): expose expert memory as an MCP server for external agents - #356
feat(memory): expose expert memory as an MCP server for external agents#356ArvinQi wants to merge 4 commits into
Conversation
Add a memory MCP server (Streamable HTTP at /mcp/memory) so external agents (coding agents, bots) can read/write Octop expert memory directly, aligned with the in-process MemoryService capabilities. Tools (per expert, bound at connect time via X-Octop-Agent-Id header): - memory_recall(query, limit): full recall pipeline (tokenize + FTS + rerank), returns structured memories + rendered markdown - memory_save(content, source, topic?): persist a structured fact directly into the atom/tree (durable, no extraction) - memory_capture(content, source, session_id?): write an L0 raw event (extraction pipeline); visible immediately via memory_search_raw - memory_search_raw(query, limit): FTS-search L0 raw events (capture visible before extraction) - memory_update(atom_id, new_content, source): deprecate old atom + save new Auth: independent token via OCTOP_MEMORY_MCP_TOKEN (fail-closed if unset); authorization via Authorization: Bearer or X-Octop-Memory-Token. Implementation: - Lives in infra/agents/memory_mcp.py (no api-layer dependency; opens the agent Memory instance via open_memory_kwargs) - One FastMCP per agent, routed by X-Octop-Agent-Id header at /mcp/memory - DNS rebinding protection disabled (server runs behind a reverse proxy) - streamable_http task groups wired into the FastAPI lifespan Tests: tests/unit/agents/test_memory_mcp.py (tools, header routing, token middleware, unified mount).
保留两者: - main: enable_mobile 路由挂载 - PR: memory_mcp MCP server 挂载
- Add assert for server.services to satisfy mypy strict mode - Add return type annotation to _memory closure
|
hi 评估了一下这个PR 有几个想要询问的问题 |
hi 谢谢 review,两个问题都问到点子上了,简单说一下:
设计文档已整理(本 PR diff 里的 Octop 专家记忆 MCP 服务设计说明(PR #356)1. 背景与目标Octop 专家会积累大量记忆(事实、对话、决策、规则),目前只有 Octop 站内 agent / 本 PR 在标准 MCP 协议(Streamable HTTP,端点 2. 总体设计(一句话)读走完整召回管线,写分两条通道,晋升流程完全留在服务端。
3. 记忆晋升边界:MCP 不干预晋升流程
时效说明(明确契约)外部 capture 的晋升时效依赖周期 sweep,MVP 阶段接受"分钟~小时级"延迟; 4. 两条写通道站内默认记忆路径是"每轮对话结束提取 raw event → 候选评审 → 晋升",站内不给 agent 4.1 capture 通道(学习型记忆)
4.2 规则通道(指令型记忆)— save / update
5. MVP 工具集与调用契约MVP 必带: 6. 专家绑定与鉴权
7. 与站内默认记忆路径的关系
8. 后续演进(非 MVP)
9. 实现说明
|
Summary
Adds a memory MCP server (Streamable HTTP at
/mcp/memory) so externalagents (coding agents, bots, other AI tools) can directly read / write /
update Octop expert memory, aligned 1:1 with the in-process
MemoryServicecapabilities. Every write stamps asourcemarker that istraceable on recall.
Why
Octop experts accumulate rich memory (facts, conversations, decisions), but
today only the Octop dashboard / in-process agent can access it. External
agents that need to reuse that expertise (e.g. a coding agent asking a
business expert's accumulated knowledge) have no way in. This PR exposes the
same memory surface over the standard MCP protocol so any MCP-capable agent
can join the loop.
What
src/octop/infra/agents/memory_mcp.py— FastMCP serverbound to one expert per connection, plus token auth and header routing.
api/app.py(build_app) at/mcp/memory, withstreamable_httptask groups wired into the FastAPI lifespan.tests/unit/agents/test_memory_mcp.py(13 tests).Tools
memory_recall(query, limit=5)recall_for_promptmemory_save(content, source, topic?)Memory.storememory_capture(content, source, session_id?)Memory.add_rawmemory_search_raw(query, limit=10)Memory.search_rawmemory_update(atom_id, new_content, source)deprecate_atom+storeExpert binding & auth
X-Octop-Agent-Idheader (callers neverpass an agent id per tool call).
OCTOP_MEMORY_MCP_TOKEN(fail-closed),Authorization: Bearer.raw vs atom (for callers)
memory_capture→ L0 raw event (evidence layer), distilled by extraction;visible immediately via
memory_search_raw.memory_save→ atom/tree directly (durable, no extraction).Implementation notes
infra/agents/(no api-layer dependency), opens Memory viaopen_memory_kwargs+Memory(...).streamable_http_pathcollapsed to/(endpoint =/mcp/memory).Usage example
{ "mcpServers": { "octop-memory": { "type": "streamable_http", "url": "http://<host>/mcp/memory/", "headers": { "Authorization": "Bearer <token>", "X-Octop-Agent-Id": "<expert-id>" } } } }Target branch
develop(feature / fix — default)main(release/*orhotfix/*only)Type of change
Test plan
make allpasses locallyChecklist
CHANGELOG.md(if user-facing)