Skip to content

Fix template CI: await ctx.error (lint) + clean bundle scan - #14

Merged
mgoldsborough merged 3 commits into
mainfrom
fix/ctx-error-await
Jul 23, 2026
Merged

Fix template CI: await ctx.error (lint) + clean bundle scan#14
mgoldsborough merged 3 commits into
mainfrom
fix/ctx-error-await

Conversation

@mgoldsborough

Copy link
Copy Markdown
Contributor

Green the template's CI

Three failures were red on main (pre-existing, unrelated to any recent docs change). Each one propagates to every server scaffolded from this template, so fixing them at the source fixes the whole fleet.

1. lint (ty) — ctx.error not awaited

FastMCP's Context.error() is async (it sends an MCP log notification). It was called without await in get_client, list_items, and get_item, so the error notifications were silently never sent — a real runtime bug, not just a lint nit. get_client was sync, so it's now async (its only two callers are already async tools) and all three call sites are awaited.

2. scan AI-05 (4× HIGH) — test files packed into the bundle

.mcpbignore excluded /tests/, /test/, /e2e/ but not /tests-integration/, so those .py files were packed and flagged as unexpected executables. Added /tests-integration/.

3. scan CD-02 (2× HIGH) — undeclared secret env access

The code reads EXAMPLE_API_KEY but the manifest declared no environment permission. Added the MTF permissions block under _meta.org.mpaktrust (environment: read, network: outbound since it's an API client).

Verification (local)

  • ty check src/ and ruff check — clean (was 3 ty errors)
  • pytest — 25 pass (the async change is transparent; patch auto-uses AsyncMock on the now-async target)
  • re-pack + re-scan: all 6 HIGH findings cleared, risk HIGH → MEDIUM. The CI scan gate fails only on CRITICAL/HIGH, so it now passes.

Not addressed (intentionally)

The remaining medium/low/info findings and the Level: None trust level don't gate CI and are out of scope here — a template scanned as a raw bundle won't earn a provenance level (no signed/attested build).

Three pre-existing failures on main, all of which propagate to every server
scaffolded from this template:

- lint (ty): ctx.error() is async in FastMCP but was called without await in
  get_client/list_items/get_item, so the error notifications were never sent.
  Made get_client async and awaited all three call sites.
- scan AI-05 (4x HIGH): tests-integration/ was packed into the bundle
  (unlisted in .mcpbignore) and flagged as unexpected executables. Excluded it.
- scan CD-02 (2x HIGH): the code reads the EXAMPLE_API_KEY secret env var but
  the manifest declared no environment permission. Added the MTF permissions
  block (environment: read, network: outbound).

Verified locally: ty + ruff clean, 25 tests pass, and a re-scan drops all 6
HIGH findings (risk HIGH -> MEDIUM), so the critical/high CI gate passes.
The scanner prints 'Scanning <bundle>...' to stdout before the JSON, so
'--json > scan-results.json' produced a file json.load couldn't parse
(Expecting value: line 1 column 1). This was latent — the scanner step used
to exit 1 on HIGH findings before the parse step ran. With the HIGH findings
cleared, the scanner exits 0 and the parse bug surfaced. Use the scanner's
-o flag (its intended machine-readable output) so the file is clean JSON.
The server reads its bundled SKILL.md via importlib.resources at import
time, so the MTF permissions block must declare filesystem access. With
filesystem "none" the scanner raises CD-02 (undeclared filesystem
permission, MEDIUM); declaring "read" makes the declaration accurate and
drops the bundle's scan risk score to LOW.
@mgoldsborough mgoldsborough added the qa-reviewed QA review completed with no critical issues label Jul 23, 2026
@mgoldsborough
mgoldsborough merged commit 9cc7532 into main Jul 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa-reviewed QA review completed with no critical issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant