Add regenerate command and auto-regenerate stale codegen on startup#6
Merged
Conversation
Re-running an API's code generation after an anyapi-mcp upgrade previously required re-adding it, which destroys stored credentials: a bearer API re-added without --token resolves to auth:none, and its keystore token is then deleted. Add a codegen-only path that preserves auth instead. - regenerate [id ...] [--stale-only]: re-fetch each API's saved source and rebuild its typed client + operation index in place. Auth, baseUrl, and hosts are preserved; no secret is written or deleted (a bearer token is only read, to re-introspect a source that needs it). Each API is independent, so one unreachable source never blocks the rest. - Stamp generated artifacts with CODEGEN_VERSION. serve regenerates any entry with an older or missing stamp on startup, before connecting, with all logging on stderr. A re-fetch failure is logged and keeps the old code.
There was a problem hiding this comment.
Pull request overview
Adds a “codegen refresh” workflow so users can rebuild cached generated clients/operation indexes after upgrading anyapi-mcp without re-registering (and therefore without clobbering/deleting stored credentials). It also teaches serve to auto-regenerate stale entries on startup based on a stored codegen contract version.
Changes:
- Introduce
CODEGEN_VERSION+ per-entrycodegenVersionto detect stale generated artifacts. - Add
regenerateApi(s)core logic and a newanyapi-mcp regenerateCLI subcommand. - Auto-regenerate stale entries on
servestartup while keeping MCP stdout clean (stderr-only diagnostics).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/registry.ts | Adds codegenVersion field to registry entries for staleness detection. |
| src/register.ts | Defines CODEGEN_VERSION and implements regenerateApi(s) to rebuild codegen in place. |
| src/main.ts | Wires the new regenerate subcommand into CLI dispatch/usage. |
| src/commands/serve.ts | Regenerates stale entries on startup before serving (stderr-only). |
| src/commands/regenerate.ts | New CLI command for targeted/all regeneration with --stale-only. |
| README.md | Documents the new regenerate command and serve startup regeneration behavior. |
| CLAUDE.md | Updates contributor/architecture docs to include regeneration behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
59
to
60
| /** Absolute path to the generated .d.ts in the cache dir. */ | ||
| typesPath: string; |
Comment on lines
+77
to
+79
| generated artifact is stamped with `CODEGEN_VERSION`; bump that constant when | ||
| a generator change makes old artifacts stale, and `serve` regenerates anything | ||
| older on startup (an entry missing the stamp counts as stale). |
Address review: typesPath is a .d.ts only for OpenAPI/GraphQL (SOAP emits a .ts runtime module), and the version stamp lives on the registry entry's codegenVersion field, not embedded in the generated artifacts themselves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-running an API's code generation after an
anyapi-mcpupgrade previously meant re-adding it, which destroys stored credentials: a bearer API re-added without--tokenresolves toauth: none, andcleanupOrphanedSecretsthen deletes its keystore token. This adds a codegen-only path that preserves auth.What's new
anyapi-mcp regenerate [id ...] [--stale-only]— re-fetches each API's saved source and rebuilds its typed client + operation index in place. Auth,baseUrl, andhostsare preserved verbatim; no secret is written or deleted (a bearer token is only read, to re-introspect a source that needs it). Per-API isolation: one unreachable source never blocks the rest.CODEGEN_VERSIONstamp — every generated artifact records the codegen-contract version it was built under (a deliberate counter, not the git hash, so doc-only releases don't force needless re-fetches).serveregenerates any entry with an older or missing stamp on startup, before connecting, logging only to stderr. A re-fetch failure is logged and keeps the existing (working) code. Entries written before this field count as stale, so they migrate on first upgraded boot.Test plan
Verified against a live registry (OpenAPI no-auth/OAuth + GraphQL):
regeneraterebuilt all entries incl. a 3068-op spec; an OAuth API (Strava) stayed logged in throughout — credentials untouched.servestartup regenerated only stale entries; a second boot regenerated zero (idempotent — no steady-state network cost).deno task check && lint && fmtclean; 9/9 tests pass.