# `Reminisce.MCP.Server`
[🔗](https://github.com/NoeticEcho/reminisce-elixir/blob/v0.6.0/lib/reminisce/mcp/server.ex#L4)

The MCP face: JSON-RPC 2.0 over stdio, one message a line, no MCP library.

**One server is one owner.** The owner is fixed when the server starts and is
never taken from a tool call: no tool accepts an `owner`, and a call that
names one is refused with `owner_is_fixed`. An agent connected to one
owner's memory cannot write into another's.

Eight tools:

| tool | does |
|---|---|
| `memory_remember` | `Reminisce.remember/3` — the secret guard and the store's policy run |
| `memory_intend` | `Reminisce.remember/3` with the aspect `prospective` fixed: an intention |
| `memory_affect` | `Reminisce.affect/4` with the basis `generated` fixed: the agent's own appraisal |
| `memory_recall` | `Reminisce.recall/4` (read-only), with the connection's focus |
| `memory_fulfil` | `Reminisce.fulfil/4` — nothing is deleted |
| `memory_forget` | `Reminisce.forget/4` — nothing is deleted |
| `memory_why` | `Reminisce.why/4` (read-only) |
| `memory_persona` | `Reminisce.persona/3` for an audience (read-only), without the reason or the actor ids |

`memory_affect` takes no `basis`: an affect written over MCP is a model's
reading, `generated`, always, so a tool result that claims to be a person
cannot become that person's own report (docs/spec.md §B.5). It takes no
`reviewed_by`, so a write held by an objection stays held.

No tool writes the persona DNA (docs/spec.md Appendix C): a strand, a
version and a reading are the keeper's, written in Elixir through the host.
`memory_persona` reads it. It answers a version's adopted strands for its
audience, never a version's `reason` or an actor id, and a `forked_from`
that names no other owner (§C.8, §C.7).

**One connection is one session.** The server holds a `Reminisce.Focus`
for its connection, as process state, and hands it from each recall to the
next (docs/spec.md §A.5); nothing of it is written. It adds the event
`session_start` to the connection's first recall.

`withdraw` is not a tool: withdrawal is a person's right, exercised through
the host, not an action an agent takes on its own reasoning.

A tool's `structuredContent` is exactly what `Reminisce.Output` makes of the
direct Elixir call's answer, and its text content is the same map as JSON.
Refusals are tool errors that name the rule, never echoing the words.

Run it with `mix reminisce.mcp`, or from code:

    Reminisce.MCP.Server.run(store, {"agent", "alice"})

# `handle_line`

Handles one line as the first of a connection; answers the reply line, or
`nil` for a notification. See `step/2` for a connection's lines in turn.

# `new`

Starts a server state for `owner`, validating the tool declarations first.

# `run`

Serves until `input` closes. Reads one JSON-RPC message a line from `input`
and writes each reply as one line to `output`.

Answers `:ok` when the input ends, and `{:error, {:read, reason}}` when it
cannot be read (after a last error reply, id `null`, code -32000).

The server is byte-transparent: both devices are put in latin1 mode, so a
line's bytes reach the JSON parser exactly as they were sent and a reply's
bytes leave exactly as they were encoded, whatever the locale. A line that
is not valid UTF-8 is a parse error.

`:stdio` is read through a port on file descriptor 0, not through the VM's
standard input, which would collect a whole line, however long, before
handing any of it over. Nothing else in the VM may read standard input
while the server runs.

When it returns, both devices have their encoding back, and the logger
filter it installs while it reads `:stdio` is gone: a host that calls it
from code finds its output as it left it.

# `step`

Handles one line; answers `{reply, state}`: the reply line (or `nil` for a
notification) and the state to handle the connection's next line with,
which carries its focus.

# `tools`

The tool declarations, as data. Given a store, `memory_remember`'s and
`memory_recall`'s `aspects` name that store's aspects, as an enum and in
their description: what `tools/list` answers.

# `tools`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
