memory: a search or save can name its project, and every answer says whose and where (Norethcy on X, #6392)

The memory tools had no target-project argument and no way to see the
caller context they resolved, so a scoped migration run from one project
couldn't keep memories for another or check where they went.

- memory_search and memory_save take `project`: a folder on this
  computer (absolute, or relative to the caller's own folder), or the key
  of a project memory knows (github.com/owner/repo, with or without
  project:, or a project's one name). A project named goes with scope
  project (a save's default then) or a search's all; global or agent with
  a project is refused, and an unknown project says which ones memory
  knows.
- Answers name what was used: a memory reads "this project (<key>)" and
  "only for you (<agent>)", and a search ends "(looked in: everywhere,
  project <key>, agent <id>)".
- New read-only memory_context: the agent the server takes the caller
  for and how it was found (router _meta, magpie mcp memory's initialize,
  key/User-Agent, the session's initialize), the project with its folder
  and source, the scopes a search looks in and the server version, as
  text and structuredContent. Given `project`, it shows that one.
- HTTP and stdio are the same server (magpie mcp memory relays), and
  OwnMCPTools lists memory_context with the others.

Run (mote, -tags nogui unless noted):
- TestMemoryMCPProjectArgumentAndContext (new): folder, key and relative
  folder; the caller's own project untouched; refusals; memory_context's
  text and structuredContent; tools/list. Red with the project argument
  ignored by hand.
- TestMemoryBridgeContextAndProject (new): the real gateway behind
  magpie mcp memory over stdio, initialized as codex as in the report.
- go test ./internal/browsermcp ./internal/cli ./internal/library: ok;
  go test -run 'Memory|OwnMCP|Hub|RootDirs|Tool' ./internal/gateway: ok.
- Windows (xiaomi-gpu, win-run): the new gateway, browsermcp and cli
  tests ok (a test's own unquoted Windows path was fixed on the way).
- go vet darwin, linux nogui, windows for the four packages; gofmt.
Not tried: Codex desktop itself over /mcp/run/magpie-memory; the full
suite runs after the tag.
This commit is contained in:
yetone
2026-11-13 12:29:04 +08:00
parent e39b9d5df7
commit 72facf72e2
6 changed files with 368 additions and 31 deletions
+13 -1
View File
@@ -43,7 +43,7 @@ and refuses empty or over-long text, an unknown kind and a bad scope
### MCP server
[internal/gateway/memory_mcp.go](../../internal/gateway/memory_mcp.go):
`memory_search`, `memory_save`, `memory_forget`, Streamable HTTP at
`memory_search`, `memory_save`, `memory_forget`, `memory_context`, Streamable HTTP at
`MemoryMCPPath` (`/mcp/magpie/memory`), served like the search server
(`serveMCP`) but to the agents on this computer alone, as the hub gives it
(`HereOnly`): memory is what is known about this computer's user, and its
@@ -58,12 +58,24 @@ away (`TestMemoryMCPGuarded`).
which relays stdio to the gateway with the folder the agent started it in
(`X-Magpie-Cwd`) and the client name from `initialize`
(`X-Magpie-Mcp-Client`).
- `magpie tool memory_*` names its folder the same way, and reads an
answer sent as an event stream, answering a server's roots/list
(`TestToolMemoryThroughTheGateway`, #6049).
- Behind the [MCP router](mcp-router.md) the hub passes the caller in the
call's `_meta` instead (`HubRootsMeta`, `HubClientMeta`;
`TestMemoryMCPHubMetaNamesTheProject`).
- Without a folder the server can't name the project, nor the agent without
a client name: such a save says so instead of guessing, and a save with
no scope is kept for everyone (`TestMemoryMCPSaysWhatItCantKnow`).
- A search or save may name another project (`project`: a folder,
absolute or under the caller's, or a key memory knows;
`memoryCaller.inProject`), so a migration run from one project keeps
memories for another. A project named goes with scope project (or a
search's all). Every answer names what it used: a memory's line says
`this project (<key>)` and `only for you (<agent>)`, and a search ends
`(looked in: …)`. `memory_context` says who the caller is taken for,
the project, and how each was found, as text and `structuredContent`
(`TestMemoryMCPProjectArgumentAndContext`).
- A save through MCP is active at once, origin `agent`.
### Other memory services