Add v0.1.0 read-only IMAP surface #1

Merged
svc-agent-writer merged 6 commits from feat/v0.1-read-surface into main 2026-10-30 06:51:52 +00:00

Summary

imap-blade-mcp v0.1.0: a read-only IMAP MCP server over the Stallari email-v1 contract, first target the Linux grokbot hosts. Eleven tools, stdio only, TLS always, EXAMINE plus BODY.PEEK only, credential from an owner-only file read at login time, every body wrapped in untrusted-content markers. No SMTP, no write path, no HTTP transport, no CI files (the .woodpecker rider is the architect's).

Six commits on feat/v0.1-read-surface from the bootstrap on main: scaffold and config, session and MIME, the tools and --check, unit tests, GreenMail integration harness, docs.

Toolchain: system Python 3.14.7, uv 0.12.17; project venv Python 3.12.12 (.python-version = 3.12, the floor). Container runtime for integration: Podman 5.8.7 (Docker daemon not running; the script prefers Podman and falls back to Docker).

Acceptance checklist

  • Preflight passed; Python and uv versions reported. Python 3.14.7 / 3.12.12 in venv, uv 0.12.17 (above).
  • make check passes on a clean clone. Cloned the branch into a scratch directory, make install, then:
    uv run ruff check src/ tests/ scripts/      All checks passed!
    uv run ruff format --check ...              29 files already formatted
    uv run mypy --strict src/                   Success: no issues found in 9 source files
    uv run pytest tests/ -m "not integration"   165 passed, 24 deselected in 5.35s
    uvx pip-audit --strict ...                  No known vulnerabilities found
    clean-clone make check exit=0
    
  • make test-integration passes against GreenMail. Image greenmail/standalone pinned by digest sha256:309ba544ea482e5d4265d09921cdab07c8dad2cc4481d715c9b8ff5d3f0a149f, IMAPS on 127.0.0.1:3993 with the repo test CA as ca_file:
    tests/integration/test_greenmail.py::TestCheckCommand::test_check_hostname_mismatch_exits_3 PASSED [100%]
    ============================== 23 passed in 8.79s ==============================
    greenmail: down
    
    A stale-id integration test was added during the red-side work; the final make test-integration run: 24 passed in 9.55s.
  • Exactly 11 tools with the default config; 1 with expose = ["mail_search"].
    default: 11
    expose=["mail_search"]: ['mail_search']
    
    Guarded by tests/test_tool_surface.py::test_default_config_registers_exactly_eleven and ::test_expose_single_tool_registers_one.
  • Red-side evidence per (red) item. Section below.
  • tools/list byte count recorded in the README and guarded. 13004 bytes (ListToolsResult, by_alias=True, exclude_none=True); RECORDED_TOOLS_LIST_BYTES = 13004 with a +10% guard in test_tools_list_byte_budget. Longest description 285 chars (limit 400), longest parameter description 69 (limit 120).
  • Forbidden-construct grep over src/ is empty.
    $ grep -rniE "smtp|starlette|uvicorn|subprocess|os\.environ\[.*(PASS|TOKEN|SECRET)" src/
    exit=1
    
    (no output; grep exit 1 = no match). tests/test_hygiene.py runs the same patterns plus eval/exec/pickle, HTTP transport calls and imapclient write methods on every test run.
  • --check against GreenMail exits 0; a 0644 credential exits 2.
    $ imap-blade-mcp --check --config config.toml
    {"ts":"2026-10-30T06:07:33.777+00:00","level":"INFO","logger":"imap_blade_mcp.connection","event":"connected","account":"greenmail","tls":"implicit","duration_ms":142}
    config: OK .../config.toml (1 account(s), 11 tool(s) exposed)
    account=greenmail: OK tls=implicit extensions=9 personal_namespaces=1 mailboxes_in_scope=4 special_use_roles=inbox,sent,trash quota=-
      degrade: no CONDSTORE: mail_changes reports new messages only (partial)
      degrade: no ESEARCH: match counts come from the full UID list
      degrade: no LIST-STATUS: counts come from one STATUS per mailbox
      degrade: no NAMESPACE: assuming a single personal namespace with an empty prefix
      degrade: no SPECIAL-USE: mailbox roles inferred from names
      degrade: no THREAD=REFERENCES: threads built client-side from References headers
    exit=0
    
    $ imap-blade-mcp --check --config config-0644.toml
    config: OK .../config644.toml (1 account(s), 11 tool(s) exposed)
    account=greenmail: FAIL credential file .../cred644 failed check: mode 0644 has forbidden bits 0077
    exit=2
    
    Also covered by TestCheckCommand in the integration suite (exit 0, 2, 4 wrong password, 3 hostname mismatch via 127.0.0.1).
  • docs/deploy-linux.md covers all seven sections: install (uv tool from the tag, wheel fallback, no Nix), bot user, credential file (sops-nix, op read/op inject, systemd LoadCredential=, keyring not used headless), least privilege, client entry with no env block and the Grok-client caveat, smoke, rollback.

Red-side results

Method for each (red) item: remove the guard in source with a one-line mutation, run the test(s) that own the item, show the failure naming the offender, restore the file, re-run to green. Items 8, 9, 11 to 18 are covered by the unit and integration suites without a red-side run.

(red) 1 TLS required: STARTTLS pre-check removed

Guard removed:

-                if "STARTTLS" not in pre_tls:
+                if False:  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_tls.py::TestStartTls -q
E   AssertionError: assert 'connection_error' == 'tls_error'
tests/test_tls.py:73: AssertionError: assert 'connection_error' == 'tls_error'
FAILED tests/test_tls.py::TestStartTls::test_refuses_when_starttls_not_advertised
1 failed, 2 passed in 5.04s

Guard restored; same selection:

3 passed in 0.02s

(red) 2 certificate failure: hostname check and CERT_REQUIRED removed

Guard removed:

-    context.check_hostname = True
-    context.verify_mode = ssl.CERT_REQUIRED
+    context.check_hostname = False  # MUTATED
+    context.verify_mode = ssl.CERT_NONE  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_tls.py -q
E   assert False is True
tests/test_tls.py:29: assert False is True
E   AssertionError: assert 'authenticationfailed' == 'tls_error'
tests/test_tls.py:46: AssertionError: assert 'authenticationfailed' == 'tls_error'
E   AssertionError: assert 'authenticationfailed' == 'tls_error'
tests/test_tls.py:55: AssertionError: assert 'authenticationfailed' == 'tls_error'
E   AssertionError: assert 'authenticationfailed' == 'tls_error'
tests/test_tls.py:99: AssertionError: assert 'authenticationfailed' == 'tls_error'
E   assert 'CERT_NONE' not in '"""IMAP ses...tial_file)\n'
tests/test_tls.py:108: assert 'CERT_NONE' not in '"""IMAP ses...tial_file)\n'
FAILED tests/test_tls.py::TestSslContext::test_hostname_and_cert_required - a...

Guard restored; same selection:

10 passed in 0.04s

(red) 3 credential handling: group/world bits allowed on the credential file

Guard removed:

-    check_file(path, label="credential file", forbidden_bits=0o077)
+    check_file(path, label="credential file", forbidden_bits=0o000)  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_config.py::TestReadCredential tests/test_scrub.py::test_credential_file_mode_enforced_at_connect tests/integration/test_greenmail.py::TestCheckCommand::test_check_world_readable_credential_exits_2 -q
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError
E   Failed: DID NOT RAISE BladeError
tests/test_config.py:139: Failed: DID NOT RAISE BladeError

Guard restored; same selection:

19 passed in 5.06s

(red) 4 scrubbing: scrub() bypassed on the error path

Guard removed:

-        return f"Error: code={self.code} retryable={'true' if self.retryable else 'false'} {scrub(self.message)}"
+        return f"Error: code={self.code} retryable={'true' if self.retryable else 'false'} {self.message}"  # MUTATED
-        return BladeError(code, scrub(text), retryable=retryable)
-    return BladeError(default_code, scrub(text), retryable=default_retryable)
+        return BladeError(code, text, retryable=retryable)  # MUTATED
+    return BladeError(default_code, text, retryable=default_retryable)  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_scrub.py -q
E   AssertionError: credential leaked into tool error: Error: code=authenticationfailed retryable=false b'[AUTHENTICATIONFAILED] bad password s3cret-app-password-XyZ'
    assert 's3cret-app-password-XyZ' not in "Error: code...assword-XyZ'"
tests/test_scrub.py:79: AssertionError: credential leaked into tool error: Error: code=authenticationfailed retryable=false b'[AUTHENTICATIONFAILED] bad password s3cret-app-password-XyZ'
FAILED tests/test_scrub.py::test_credential_never_in_error_or_stderr - Assert...
1 failed, 4 passed in 5.14s

Guard restored; same selection:

5 passed in 5.04s

(red) 5 no side effects: SELECT instead of EXAMINE and BODY[] instead of BODY.PEEK[]

Guard removed:

-            response = client.select_folder(canonical, readonly=True)
+            response = client.select_folder(canonical, readonly=False)
-        data = self.fetch([uid], [f"BODY.PEEK[{section}]<{start}.{count}>"])
+        data = self.fetch([uid], [f"BODY[{section}]<{start}.{count}>"])

Test run with the guard removed:

$ uv run pytest tests/test_hygiene.py::test_every_select_is_readonly tests/test_tools.py::TestMailRead::test_seen_flag_untouched tests/integration/test_greenmail.py::TestSearchAndRead::test_read_plain_trims_quotes_and_keeps_seen_unchanged -q
E   AssertionError: connection.py: select_folder(canonical, readonly=False)
    assert 'readonly=True' in 'canonical, readonly=False'
tests/test_hygiene.py:45: AssertionError: connection.py: select_folder(canonical, readonly=False)
E   AssertionError: mail_read must not set \Seen
    assert b'\\Seen' not in (b'\\Seen',)
tests/integration/test_greenmail.py:125: AssertionError: mail_read must not set \Seen
FAILED tests/test_hygiene.py::test_every_select_is_readonly - AssertionError:...
FAILED tests/integration/test_greenmail.py::TestSearchAndRead::test_read_plain_trims_quotes_and_keeps_seen_unchanged
2 failed, 1 passed in 0.71s

Guard restored; same selection:

1 failed, 2 passed in 0.49s   # the mutated run left \Seen set on the fixture; after `scripts/greenmail.sh down && up`: 3 passed in 0.74s

(red) 6 message identity: UIDVALIDITY comparison removed

Guard removed:

-        if state.uidvalidity != uidvalidity:
+        if False:  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_identity.py tests/integration/test_greenmail.py::TestStateAndThreads::test_stale_uidvalidity_refused -q
E   Failed: DID NOT RAISE BladeError
tests/test_identity.py:67: Failed: DID NOT RAISE BladeError
E   assert 'code=stale_id' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzcvMw\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max_chars=8000"],"latency_ms":175,"redac
tests/integration/test_greenmail.py:197: assert 'code=stale_id' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzcvMw\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max
FAILED tests/test_identity.py::test_real_session_examine_for_refuses_moved_uidvalidity
FAILED tests/integration/test_greenmail.py::TestStateAndThreads::test_stale_uidvalidity_refused
2 failed, 12 passed in 0.53s

Guard restored; same selection:

14 passed in 0.40s

(red) 7 schema guard: a host parameter added to mail_mailboxes

Guard removed:

-async def mail_mailboxes(account: AccountParam) -> str:
+async def mail_mailboxes(account: AccountParam, host: str = "") -> str:  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_tool_surface.py::test_schema_guard_no_host_port_url_path_or_credential_params -q
E   AssertionError: forbidden parameters: ['mail_mailboxes.host (name)']
    assert ['mail_mailboxes.host (name)'] == []
tests/test_tool_surface.py:74: AssertionError: forbidden parameters: ['mail_mailboxes.host (name)']
FAILED tests/test_tool_surface.py::test_schema_guard_no_host_port_url_path_or_credential_params
1 failed in 0.03s

Guard restored; same selection:

1 passed in 0.03s

(red) 10 parser bounds: nesting bound raised from 32 to 1000

Guard removed:

-MAX_NESTING: Final = 32
+MAX_NESTING: Final = 1000  # MUTATED

Test run with the guard removed:

$ uv run pytest tests/test_mime.py::TestBodystructure::test_nesting_bound_40_levels tests/integration/test_greenmail.py::TestSearchAndRead::test_nested_40_levels_hits_bound -q
E   Failed: DID NOT RAISE BladeError
tests/test_mime.py:170: Failed: DID NOT RAISE BladeError
E   assert 'code=parse_bounds' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzYvNg\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max_chars=8000"],"latency_ms":205,"r
tests/integration/test_greenmail.py:151: assert 'code=parse_bounds' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzYvNg\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false",
FAILED tests/test_mime.py::TestBodystructure::test_nesting_bound_40_levels - ...
FAILED tests/integration/test_greenmail.py::TestSearchAndRead::test_nested_40_levels_hits_bound
2 failed in 0.55s

Guard restored; same selection:

2 passed in 0.44s

Dependencies

Runtime, all from the fixed-decisions list, nothing added:

Package Pin Reason
fastmcp >=3.1.0,<4 MCP server, stdio transport, tool annotations
imapclient >=4.1,<5 IMAP client with STARTTLS, ssl_context, EXAMINE, PEEK, raw command path
pydantic >=2.0.0,<3 config model with extra="forbid" and parameter schemas
stallari-mcp-helpers >=0.1.1,<1.0 meta_envelope / append_meta audit tail (DD-338)

Dev and test groups: ruff, mypy, pytest, pytest-asyncio. pip-audit runs via uvx, not installed. uv.lock is committed.

Server quirks found against GreenMail

  • GreenMail omits the space between a partial-fetch offset and the literal size (BODY[1]<0>{64}), which the imapclient response parser rejects as "uneven number of response items". All fetches now go through imapclient's raw command path and that exact byte pattern is normalised before parsing. Compliant servers are unaffected.
  • GreenMail's FROM search matches the address only, not the display name. The integration test searches by address.
  • GreenMail's login failure carries no RFC 5530 code, so a wrong password surfaces as auth_error (exit 4) through the generic login-failure path rather than authenticationfailed. The RFC 5530 mapping is exercised by the unit suite's scripted server.
  • GreenMail advertises no NAMESPACE, SPECIAL-USE, LIST-STATUS, ESEARCH, CONDSTORE or THREAD, so the integration suite exercises every degrade path and none of the advertised-extension paths. Those are covered by the fake session in unit tests only.

Open items for the operator

  1. Grok MCP client format is unconfirmed. DD-453's status recorded the grok-bot MCP client as missing on 2026-09-18. docs/deploy-linux.md §5 gives the generic stdio stanza and says so.
  2. Tag v0.1.0 once merged; the install line in the deploy doc points at the tag. Not done here per the brief.
  3. .woodpecker/* rider to be added by the architect from fastmail-blade-mcp (ADR-0021). No CI files in this PR.
  4. Test CA private keys are committed under tests/fixtures/tls/ (ca.key, localhost.key, greenmail.p12 with password changeit). They sign only DNS:localhost for the loopback and GreenMail tests and are documented in tests/fixtures/tls/README.md. Say if you would rather they were generated at test time.
  5. Real-provider run. Everything advertised-extension-side (NAMESPACE, SPECIAL-USE, LIST-STATUS, ESEARCH, CONDSTORE, THREAD=REFERENCES, QUOTA, X-GM-EXT-1) has fake-session coverage only. A --check and a handful of tool calls against a real Dovecot or iCloud mailbox before deployment would be the first live exercise of those paths.
  6. make test-integration needs Podman or Docker and pulls the digest-pinned image on first run.

🤖 Generated with Claude Code

## Summary `imap-blade-mcp` v0.1.0: a read-only IMAP MCP server over the Stallari `email-v1` contract, first target the Linux grokbot hosts. Eleven tools, stdio only, TLS always, `EXAMINE` plus `BODY.PEEK` only, credential from an owner-only file read at login time, every body wrapped in untrusted-content markers. No SMTP, no write path, no HTTP transport, no CI files (the `.woodpecker` rider is the architect's). Six commits on `feat/v0.1-read-surface` from the bootstrap on `main`: scaffold and config, session and MIME, the tools and `--check`, unit tests, GreenMail integration harness, docs. **Toolchain:** system Python 3.14.7, uv 0.12.17; project venv Python 3.12.12 (`.python-version` = 3.12, the floor). Container runtime for integration: Podman 5.8.7 (Docker daemon not running; the script prefers Podman and falls back to Docker). ## Acceptance checklist - [x] **Preflight passed; Python and uv versions reported.** Python 3.14.7 / 3.12.12 in venv, uv 0.12.17 (above). - [x] **`make check` passes on a clean clone.** Cloned the branch into a scratch directory, `make install`, then: ``` uv run ruff check src/ tests/ scripts/ All checks passed! uv run ruff format --check ... 29 files already formatted uv run mypy --strict src/ Success: no issues found in 9 source files uv run pytest tests/ -m "not integration" 165 passed, 24 deselected in 5.35s uvx pip-audit --strict ... No known vulnerabilities found clean-clone make check exit=0 ``` - [x] **`make test-integration` passes against GreenMail.** Image `greenmail/standalone` pinned by digest `sha256:309ba544ea482e5d4265d09921cdab07c8dad2cc4481d715c9b8ff5d3f0a149f`, IMAPS on 127.0.0.1:3993 with the repo test CA as `ca_file`: ``` tests/integration/test_greenmail.py::TestCheckCommand::test_check_hostname_mismatch_exits_3 PASSED [100%] ============================== 23 passed in 8.79s ============================== greenmail: down ``` A stale-id integration test was added during the red-side work; the final `make test-integration` run: `24 passed in 9.55s`. - [x] **Exactly 11 tools with the default config; 1 with `expose = ["mail_search"]`.** ``` default: 11 expose=["mail_search"]: ['mail_search'] ``` Guarded by `tests/test_tool_surface.py::test_default_config_registers_exactly_eleven` and `::test_expose_single_tool_registers_one`. - [x] **Red-side evidence per (red) item.** Section below. - [x] **`tools/list` byte count recorded in the README and guarded.** 13004 bytes (`ListToolsResult`, `by_alias=True`, `exclude_none=True`); `RECORDED_TOOLS_LIST_BYTES = 13004` with a +10% guard in `test_tools_list_byte_budget`. Longest description 285 chars (limit 400), longest parameter description 69 (limit 120). - [x] **Forbidden-construct grep over `src/` is empty.** ``` $ grep -rniE "smtp|starlette|uvicorn|subprocess|os\.environ\[.*(PASS|TOKEN|SECRET)" src/ exit=1 ``` (no output; grep exit 1 = no match). `tests/test_hygiene.py` runs the same patterns plus eval/exec/pickle, HTTP transport calls and imapclient write methods on every test run. - [x] **`--check` against GreenMail exits 0; a 0644 credential exits 2.** ``` $ imap-blade-mcp --check --config config.toml {"ts":"2026-10-30T06:07:33.777+00:00","level":"INFO","logger":"imap_blade_mcp.connection","event":"connected","account":"greenmail","tls":"implicit","duration_ms":142} config: OK .../config.toml (1 account(s), 11 tool(s) exposed) account=greenmail: OK tls=implicit extensions=9 personal_namespaces=1 mailboxes_in_scope=4 special_use_roles=inbox,sent,trash quota=- degrade: no CONDSTORE: mail_changes reports new messages only (partial) degrade: no ESEARCH: match counts come from the full UID list degrade: no LIST-STATUS: counts come from one STATUS per mailbox degrade: no NAMESPACE: assuming a single personal namespace with an empty prefix degrade: no SPECIAL-USE: mailbox roles inferred from names degrade: no THREAD=REFERENCES: threads built client-side from References headers exit=0 $ imap-blade-mcp --check --config config-0644.toml config: OK .../config644.toml (1 account(s), 11 tool(s) exposed) account=greenmail: FAIL credential file .../cred644 failed check: mode 0644 has forbidden bits 0077 exit=2 ``` Also covered by `TestCheckCommand` in the integration suite (exit 0, 2, 4 wrong password, 3 hostname mismatch via `127.0.0.1`). - [x] **`docs/deploy-linux.md` covers all seven sections:** install (uv tool from the tag, wheel fallback, no Nix), bot user, credential file (sops-nix, `op read`/`op inject`, systemd `LoadCredential=`, keyring not used headless), least privilege, client entry with no `env` block and the Grok-client caveat, smoke, rollback. ## Red-side results Method for each (red) item: remove the guard in source with a one-line mutation, run the test(s) that own the item, show the failure naming the offender, restore the file, re-run to green. Items 8, 9, 11 to 18 are covered by the unit and integration suites without a red-side run. ### (red) 1 TLS required: STARTTLS pre-check removed Guard removed: ```diff - if "STARTTLS" not in pre_tls: + if False: # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_tls.py::TestStartTls -q E AssertionError: assert 'connection_error' == 'tls_error' tests/test_tls.py:73: AssertionError: assert 'connection_error' == 'tls_error' FAILED tests/test_tls.py::TestStartTls::test_refuses_when_starttls_not_advertised 1 failed, 2 passed in 5.04s ``` Guard restored; same selection: ``` 3 passed in 0.02s ``` ### (red) 2 certificate failure: hostname check and CERT_REQUIRED removed Guard removed: ```diff - context.check_hostname = True - context.verify_mode = ssl.CERT_REQUIRED + context.check_hostname = False # MUTATED + context.verify_mode = ssl.CERT_NONE # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_tls.py -q E assert False is True tests/test_tls.py:29: assert False is True E AssertionError: assert 'authenticationfailed' == 'tls_error' tests/test_tls.py:46: AssertionError: assert 'authenticationfailed' == 'tls_error' E AssertionError: assert 'authenticationfailed' == 'tls_error' tests/test_tls.py:55: AssertionError: assert 'authenticationfailed' == 'tls_error' E AssertionError: assert 'authenticationfailed' == 'tls_error' tests/test_tls.py:99: AssertionError: assert 'authenticationfailed' == 'tls_error' E assert 'CERT_NONE' not in '"""IMAP ses...tial_file)\n' tests/test_tls.py:108: assert 'CERT_NONE' not in '"""IMAP ses...tial_file)\n' FAILED tests/test_tls.py::TestSslContext::test_hostname_and_cert_required - a... ``` Guard restored; same selection: ``` 10 passed in 0.04s ``` ### (red) 3 credential handling: group/world bits allowed on the credential file Guard removed: ```diff - check_file(path, label="credential file", forbidden_bits=0o077) + check_file(path, label="credential file", forbidden_bits=0o000) # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_config.py::TestReadCredential tests/test_scrub.py::test_credential_file_mode_enforced_at_connect tests/integration/test_greenmail.py::TestCheckCommand::test_check_world_readable_credential_exits_2 -q E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError E Failed: DID NOT RAISE BladeError tests/test_config.py:139: Failed: DID NOT RAISE BladeError ``` Guard restored; same selection: ``` 19 passed in 5.06s ``` ### (red) 4 scrubbing: scrub() bypassed on the error path Guard removed: ```diff - return f"Error: code={self.code} retryable={'true' if self.retryable else 'false'} {scrub(self.message)}" + return f"Error: code={self.code} retryable={'true' if self.retryable else 'false'} {self.message}" # MUTATED - return BladeError(code, scrub(text), retryable=retryable) - return BladeError(default_code, scrub(text), retryable=default_retryable) + return BladeError(code, text, retryable=retryable) # MUTATED + return BladeError(default_code, text, retryable=default_retryable) # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_scrub.py -q E AssertionError: credential leaked into tool error: Error: code=authenticationfailed retryable=false b'[AUTHENTICATIONFAILED] bad password s3cret-app-password-XyZ' assert 's3cret-app-password-XyZ' not in "Error: code...assword-XyZ'" tests/test_scrub.py:79: AssertionError: credential leaked into tool error: Error: code=authenticationfailed retryable=false b'[AUTHENTICATIONFAILED] bad password s3cret-app-password-XyZ' FAILED tests/test_scrub.py::test_credential_never_in_error_or_stderr - Assert... 1 failed, 4 passed in 5.14s ``` Guard restored; same selection: ``` 5 passed in 5.04s ``` ### (red) 5 no side effects: SELECT instead of EXAMINE and BODY[] instead of BODY.PEEK[] Guard removed: ```diff - response = client.select_folder(canonical, readonly=True) + response = client.select_folder(canonical, readonly=False) - data = self.fetch([uid], [f"BODY.PEEK[{section}]<{start}.{count}>"]) + data = self.fetch([uid], [f"BODY[{section}]<{start}.{count}>"]) ``` Test run with the guard removed: ``` $ uv run pytest tests/test_hygiene.py::test_every_select_is_readonly tests/test_tools.py::TestMailRead::test_seen_flag_untouched tests/integration/test_greenmail.py::TestSearchAndRead::test_read_plain_trims_quotes_and_keeps_seen_unchanged -q E AssertionError: connection.py: select_folder(canonical, readonly=False) assert 'readonly=True' in 'canonical, readonly=False' tests/test_hygiene.py:45: AssertionError: connection.py: select_folder(canonical, readonly=False) E AssertionError: mail_read must not set \Seen assert b'\\Seen' not in (b'\\Seen',) tests/integration/test_greenmail.py:125: AssertionError: mail_read must not set \Seen FAILED tests/test_hygiene.py::test_every_select_is_readonly - AssertionError:... FAILED tests/integration/test_greenmail.py::TestSearchAndRead::test_read_plain_trims_quotes_and_keeps_seen_unchanged 2 failed, 1 passed in 0.71s ``` Guard restored; same selection: ``` 1 failed, 2 passed in 0.49s # the mutated run left \Seen set on the fixture; after `scripts/greenmail.sh down && up`: 3 passed in 0.74s ``` ### (red) 6 message identity: UIDVALIDITY comparison removed Guard removed: ```diff - if state.uidvalidity != uidvalidity: + if False: # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_identity.py tests/integration/test_greenmail.py::TestStateAndThreads::test_stale_uidvalidity_refused -q E Failed: DID NOT RAISE BladeError tests/test_identity.py:67: Failed: DID NOT RAISE BladeError E assert 'code=stale_id' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzcvMw\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max_chars=8000"],"latency_ms":175,"redac tests/integration/test_greenmail.py:197: assert 'code=stale_id' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzcvMw\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max FAILED tests/test_identity.py::test_real_session_examine_for_refuses_moved_uidvalidity FAILED tests/integration/test_greenmail.py::TestStateAndThreads::test_stale_uidvalidity_refused 2 failed, 12 passed in 0.53s ``` Guard restored; same selection: ``` 14 passed in 0.40s ``` ### (red) 7 schema guard: a host parameter added to mail_mailboxes Guard removed: ```diff -async def mail_mailboxes(account: AccountParam) -> str: +async def mail_mailboxes(account: AccountParam, host: str = "") -> str: # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_tool_surface.py::test_schema_guard_no_host_port_url_path_or_credential_params -q E AssertionError: forbidden parameters: ['mail_mailboxes.host (name)'] assert ['mail_mailboxes.host (name)'] == [] tests/test_tool_surface.py:74: AssertionError: forbidden parameters: ['mail_mailboxes.host (name)'] FAILED tests/test_tool_surface.py::test_schema_guard_no_host_port_url_path_or_credential_params 1 failed in 0.03s ``` Guard restored; same selection: ``` 1 passed in 0.03s ``` ### (red) 10 parser bounds: nesting bound raised from 32 to 1000 Guard removed: ```diff -MAX_NESTING: Final = 32 +MAX_NESTING: Final = 1000 # MUTATED ``` Test run with the guard removed: ``` $ uv run pytest tests/test_mime.py::TestBodystructure::test_nesting_bound_40_levels tests/integration/test_greenmail.py::TestSearchAndRead::test_nested_40_levels_hits_bound -q E Failed: DID NOT RAISE BladeError tests/test_mime.py:170: Failed: DID NOT RAISE BladeError E assert 'code=parse_bounds' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzYvNg\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false","max_chars=8000"],"latency_ms":205,"r tests/integration/test_greenmail.py:151: assert 'code=parse_bounds' in 'id: Z3JlZW5tYWlsL0lOQk9YLzE3OTMzNDA0MzYvNg\nFrom: Alice Example <alice@example.test>\nTo: Bot <bot@localhost>\nDate: ...by":["account=greenmail","include_quoted=false", FAILED tests/test_mime.py::TestBodystructure::test_nesting_bound_40_levels - ... FAILED tests/integration/test_greenmail.py::TestSearchAndRead::test_nested_40_levels_hits_bound 2 failed in 0.55s ``` Guard restored; same selection: ``` 2 passed in 0.44s ``` ## Dependencies Runtime, all from the fixed-decisions list, nothing added: | Package | Pin | Reason | |---|---|---| | `fastmcp` | `>=3.1.0,<4` | MCP server, stdio transport, tool annotations | | `imapclient` | `>=4.1,<5` | IMAP client with STARTTLS, `ssl_context`, EXAMINE, PEEK, raw command path | | `pydantic` | `>=2.0.0,<3` | config model with `extra="forbid"` and parameter schemas | | `stallari-mcp-helpers` | `>=0.1.1,<1.0` | `meta_envelope` / `append_meta` audit tail (DD-338) | Dev and test groups: `ruff`, `mypy`, `pytest`, `pytest-asyncio`. `pip-audit` runs via `uvx`, not installed. `uv.lock` is committed. ## Server quirks found against GreenMail - GreenMail omits the space between a partial-fetch offset and the literal size (`BODY[1]<0>{64}`), which the imapclient response parser rejects as "uneven number of response items". All fetches now go through imapclient's raw command path and that exact byte pattern is normalised before parsing. Compliant servers are unaffected. - GreenMail's `FROM` search matches the address only, not the display name. The integration test searches by address. - GreenMail's login failure carries no RFC 5530 code, so a wrong password surfaces as `auth_error` (exit 4) through the generic login-failure path rather than `authenticationfailed`. The RFC 5530 mapping is exercised by the unit suite's scripted server. - GreenMail advertises no NAMESPACE, SPECIAL-USE, LIST-STATUS, ESEARCH, CONDSTORE or THREAD, so the integration suite exercises every degrade path and none of the advertised-extension paths. Those are covered by the fake session in unit tests only. ## Open items for the operator 1. **Grok MCP client format is unconfirmed.** DD-453's status recorded the grok-bot MCP client as missing on 2026-09-18. `docs/deploy-linux.md` §5 gives the generic stdio stanza and says so. 2. **Tag `v0.1.0`** once merged; the install line in the deploy doc points at the tag. Not done here per the brief. 3. **`.woodpecker/*` rider** to be added by the architect from `fastmail-blade-mcp` (ADR-0021). No CI files in this PR. 4. **Test CA private keys are committed** under `tests/fixtures/tls/` (`ca.key`, `localhost.key`, `greenmail.p12` with password `changeit`). They sign only `DNS:localhost` for the loopback and GreenMail tests and are documented in `tests/fixtures/tls/README.md`. Say if you would rather they were generated at test time. 5. **Real-provider run.** Everything advertised-extension-side (NAMESPACE, SPECIAL-USE, LIST-STATUS, ESEARCH, CONDSTORE, THREAD=REFERENCES, QUOTA, X-GM-EXT-1) has fake-session coverage only. A `--check` and a handful of tool calls against a real Dovecot or iCloud mailbox before deployment would be the first live exercise of those paths. 6. **`make test-integration` needs Podman or Docker** and pulls the digest-pinned image on first run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Python 3.12+ package with FastMCP 3, imapclient 4, pydantic 2 and stallari-mcp-helpers as the only runtime deps. Config is TOML with unknown keys rejected, tls limited to implicit or starttls, absolute credential and CA paths, an expose allowlist, and file-mode and ownership checks on the config (no group/world write) and credential (owner-only). Errors render as one structured line with RFC 5530 codes mapped and registered secrets scrubbed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
AccountSession enforces TLS 1.2+ with hostname and certificate verification, requires STARTTLS to be advertised before upgrading and re-reads CAPABILITY after it, reads the credential only inside login, selects with EXAMINE and fetches with BODY.PEEK. Fetches go through the raw command path so GreenMail's missing space before a partial-fetch literal can be normalised. The search grammar quotes every literal. MIME walking is bounded at 32 levels, 100 MB per message and 25 MB per part; text is stripped of control, ANSI and bidi characters, HTML is reduced with hidden content dropped, and message ids bind account, mailbox, UIDVALIDITY and UID.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Registers only the tools in the expose list, each with read-only MCP annotations and a _meta audit tail. Lists use pipe-delimited rows with cursor paging and a fields selector; mail_read trims quotes and signatures and caps characters; bodies, snippets and attachments are wrapped in untrusted-content markers. Logging is JSON lines on stderr with no subjects, addresses, bodies or filenames. --check validates config, TLS, login and capabilities with exit codes 0, 2, 3, 4 and 5.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Covers config resolution and file modes, TLS ordering and certificate failure, credential scrubbing against a server that echoes the password, the schema guard and tools/list byte budget, message identity and stale ids, the search grammar, MIME bounds and sanitising, every tool's output shape, DD-338 determinism, the --check exit codes, and a hygiene grep for SMTP, HTTP transports, subprocess, eval and IMAP write commands.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
scripts/greenmail.sh runs a digest-pinned GreenMail in Podman or Docker over IMAPS with the test CA and a preloaded corpus: multipart, HTML-only, hidden-text HTML, bidi subject, 40-level nesting, 1.5 MB attachment, non-ASCII mailbox and a thread. The tests prove that \Seen stays unchanged after mail_read and mail_attachment, that nesting hits parse_bounds, that stale ids are refused, and the --check exit codes for OK, a world-readable credential, a wrong password and a hostname mismatch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
README carries the paddle-pattern comparison updated to v0.1 read-only, the configuration reference, the tool table, error codes, degrade paths and the measured tools/list size. SECURITY.md maps each threat to its control. docs/deploy-linux.md covers install, bot user, credential delivery, least privilege, client entry, smoke and rollback for the grokbot hosts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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/imap-blade-mcp!1
No description provided.