Skip to content

feat: fetch OpenAPI spec from R2 binding instead of bundling - #11

Merged
mattzcarey merged 1 commit into
mainfrom
fix/json-spec-fetching
Feb 16, 2026
Merged

feat: fetch OpenAPI spec from R2 binding instead of bundling#11
mattzcarey merged 1 commit into
mainfrom
fix/json-spec-fetching

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the 45MB bundled spec from the worker. The processed OpenAPI spec (with all $refs resolved) was previously imported at build time and embedded into every deployment.
  • Stores the spec in R2, read directly via the SPEC_BUCKET R2 binding — no HTTP routes or caching layer needed.
  • Adds a daily cron trigger (0 0 * * * UTC) with a scheduled() handler that fetches the latest spec from GitHub, resolves $refs, and writes both spec.json and products.json to R2.
  • Extracts shared spec processing into src/spec-processor.ts with full test coverage.
  • Makes account_id optional in the execute tool — auto-selects for single-account users, shows a picker for multi-account (incorporates fix: account ID negotiation for multi-account OAuth users #8).
  • Cleans up OAuth scope templates — removes broken security-full and full-access templates, trims read-only to essential scopes. See OAuth fails when too many scopes are requested #12 for the scope limit issue.
  • Adds OPENAPI_SPEC_URL as an environment variable across all environments.
  • Adds R2 seed script (scripts/seed-r2.ts) for populating staging/production R2 buckets.

How it works

Cron (daily midnight UTC)
  → fetch raw spec from GitHub
  → resolve $refs, extract products
  → write spec.json + products.json to R2

Search request
  → env.SPEC_BUCKET.get('spec.json')
  → spec text passed to sandbox worker for search execution

Server startup
  → env.SPEC_BUCKET.get('products.json')
  → product list used in search tool description

Closes #8

Test plan

  • All 68 tests pass (npm run check)
  • TypeScript compiles cleanly
  • Deployed to staging, search + execute tools verified
  • R2 buckets created and seeded (mcp-spec-staging)
  • OAuth flow works with read-only, workers-full, dns-full templates

@mattzcarey
mattzcarey force-pushed the fix/json-spec-fetching branch 5 times, most recently from a3fe280 to 923c63b Compare February 16, 2026 13:57
@mattzcarey
mattzcarey force-pushed the fix/json-spec-fetching branch 3 times, most recently from 70ebe7a to 19fb952 Compare February 16, 2026 14:07
@mattzcarey mattzcarey changed the title Fix: fetch OpenAPI spec from R2 via HTTP cache instead of bundling feat: fetch OpenAPI spec from R2 binding instead of bundling Feb 16, 2026
Replace build-time spec bundling with runtime fetching from R2,
cached at each PoP via Cloudflare HTTP cache.

- Add scheduled handler (daily cron) to fetch spec from GitHub,
  resolve $refs, and write spec.json + products.json to R2
- Serve /spec.json and /products.json from R2 in default handler
- Search executor and server fetch via cached self-request
- Extract shared spec-processor module for processing logic
- Extract fetch-cached module for cached data fetching
- Add scripts/seed-r2.ts for manually seeding staging/prod R2
- Delete build-spec.ts and static products.ts (no longer needed)
@mattzcarey
mattzcarey force-pushed the fix/json-spec-fetching branch from 19fb952 to 38fa389 Compare February 16, 2026 14:18
@mattzcarey
mattzcarey merged commit b0f9fa8 into main Feb 16, 2026
1 check passed
@mattzcarey
mattzcarey deleted the fix/json-spec-fetching branch February 16, 2026 14:21
mattzcarey added a commit that referenced this pull request Feb 16, 2026
Replace build-time spec bundling with runtime fetching from R2,
cached at each PoP via Cloudflare HTTP cache.

- Add scheduled handler (daily cron) to fetch spec from GitHub,
  resolve $refs, and write spec.json + products.json to R2
- Serve /spec.json and /products.json from R2 in default handler
- Search executor and server fetch via cached self-request
- Extract shared spec-processor module for processing logic
- Extract fetch-cached module for cached data fetching
- Add scripts/seed-r2.ts for manually seeding staging/prod R2
- Delete build-spec.ts and static products.ts (no longer needed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant