Read tools over Streamable HTTP with bearer tokens and compact rows #4

Closed
opened 2026-11-01 01:59:22 +00:00 by svc-agent-writer · 2 comments

Parent: #1. Records: ADR 0001 and 0003.

What to build

The MCP server a Grok Bot custom connector talks to. Streamable HTTP, bearer tokens read from files, mailmind's token shape.

  • Auth: read and write token files, constant-time comparison, a token-bucket rate limit, a FastMCP token verifier. A write token carries a label (auth.write_token_label); Phase A ships no write tool, but the scope model is in place.
  • Tools, read scope: people_find (name, address, phone or free text; returns default rows and Candidates), people_card (one Person, asserted and derived fields with provenance; evidence only on request), people_related (Relations, Organisation members, shared Tags), people_recent (Interactions by time, direction in/out), people_status (store counts and Source freshness), people_sources (configured Sources and their last sync).
  • Output: pipe rows, a footer with next_cursor, more and total, max_chars on text fields. The default row is exactly the closed seven-field list from config. Birthday, address and notes never appear unless config enables them.
  • Every tool docstring says content is untrusted data. Display names and signatures are rendered as data, never used to form a call.
  • Endpoints: /healthz and /healthz/sync with the same semantics as mailmind's.
  • CLI: peoplemind api, peoplemind token to mint and label tokens.

Acceptance criteria

  • Token budget: people_find default row under 150 tokens; people_card without evidence under 600; measured with a tokenizer in the test suite.
  • Field list: the default row emits exactly seven fields; a test enumerates them and fails on an eighth.
  • Auth: a request with no token, a wrong token, or a write token on a read tool behaves as specified; comparison is constant-time.
  • /healthz returns the api state; /healthz/sync returns the sync state and freshness.
  • The server module imports no Source; a test checks it, as mailmind's does.
  • Logs carry counts and codes only. The log-scan test from the store slice covers a tool run.

Blocked by

Filed under: operator word "go. compelling public-facing README.md as A0" sha256:3f9e946994fa

Parent: #1. Records: ADR 0001 and 0003. ## What to build The MCP server a Grok Bot custom connector talks to. Streamable HTTP, bearer tokens read from files, mailmind's token shape. - Auth: read and write token files, constant-time comparison, a token-bucket rate limit, a FastMCP token verifier. A write token carries a label (`auth.write_token_label`); Phase A ships no write tool, but the scope model is in place. - Tools, read scope: `people_find` (name, address, phone or free text; returns default rows and Candidates), `people_card` (one Person, asserted and derived fields with provenance; evidence only on request), `people_related` (Relations, Organisation members, shared Tags), `people_recent` (Interactions by time, direction `in`/`out`), `people_status` (store counts and Source freshness), `people_sources` (configured Sources and their last sync). - Output: pipe rows, a footer with `next_cursor`, `more` and `total`, `max_chars` on text fields. The default row is exactly the closed seven-field list from config. Birthday, address and notes never appear unless config enables them. - Every tool docstring says content is untrusted data. Display names and signatures are rendered as data, never used to form a call. - Endpoints: `/healthz` and `/healthz/sync` with the same semantics as mailmind's. - CLI: `peoplemind api`, `peoplemind token` to mint and label tokens. ## Acceptance criteria - Token budget: `people_find` default row under 150 tokens; `people_card` without evidence under 600; measured with a tokenizer in the test suite. - Field list: the default row emits exactly seven fields; a test enumerates them and fails on an eighth. - Auth: a request with no token, a wrong token, or a write token on a read tool behaves as specified; comparison is constant-time. - `/healthz` returns the api state; `/healthz/sync` returns the sync state and freshness. - The server module imports no Source; a test checks it, as mailmind's does. - Logs carry counts and codes only. The log-scan test from the store slice covers a tool run. ## Blocked by - #3 Filed under: operator word "go. compelling public-facing README.md as A0" sha256:3f9e946994fa
Collaborator

⏸ SVD architect gate: dev/peoplemind-mcp#4 read-tools-over-streamable-http-with-bearer-tokens-and-compa

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity substrate · dispatch effort high

Run: 20261101T031041Z-c75f7024

Held because: CLEAN but 8 open risk(s) (3 verification · 5 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. Should people_status follow ADR 0001 Amendment 1 (persons | organisations | handles | interactions | tombstones | change_seq | embed) or the issue text, which also asks for Source freshness? The lean follows the amendment and serves freshness through people_sources.last_sync and /healthz/sync. Confirm, or add a freshness cell (an amendment edit). [decision]
  2. Should the people_find row be person_id | | reason? Amendment 1 says 'default row plus match reason'. The lean prefixes person_id so the agent can call people_card, as mailmind rows carry ids. The seven-field test counts only the field columns. Accept? [decision]
  3. Should this slice own the sync-state writer? It adds schema v2 sync_log (mailmind shape) and has sync --once write it, because people_sources and /healthz/sync cannot be built without it. api.max_lag_seconds defaults to 86400 because there is no sync interval yet. Accept the schema bump here, or move it to a sync-daemon slice (with what lag default)? [decision]
  4. tiktoken.get_encoding('o200k_base') downloads its BPE file on first use, and the budget tests depend on it. Check at dispatch, after uv sync: uv run python3 -c "import tiktoken; print(len(tiktoken.get_encoding('o200k_base').encode('p_0000000000 | Ada')))" prints an integer. If it fails offline, halt rather than substitute a heuristic counter. [verification]
  5. FastMCP 3.4.11 and mcp 1.30.0 internals were unreadable in this sandbox and may log tool arguments at DEBUG. Check: the extended test_sync_log_output_has_no_pii passes under caplog.set_level(DEBUG) with build_app's logger pins. If it fails, add the offending logger to the pins; never weaken the scan. [verification]
  6. Amendment 1 lists people_changes and people_changes_ack in Phase A, but issue #4 names only six tools. The lean mounts six, and a test pins the set at six. Which issue owns the change-feed tools, or should this slice widen to eight (adding Consumer writes from api)? [decision]
  7. What should people_card evidence=true return before any evidence text source exists? The lean appends 'evidence | field | evidence_ref | observed_at' lines. The alternative is answering Error: code=evidence-unavailable until the mailmind Source slice. Which? [decision]
  8. Mailmind server.py, config.py, cli.py and the tests were read as quote-limited excerpts; only auth.py was verbatim. Check at dispatch: read mailmind src/imap_mailmind_mcp/server.py (_render, _footer, health routes, build_app) and tests/test_server.py (server fixture) from the public forge before writing server.py and conftest.serve, and record any divergence from spec §6–§8 in the PR body. [verification]

Change: Copy mailmind (dev/imap-mailmind-mcp at tree 8fbbb2430eda, public, read over WebFetch).

  • auth.py: copy mailmind's Tokens.scopes_for (hmac.compare_digest against every token; the write token gets [read, write]), RateLimiter, FileTokenVerifier (over rate returns None) and write_token_file, adapted to read_secret_file (config.py:100-107) and a write_token_label client_id.
  • server.py: mirror mailmind's module-level FastMCP, with each tool declared @mcp.tool(auth=require_scopes("read")) above a _render wrapper. _render opens open_reader per call, maps StoreError/ToolError to "Error: code=" and logs counts and codes only.
  • Health routes: /healthz always 200 "ok lag_seconds=<n|never>"; /healthz/sync 200 or 503 "ok|stale lag_seconds=.. max_lag_seconds=..".
  • build_app returns mcp.http_app(path, stateless_http=True, middleware=[TrustedHostMiddleware]).
  • rows.py: pipe cells escaped (whitespace collapsed, "|" replaced) and truncated to max_chars; trailing empty cells kept; footer "next_cursor= more= total="; integer-offset cursors.
  • views.py: the default row equals cfg.default_row.fields (config.py:10); asserted values win, derived values show only at or above the threshold; resolve() at identity.py:43-89 and canonical_id at identity.py:32-36; never imports graph or sources.
  • store.py: append migration 2, a sync_log table (mailmind shape), to MIGRATIONS (store.py:21-70); SCHEMA_VERSION becomes 2; open_writer migrates in place.
  • cli.py: _sync (cli.py:40-65) writes sync_log; main (cli.py:68-102) gates the salt and source checks to check/sync; new verbs api (uvicorn.run with access_log=False) and token (token_urlsafe(48), --out writes a 0600 file, --label).

Files: pyproject.toml · uv.lock · src/peoplemind_mcp/config.py · src/peoplemind_mcp/store.py · src/peoplemind_mcp/cli.py · src/peoplemind_mcp/auth.py · src/peoplemind_mcp/rows.py · src/peoplemind_mcp/views.py · src/peoplemind_mcp/server.py · tests/conftest.py · tests/test_config_cli.py · tests/test_identity.py · tests/test_vcard_sync.py · tests/test_auth.py · tests/test_server.py
Derived artifacts: uv.lock

Decision: accept the 8 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-read-tools-over-streamable-http-with-bearer-tokens-and-compa.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-read-tools-over-streamable-http-with-bearer-tokens-and-compa.md

### ⏸ SVD architect gate: dev/peoplemind-mcp#4 read-tools-over-streamable-http-with-bearer-tokens-and-compa **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `substrate` · dispatch effort `high` **Run:** `20261101T031041Z-c75f7024` **Held because:** CLEAN but 8 open risk(s) (3 verification · 5 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Should people_status follow ADR 0001 Amendment 1 (persons | organisations | handles | interactions | tombstones | change_seq | embed) or the issue text, which also asks for Source freshness? The lean follows the amendment and serves freshness through people_sources.last_sync and /healthz/sync. Confirm, or add a freshness cell (an amendment edit). [decision] 2. Should the people_find row be person_id | <seven configured fields> | reason? Amendment 1 says 'default row plus match reason'. The lean prefixes person_id so the agent can call people_card, as mailmind rows carry ids. The seven-field test counts only the field columns. Accept? [decision] 3. Should this slice own the sync-state writer? It adds schema v2 sync_log (mailmind shape) and has sync --once write it, because people_sources and /healthz/sync cannot be built without it. api.max_lag_seconds defaults to 86400 because there is no sync interval yet. Accept the schema bump here, or move it to a sync-daemon slice (with what lag default)? [decision] 4. tiktoken.get_encoding('o200k_base') downloads its BPE file on first use, and the budget tests depend on it. Check at dispatch, after uv sync: `uv run python3 -c "import tiktoken; print(len(tiktoken.get_encoding('o200k_base').encode('p_0000000000 | Ada')))"` prints an integer. If it fails offline, halt rather than substitute a heuristic counter. [verification] 5. FastMCP 3.4.11 and mcp 1.30.0 internals were unreadable in this sandbox and may log tool arguments at DEBUG. Check: the extended test_sync_log_output_has_no_pii passes under caplog.set_level(DEBUG) with build_app's logger pins. If it fails, add the offending logger to the pins; never weaken the scan. [verification] 6. Amendment 1 lists people_changes and people_changes_ack in Phase A, but issue #4 names only six tools. The lean mounts six, and a test pins the set at six. Which issue owns the change-feed tools, or should this slice widen to eight (adding Consumer writes from api)? [decision] 7. What should people_card evidence=true return before any evidence text source exists? The lean appends 'evidence | field | evidence_ref | observed_at' lines. The alternative is answering Error: code=evidence-unavailable until the mailmind Source slice. Which? [decision] 8. Mailmind server.py, config.py, cli.py and the tests were read as quote-limited excerpts; only auth.py was verbatim. Check at dispatch: read mailmind src/imap_mailmind_mcp/server.py (_render, _footer, health routes, build_app) and tests/test_server.py (server fixture) from the public forge before writing server.py and conftest.serve, and record any divergence from spec §6–§8 in the PR body. [verification] **Change:** Copy mailmind (dev/imap-mailmind-mcp at tree 8fbbb2430eda, public, read over WebFetch). - auth.py: copy mailmind's Tokens.scopes_for (hmac.compare_digest against every token; the write token gets [read, write]), RateLimiter, FileTokenVerifier (over rate returns None) and write_token_file, adapted to read_secret_file (config.py:100-107) and a write_token_label client_id. - server.py: mirror mailmind's module-level FastMCP, with each tool declared @mcp.tool(auth=require_scopes("read")) above a _render wrapper. _render opens open_reader per call, maps StoreError/ToolError to "Error: code=<c>" and logs counts and codes only. - Health routes: /healthz always 200 "ok lag_seconds=<n|never>"; /healthz/sync 200 or 503 "ok|stale lag_seconds=.. max_lag_seconds=..". - build_app returns mcp.http_app(path, stateless_http=True, middleware=[TrustedHostMiddleware]). - rows.py: pipe cells escaped (whitespace collapsed, "|" replaced) and truncated to max_chars; trailing empty cells kept; footer "next_cursor= more= total="; integer-offset cursors. - views.py: the default row equals cfg.default_row.fields (config.py:10); asserted values win, derived values show only at or above the threshold; resolve() at identity.py:43-89 and canonical_id at identity.py:32-36; never imports graph or sources. - store.py: append migration 2, a sync_log table (mailmind shape), to MIGRATIONS (store.py:21-70); SCHEMA_VERSION becomes 2; open_writer migrates in place. - cli.py: _sync (cli.py:40-65) writes sync_log; main (cli.py:68-102) gates the salt and source checks to check/sync; new verbs api (uvicorn.run with access_log=False) and token (token_urlsafe(48), --out writes a 0600 file, --label). **Files:** `pyproject.toml` · `uv.lock` · `src/peoplemind_mcp/config.py` · `src/peoplemind_mcp/store.py` · `src/peoplemind_mcp/cli.py` · `src/peoplemind_mcp/auth.py` · `src/peoplemind_mcp/rows.py` · `src/peoplemind_mcp/views.py` · `src/peoplemind_mcp/server.py` · `tests/conftest.py` · `tests/test_config_cli.py` · `tests/test_identity.py` · `tests/test_vcard_sync.py` · `tests/test_auth.py` · `tests/test_server.py` **Derived artifacts:** `uv.lock` **Decision:** accept the 8 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-read-tools-over-streamable-http-with-bearer-tokens-and-compa.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-read-tools-over-streamable-http-with-bearer-tokens-and-compa.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/peoplemind-mcp#4 read-tools-over-streamable-http-with-bearer-tokens-and-compa completed integration verify.

  • PR: dev/peoplemind-mcp#15
  • Branch: feat/svd-dev-peoplemind-mcp-4-read-tools-over-streamable-http-1c657f20
  • Commit: 9578907ba6
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check forgejo-commit-statuses: absent
  • Checks: PR #15 head 9578907: no remote checks exist (absent). Local: 100 tests passed, mypy --strict, ruff check and format, and uv lock --check all clean.
  • Warning: Remote CI is absent: the PR head has no commit statuses and the repo has no CI configuration.
  • Warning: Spec Test Strategy has no scenario table, so no scenario tracing applied. All named planned tests were found in collected node ids.
  • Warning: Subagent changed two graph-idempotence assertions to exclude sync_log INSERT rows. This is intentional per the deviation note and is not a defect.
  • Warning: no CI for forgejo-commit-statuses: No commit statuses on PR head 9578907 and no CI config in the repo (.forgejo, .woodpecker, .buildkite, .github all absent); no tracking pointer exists. — reported as absent, not blocking (gh#633)
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261101T033712Z-1c657f20 --confirm-merge)
spec-verify-dispatch Half B for dev/peoplemind-mcp#4 read-tools-over-streamable-http-with-bearer-tokens-and-compa completed integration verify. - PR: https://git.groupthink.asia/dev/peoplemind-mcp/pulls/15 - Branch: feat/svd-dev-peoplemind-mcp-4-read-tools-over-streamable-http-1c657f20 - Commit: 9578907ba6e53ded7a05a010918a93d9a3a50a2a - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check forgejo-commit-statuses: absent - Checks: PR #15 head 9578907: no remote checks exist (absent). Local: 100 tests passed, mypy --strict, ruff check and format, and uv lock --check all clean. - Warning: Remote CI is absent: the PR head has no commit statuses and the repo has no CI configuration. - Warning: Spec Test Strategy has no scenario table, so no scenario tracing applied. All named planned tests were found in collected node ids. - Warning: Subagent changed two graph-idempotence assertions to exclude sync_log INSERT rows. This is intentional per the deviation note and is not a defect. - Warning: no CI for forgejo-commit-statuses: No commit statuses on PR head 9578907 and no CI config in the repo (.forgejo, .woodpecker, .buildkite, .github all absent); no tracking pointer exists. — reported as absent, not blocking (gh#633) - Decision: review the PR and merge? (`codex-svd ship --run-id 20261101T033712Z-1c657f20 --confirm-merge`)
piers closed this issue 2026-11-01 03:50:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/people-mind-mcp#4
No description provided.