[Feature]: Expose peer_id on the MCP remember tool for project-scoped memory writes
Issue Origin
Observed or reproduced in a real environment.
Problem Statement
In multi-agent setups, several agent clients share one user identity and are differentiated only by the x-openviking-actor-peer header. Reads are peer-aware: find/search accept peer_scope / other_peer_penalties, and the actor peer from the header scopes retrieval.
Writes via the MCP remember tool cannot target a peer at all. StoreMessage only carries role + content (still true in v0.5.3), so everything submitted through remember lands in the user-global namespace, silently mixing project-scoped memories from all peers. The underlying session API already supports attribution — Session.add_message(role, parts, peer_id=None, ...) / add_message_async(...) in openviking/session/session.py — the parameter is simply not exposed on the MCP tool surface.
We have carried a tiny local patch for this since v0.4.x and verified today (against v0.5.3 source) that it is still required.
Related: #5613 covers the extraction-layer side of the same gap (an extraction operation that omits peer_id widens single-peer memory to user-global). This request is the input-layer side: give callers a deterministic way to supply the peer on remember.
Proposed Solution
Add an optional peer_id to StoreMessage and pass it through to add_message / add_message_async. Three lines against v0.5.3 (openviking/server/mcp_endpoint.py):
class StoreMessage(BaseModel):
role: Literal["user", "assistant"] = Field(description="Message role")
content: str = Field(description="Message text content")
+ peer_id: Optional[str] = Field(default=None, description="Peer ID for project-scoped memory isolation. Set to group this memory under a specific project/peer.")
add_async = getattr(session, "add_message_async", None)
if callable(add_async):
- await add_async(msg.role, [TextPart(text=msg.content)])
+ await add_async(msg.role, [TextPart(text=msg.content)], peer_id=msg.peer_id)
else:
- session.add_message(msg.role, [TextPart(text=msg.content)])
+ session.add_message(msg.role, [TextPart(text=msg.content)], peer_id=msg.peer_id)
Optional hardening: when the caller omits peer_id, the MCP layer could fall back to ctx.actor_peer_id (the header already reaches this endpoint) so agent clients that set the header get attribution without changing their tool calls. That fallback would also shrink the window described in #5613.
Alternatives Considered
- Carrying a local patch per release (what we do today) — works, but must be re-derived against every new image and is easy to lose during upgrades.
- Teaching each agent client to call
writeto a peer-scoped URI directly — bypasses the extraction pipeline's dedup/update benefits ofrememberand is error-prone across clients. - Relying on extraction-layer inference (#5613) — helps only when all messages unambiguously belong to one peer; explicit input is deterministic and composes with it.
Feature Area
Core (Client/Engine)
Use Case
A self-hosted OpenViking instance backs multiple agent clients (coding agents, bots, automation) that connect as the same user with distinct x-openviking-actor-peer identities, so each project/agent keeps an isolated memory drawer. Reads are already isolated per peer; with this change, remember writes can be attributed to the right peer instead of all pooling into user-global, which keeps per-project memories from cross-contaminating.
Example API
# MCP tool call: remember
{
"messages": [
{
"role": "user",
"content": "Prefer SQLite WAL mode for all new services in this project.",
"peer_id": "project-alpha"
}
]
}
Additional Context
- Verified
StoreMessagelackspeer_idand the write path drops attribution in both v0.4.23 and v0.5.3 (openviking/server/mcp_endpoint.py). - The proposed passthrough relies only on the existing
peer_idparameter ofSession.add_message/add_message_async, so no storage or API changes are needed beyond the tool schema. - Happy to turn this into a PR if the approach sounds good.
Contribution
- [x] I am willing to contribute to implementing this feature
Opened #6999 for this — adds optional peer_id: Optional[str] = None to StoreMessage in openviking/server/mcp_endpoint.py and forwards it only when explicitly set by the caller so default global writes stay unchanged.
Thanks for the report and the contribution in #6999.
We are keeping the existing product decision from #3326: MCP does not expose peer-level concepts. remember accepts messages for user-level extraction; the actor-peer header does not assign a project identity to those messages.
Project attribution belongs to plugin/session message capture, where peer_id is supplied explicitly when adding messages before session commit. Adding an optional field to remember would expand the MCP contract, rather than correct an omitted argument within its supported scope. We are not accepting that API expansion, so closing as not planned, consistent with the earlier decision.