Add schema evolution guardrails and add_field MCP tool#8
Merged
mgoldsborough merged 6 commits intomainfrom Mar 27, 2026
Merged
Conversation
- validate_schema_change(): pure function that detects unsafe schema changes (required-without-default, type changes, enum narrowing, field removal) - _check_required_without_defaults(): warns at validation time when required fields lack defaults (catches the footgun early) - UpjackApp.reload_schema(): hot-reloads entity schema from disk with manifest_dir tracking - add_field MCP tool: lets agents add fields to running apps with structural guardrails (default required, type validation, schema change validation before write) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
get_entity, list_entities, update_entity, and search_entities now accept an optional schema parameter. When provided, missing fields are filled with schema defaults before returning — enabling seamless schema evolution without backfill migrations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- deepcopy schema defaults so hydrated entities don't share mutable objects (lists, dicts) - Validate field names against [a-z][a-z0-9_]* pattern - Reject reserved base entity field names (id, type, status, etc.) - Block path traversal in schema paths - Reject adding a field that already exists, even with matching type
json.dumps doesn't include a trailing newline, causing "No newline at end of file" noise in git diffs.
Tests add_field + hydrate-on-read against real CRM, Todo, and Research Assistant schemas (allOf + $ref composition). Covers get, list, and search read paths after field addition.
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
validate_schema_change()— pure function that compares two schema dicts and returns diagnostics for unsafe changes: required-without-default (error), type change (error), enum narrowing (error), field removal (warning)validate_entity()now logs a warning when required fields lack defaults, catching the footgun early without blockingUpjackApp.reload_schema()— hot-reloads an entity schema from disk via newmanifest_dirtracking on the app instanceadd_fieldMCP tool — lets agents add fields to a running app with structural guardrails: default is required, type is validated,validate_schema_change()gates the write, then schema is reloaded in-placeTest plan
TestValidateSchemaChange— 8 cases (no change, required+default ok, required no default, type change, enum narrow/widen, field removed, multiple issues)TestRequiredWithoutDefaultWarning— 3 cases via caplog (warns, no warn with default, no warn for base fields)TestReloadSchema— 3 cases (picks up file change, unknown entity, no manifest_dir)TestAddFieldTool— 7 cases (registered, writes schema, adds to required, reload+hydrate roundtrip, rejects invalid type, rejects bad default, rejects type conflict)add_fieldtool presence (tool count assertions)make checkpasses (format + lint + typecheck + 255 tests)