Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@ These releases fix URI authority parsing, HTTP parsing and rendering, and IP
address classification issues. They retain the installed major versions and
satisfy their parent dependencies' existing constraints.

## November 18: Remove An Unneeded Agents MCP Wrapper

For projects whose only Agents import is the stateless MCP wrapper, inspect
whether the existing `@modelcontextprotocol/server` version exposes
`createMcpHandler` and `hostHeaderValidationResponse`. Kirjolab's SDK 2.4.0 does.
Agents 0.33.0 brings `@rolldown/plugin-babel` and Vite into the production
dependency graph, making the unpatched
[picomatch advisory](https://github.com/advisories/GHSA-fc5q-39xc-vjpf)
block its production audit.

1. Replace the Agents wrapper import with the existing SDK's handler and
retain `legacy: "stateless"` and request-local server construction.
2. Keep exact-origin validation, authenticated owner selection, route mounting,
and CORS in the application's existing boundary. The SDK handler does not
supply Host or Origin validation: retain an explicit
`hostHeaderValidationResponse(request, allowedHostnames)` check before dispatch.
3. Remove `agents` using the target's pinned npm toolchain, then inspect the
lockfile and installed graph. Preserve unrelated pins and security overrides.
4. Cover Host rejection, stateless legacy protocol behavior, tools/resources,
and owner/origin isolation. Check that build tools are absent or development
only in the production graph. Run the existing audit, typecheck, Workers,
full native CI, and deployment dry runs.

Do not apply this removal to projects using Agent classes, Agents-provided
OAuth context, reverse server requests, or sessionful transports without a
separate compatibility review. Do not move a runtime Agents import to development
dependencies to hide it from the audit, force npm's incompatible Agents 0.8.3
downgrade, or suppress the finding. Development-only picomatch still has no
published patch as of November 18, 2026. See
[ADR-253](../../../docs/adrs/implemented/ADR-253-use-the-mcp-sdk-handler-directly.md).

The historical `patch.diff` and November 12 instructions below are not the
November 18 remedy. Apply this supplement manually to matching existing
graphs, preserving newer compatible fixes and the recorded update ID.

## November 12: Retire The MCP Bridge

For affected Agents/MCP projects, use
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
{
"id": "2026-10-01-patch-transitive-audit-findings",
"title": "Patch transitive audit findings and retire MCP peer overrides",
"title": "Patch transitive audit findings and remove unneeded MCP dependency bridges",
"status": "implemented",
"risk": "medium",
"supersedes": [],
"adrs": [
"docs/adrs/implemented/ADR-245-override-vulnerable-mcp-client-peers.md",
"docs/adrs/implemented/ADR-247-retire-mcp-peer-overrides.md"
"docs/adrs/implemented/ADR-247-retire-mcp-peer-overrides.md",
"docs/adrs/implemented/ADR-253-use-the-mcp-sdk-handler-directly.md"
],
"touches": [
"package.json",
"package-lock.json",
"scripts/research-corpus.test.mjs",
"src/research-corpus/",
"docs/",
"specs/",
"ARCHITECTURE.md"
],
"touches": ["package.json", "package-lock.json", "scripts/research-corpus.test.mjs"],
"checks": ["npm run security:audit", "npm run ci:local"]
}
16 changes: 10 additions & 6 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ Use this file for global constraints. Use feature specs under `specs/` for domai
the writing authority.
- Define application-owned Corpus MCP schemas with Valibot and project tool
schemas through `@valibot/to-json-schema`'s `toStandardJsonSchema`. Preserve
strict input contracts and explicit protocol error mapping. Keep the SDK
server and Agents handler; retain patched Zod only for upstream compatibility,
strict input contracts and explicit protocol error mapping. Use the MCP SDK
server and its stateless HTTP handler directly, with explicit Host validation
and the existing authenticated exact-origin boundary. Retain patched Zod only for upstream compatibility,
with no application Zod imports. See
[ADR-248](docs/adrs/implemented/ADR-248-use-valibot-for-corpus-mcp-schemas.md).
[ADR-248](docs/adrs/implemented/ADR-248-use-valibot-for-corpus-mcp-schemas.md) and
[ADR-253](docs/adrs/implemented/ADR-253-use-the-mcp-sdk-handler-directly.md).
- Reuse the dependency-free unknown-value guard when a handwritten trust
boundary only needs the shared plain-record rule: a non-null object that is
not an array. Do not duplicate that semantic locally or introduce a schema
Expand Down Expand Up @@ -1950,9 +1952,11 @@ Use this file for global constraints. Use feature specs under `specs/` for domai
typed bindings on their Lit owners. Keep global toast presentation in the
workspace coordinator.
- Keep top-navigation visibility, persistence, restore actions, and focus
handoff under one progressive Lit owner. Library restoration belongs in the
Library action row or the private PDF control rail, with each trigger taking
normal layout space in its active surface. Do not position shell recovery
handoff under one progressive Lit owner. Workspace context tabs must not
hide the navigation toggle. Connection-settings shortcuts restore the header
through this owner before opening shared Preferences. Library restoration
belongs in the Library action row or the private PDF control rail, with each
trigger taking normal layout space in its active surface. Do not position shell recovery
controls over unrelated actions or add overlay-specific clearance offsets.
See [ADR-252](docs/adrs/implemented/ADR-252-place-navigation-restore-in-surface-controls.md).
- Allow the ancillary project rail to resize only on desktop, persist its
Expand Down
1 change: 1 addition & 0 deletions docs/adrs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ No accepted-but-unimplemented ADRs.

| ADR | Status | Summary |
| ----------------------------------------------------------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------- |
| [ADR-253](./implemented/ADR-253-use-the-mcp-sdk-handler-directly.md) | Implemented | Use the MCP SDK's stateless handler directly and remove the Agents production build-tool dependency path. |
| [ADR-252](./implemented/ADR-252-place-navigation-restore-in-surface-controls.md) | Implemented | Place Library navigation restoration in normal-flow action and PDF rail slots under one control owner. |
| [ADR-251](./implemented/ADR-251-rewrite-anonymous-pdf-reviews.md) | Implemented | Rewrite anonymous reviews with sanitized annotation authors, metadata removal, and validated fresh PDF bytes. |
| [ADR-249](./implemented/ADR-249-share-immutable-annotated-pdf-copies.md) | Implemented | Share immutable annotated PDF copies through recoverable, revocable owner-created bearer links. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ The adopted components own bounded presentation:
resolution, source-map translation, publication resolution, citation
navigation, and the resulting transitions.
- The preview navigation control owns browser-local top-navigation visibility,
storage restoration, toggle and restore presentation, active-context
availability, and focus handoff between its spatially separated controls.
storage restoration, toggle and restore presentation, and focus handoff
between its spatially separated controls. The workspace toggle is independent
of the active context tab.
- The publication intake panel owns DOI and citation-key input, reviewed
metadata, active-PDF linked-reference projection and rows, its XState workflow
actor, preview and acceptance requests, response validation, stale-response
Expand Down Expand Up @@ -1482,8 +1483,9 @@ components do not duplicate query-and-error boilerplate.
reveals its nearest mapped DOM range directly.
- The preview navigation control owns browser-local top-navigation visibility,
stored restoration, toggle and restore presentation, ARIA and title copy,
restricted-Preview availability, and focus handoff. The application
coordinator supplies only whether Preview is the active workspace context.
and focus handoff. Its workspace toggle remains available across context
tabs. Model settings ask this owner to restore navigation before opening
shared Preferences, retaining one visibility and persistence owner.
- The context tab strip replaces five shell references, three native primary
action bindings, fixed-tab ARIA mutations, coordinator-owned roving focus,
the separate overflow-tab renderer, seven controlled-panel references,
Expand Down
6 changes: 6 additions & 0 deletions docs/adrs/implemented/ADR-247-retire-mcp-peer-overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ MCP contracts, Workers tests, native CI, and production dry run before release.
Keep the stateless handler, Cloudflare Access identity boundary, and owner
scope. This upgrade introduces no OAuth client or credential-storage workflow.

**2026-11-18 amendment:** [ADR-253](./ADR-253-use-the-mcp-sdk-handler-directly.md)
removes Agents and its MCP client peer. Research Corpus calls the existing
MCP SDK's stateless HTTP handler directly. The SDK/core and patched Zod pins
remain, and the retired MCP overrides stay absent. The upstream-compatible
policy still applies to the remaining MCP packages.

## Consequences

**Positive:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ compatibility, consistent with
[ADR-247](./ADR-247-retire-mcp-peer-overrides.md). This migration does not claim
to remove Zod from the installed or bundled upstream dependency graph.

**2026-11-18 transport amendment:**
[ADR-253](./ADR-253-use-the-mcp-sdk-handler-directly.md) replaces only the Agents
wrapper with the MCP SDK's own stateless handler. Valibot schemas, `McpServer`,
the patched upstream Zod dependency, and the Access/owner boundary remain.

## Consequences

**Positive:**
Expand Down
71 changes: 71 additions & 0 deletions docs/adrs/implemented/ADR-253-use-the-mcp-sdk-handler-directly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ADR-253: Use the MCP SDK Handler Directly

**Status:** Implemented

**Date:** 2026-11-18

**Amends:** [ADR-247](./ADR-247-retire-mcp-peer-overrides.md) and
[ADR-248](./ADR-248-use-valibot-for-corpus-mcp-schemas.md)

## Context

The production audit reports
[GHSA-fc5q-39xc-vjpf](https://github.com/advisories/GHSA-fc5q-39xc-vjpf) in
`picomatch@4.0.7`. No patched release is published. Agents 0.33.0 introduces
the production path through `@rolldown/plugin-babel`, Vite, and their glob
dependencies. npm suggests downgrading Agents to 0.8.3, which predates the
current MCP API and is not a compatible remediation.

Kirjolab imports Agents only for `createMcpHandler` from `agents/mcp/server`.
It uses no Agent class, Agents OAuth context, reverse server requests, or
sessionful MCP transport. The already installed MCP server SDK 2.4.0 exposes
the underlying `createMcpHandler` and `hostHeaderValidationResponse` APIs.
Its published handler documentation explicitly supports Workers' standard
`Request`/`Response` interface and requires callers to own Host and Origin
validation. Corpus already owns routing, Access identity, owner selection,
exact-origin validation, and CORS outside the wrapper.

## Decision

Import `createMcpHandler` directly from `@modelcontextprotocol/server` and
remove the Agents dependency. Keep MCP server/core 2.4.0 and patched Zod
4.6.7 without adding packages, overrides, or audit exceptions.

Retain a fresh server per request with `legacy: "stateless"`. Keep Host
validation explicit through the SDK helper before dispatch. Preserve Corpus
origin validation and CORS and the Worker's authenticated `/mcp` routing and
owner selection. Tool/resource schemas, callbacks, and sanitized errors do
not change. GET and DELETE remain unsupported session operations.

Keep the audit's shipped-dependency scope and high-severity failure threshold.
Verify the production dependency graph, audit, MCP contracts, TypeScript,
Workers tests, native CI, and both deployment dry runs. A tooling regression
checks that Agents and its build-tool dependency path cannot enter the
production graph again through this integration.

## Consequences

- Production dependencies no longer contain Agents, its MCP client peer, or
the vulnerable build-tool dependency path. Remaining package versions do
not change.
- Corpus uses the protocol SDK directly and retains one application-owned
authentication and origin boundary.
- The wrapper's optional Agents OAuth and reverse-request compatibility
behavior is unavailable. A future feature needing those capabilities must
make that adoption explicit and repeat security and protocol verification.
- Picomatch remains in development-only tooling and has no published patch
as of this decision. Whole-graph audits still report that finding; the
production audit is not suppressed or weakened.

## Alternatives Considered

- Upgrading picomatch or Agents cannot fix the current graph: 4.0.7 and 0.33.0
are their latest published releases at this decision date.
- Downgrading Agents to npm's suggested 0.8.3 would replace the current MCP
integration with an incompatible API.
- Moving Agents to development dependencies would exclude a runtime import
from the production audit without removing that import.
- A private picomatch patch or unpublished fork would add maintenance for a
dependency Corpus does not need.
- Suppressing the advisory or lowering the audit threshold would preserve the
vulnerable production dependency path and weaken the existing gate.
23 changes: 15 additions & 8 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ and its security fixes remain deferred. Revisit the pin when Cloudflare can
install that release, then repeat the runtime and deployment checks. See
[ADR-011](./adrs/implemented/ADR-011-upgrade-runtime-baseline-to-node-24.md).

The November dependency refresh uses Agents 0.33.0 and MCP server, client,
and core 2.4.0 with Zod 4.6.7. Agents now makes the legacy MCP SDK an optional
peer, and the installed graph omits it. The three retired MCP npm overrides
remain absent. For future upgrades, inspect declared peers and the installed
graph, then run the production audit, type checks, MCP contract tests, Workers
tests, full native CI, and production dry run. Do not restore the retired
bridge or force incompatible installs. See
[ADR-247](./adrs/implemented/ADR-247-retire-mcp-peer-overrides.md).
Research Corpus uses MCP server and core 2.4.0 with Zod 4.6.7. The November 18
audit remediation replaces the Agents wrapper with the SDK's own stateless
HTTP handler and removes Agents and its unrelated build-tool dependency path.
Host validation stays explicit, and the existing Access, owner, origin, and
CORS boundaries remain in place. The MCP client, legacy SDK, and retired MCP
overrides remain absent. For future upgrades, inspect the installed graph,
then run the production audit, type checks, MCP contract tests, Workers tests,
full native CI, and production dry run. See
[ADR-253](./adrs/implemented/ADR-253-use-the-mcp-sdk-handler-directly.md).

`picomatch@4.0.7` remains in development-only tooling. As of November 18,
[GHSA-fc5q-39xc-vjpf](https://github.com/advisories/GHSA-fc5q-39xc-vjpf) has no
patched release, so a whole-graph `npm audit` still reports that advisory.
The required production audit remains unchanged and reports zero findings.
Recheck upstream releases before accepting untrusted glob patterns in tooling.

The repo pins CLI tooling in `devDependencies`, including Wrangler for Cloudflare-based experiments. Prefer invoking those tools through `npx` or repo scripts so the project version is used instead of a global install.

Expand Down
Loading
Loading