Read tools with compact transcript rows and tokenizer budgets (#14) #27

Merged
svc-agent-writer merged 1 commit from issue-14-read-tools into main 2026-11-12 23:40:25 +00:00

Closes #14.

What this adds

The api process and its five read tools, over stateless Streamable HTTP with a bearer token: messages_status, messages_chats, messages_recent, messages_search and messages_context.

  • messagesmind api --config FILE binds the one address that [server] states, on port 8420 unless the config sets another, and serves the one path /mcp (ADR 0011). [server] is now required for every verb.
  • Every page is text with no structured copy. A transcript has a legend, one date line for each day, one row for each message with its flags, and a footer with a keyset cursor.
  • messages_search returns pointers and no text. messages_context expands a pointer.
  • The read token reaches the tools. The evidence token does not.

Security controls

  • Each call opens the store in reader mode for one read transaction. The api holds no client code, and a test follows every module that the api loads.
  • A foreign Host gets 421 and a foreign Origin gets 403. The allow-lists of the guard are stated in code.
  • The api does not start when a FASTMCP_ variable, or a .env file in the working directory, changes a setting of the MCP framework. Such a setting can turn the Host and Origin checks off.
  • Every refused call answers Error: code=<code>. No reply repeats an argument, a tool name that the caller sent, a file path or the message of a fault.
  • The log holds one line for each call: the tool, the line count and the code. One handler passes the records of the service and of uvicorn, and drops every record of a library. A fault prints its class only.
  • Message text is one bounded line with no |, so it cannot forge a row, a flag or a footer.

Acceptance criteria of #14

Criterion Test
A tokenizer budget for a transcript row, for a default page of each tool and for the tool list tests/test_server.py, the four budget tests
The tokenizer is pinned and runs offline tests/test_layout.py, the vocabulary hash and the offline loader
messages_search returns no body; messages_context expands a pointer tests/test_views.py
Every read tool refuses the evidence token tests/test_server.py
Paging shows every row once when rows share one timestamp tests/test_views.py
A redacted row keeps its sender, time and direction tests/test_views.py, for a received row and a sent row

Points for the reviewer

  1. The Kit cursor is plain text. It costs about 20 tokens less on every page. It replaces the earlier rule that a cursor holds no readable key. The cursor holds a date and local ids that the page already shows.
  2. The tokenizer vocabulary is a file in the repository. tests/tokenizer/o200k_base.tiktoken is 3.6 MB. Its publisher states no licence for the file. tests/tokenizer/README.md records its source and its SHA-256.
  3. A tool error is text with isError false, as People Mind does it. The MCP specification asks for isError true.
  4. Times print in UTC. There is no timezone option.
  5. The Host allow-list for a published name is not built. It belongs to the hardening slice. Today the api accepts the bind address and the loopback names.

Checks

make check is green on macOS: 182 tests. Mutation runs prove that the tests for the log filter, the fault formatter and the framework-settings refusal fail when the control is removed.

🤖 Generated with Claude Code

Closes #14. ## What this adds The api process and its five read tools, over stateless Streamable HTTP with a bearer token: `messages_status`, `messages_chats`, `messages_recent`, `messages_search` and `messages_context`. - `messagesmind api --config FILE` binds the one address that `[server]` states, on port 8420 unless the config sets another, and serves the one path `/mcp` (ADR 0011). `[server]` is now required for every verb. - Every page is text with no structured copy. A transcript has a legend, one date line for each day, one row for each message with its flags, and a footer with a keyset cursor. - `messages_search` returns pointers and no text. `messages_context` expands a pointer. - The read token reaches the tools. The evidence token does not. ## Security controls - Each call opens the store in reader mode for one read transaction. The api holds no client code, and a test follows every module that the api loads. - A foreign `Host` gets `421` and a foreign `Origin` gets `403`. The allow-lists of the guard are stated in code. - The api does not start when a `FASTMCP_` variable, or a `.env` file in the working directory, changes a setting of the MCP framework. Such a setting can turn the `Host` and `Origin` checks off. - Every refused call answers `Error: code=<code>`. No reply repeats an argument, a tool name that the caller sent, a file path or the message of a fault. - The log holds one line for each call: the tool, the line count and the code. One handler passes the records of the service and of uvicorn, and drops every record of a library. A fault prints its class only. - Message text is one bounded line with no `|`, so it cannot forge a row, a flag or a footer. ## Acceptance criteria of #14 | Criterion | Test | |---|---| | A tokenizer budget for a transcript row, for a default page of each tool and for the tool list | `tests/test_server.py`, the four budget tests | | The tokenizer is pinned and runs offline | `tests/test_layout.py`, the vocabulary hash and the offline loader | | `messages_search` returns no body; `messages_context` expands a pointer | `tests/test_views.py` | | Every read tool refuses the evidence token | `tests/test_server.py` | | Paging shows every row once when rows share one timestamp | `tests/test_views.py` | | A redacted row keeps its sender, time and direction | `tests/test_views.py`, for a received row and a sent row | ## Points for the reviewer 1. **The Kit cursor is plain text.** It costs about 20 tokens less on every page. It replaces the earlier rule that a cursor holds no readable key. The cursor holds a date and local ids that the page already shows. 2. **The tokenizer vocabulary is a file in the repository.** `tests/tokenizer/o200k_base.tiktoken` is 3.6 MB. Its publisher states no licence for the file. `tests/tokenizer/README.md` records its source and its SHA-256. 3. **A tool error is text with `isError` false**, as People Mind does it. The MCP specification asks for `isError` true. 4. **Times print in UTC.** There is no timezone option. 5. **The Host allow-list for a published name is not built.** It belongs to the hardening slice. Today the api accepts the bind address and the loopback names. ## Checks `make check` is green on macOS: 182 tests. Mutation runs prove that the tests for the log filter, the fault formatter and the framework-settings refusal fail when the control is removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Read tools with compact transcript rows and tokenizer budgets (#14)
All checks were successful
ci/woodpecker/pr/validation Pipeline was successful
ci/woodpecker/push/validation Pipeline was successful
9e0d5ccd63
The api process and its five read tools, over stateless Streamable HTTP
with a bearer token.

The api
- `messagesmind api` binds the one address that `[server]` states, on
  port 8420 unless the config sets another, and serves the one path /mcp
  (ADR 0011). `[server]` is required, `host` is an IP address as text and
  `port` is a number.
- The read token reaches the tools. The evidence token does not.
- Each call opens the store in reader mode for one read transaction. The
  api holds no client code, and a test follows every module it loads.
- A request with a foreign Host gets 421 and a foreign Origin gets 403.
  The guard's allow-lists are stated in code. The api does not start when
  a FASTMCP_ variable or a .env file changes a framework setting.
- Every refused call answers `Error: code=<code>`: a bad argument, an
  unknown tool, a resource read and a prompt read. No reply repeats what
  the caller sent.
- The log holds one line for each call: the tool, the line count and the
  code. One handler passes the records of the service and of uvicorn and
  drops every library record. A fault prints its class only.

The pages
- Text only, with no structured copy. A transcript has a legend, one date
  line for each day, one row for each message with its flags, and a
  footer with a keyset cursor. A Tapback folds into its row.
- Message text is one bounded line with no `|`, so it cannot forge a row,
  a flag or a footer.
- `messages_search` returns pointers and no text. `messages_context`
  expands a pointer, and its cursor reads older rows.
- Local ids are short: c2 is a Chat, m340 a message, p1 a handle.

The Kit
- A cursor is plain text: its kind, an epoch tag and its key fields. It
  costs about 20 tokens less on every page than the encoded form.

Budgets
- A tokenizer test holds a budget for the tool list (660 of 2,500), for a
  transcript row (18) and for a default page of each tool. tiktoken runs
  offline on a vocabulary file in tests/tokenizer, checked by its hash.

The two-axis code review ran and its findings are closed here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.