Repository navigation
Feat mcp bulk attributes - #55
Merged
Merged
Conversation
…ction) create_entity + N add_attribute calls was O(N) MCP round trips AND O(N) full load/save/validate cycles — building a 54-column entity meant 55 calls, and a mid-sequence failure left a half-built entity. Add a bulk path end to end: - core: new add_attributes command adds many columns to one entity in a single load->append-all->one save->one validate; create_entity takes an optional inline attributes list. Both share _append_attribute, which rejects a duplicate name against existing columns AND earlier in the same batch, so the whole batch is all-or-nothing. CommandResult gains created_ids (the full list; created_id stays the first id for back-compat). - mcp: create_entity gains an attributes param; update_entity's add_attribute accepts EITHER one object or a list. New ids come back as created_ids / attribute_ids so an agent can build a composite key from them with no re-read. - server: add_attributes is proposable (SME PR flow); preview records a bulk change's primary (first) id, mirroring apply_command. Tests: core (inline create, bulk add, all-or-nothing on dup, empty-list reject, supplied-id parity) + mcp (one-call wide entity, list add, dup roll-back, and the create->key-group-from-returned-ids money path). Full suite 999 passed.
The MCP tools returned every minted id from a bulk create_entity/add_attributes, but the HTTP command route returned only created_id (the first id) — a canvas/API caller doing a bulk create got the entity id and lost the new attribute ids, forcing a re-read to reference the columns. Echo created_ids on the response when a command minted more than one id, matching the MCP _write convention; single-create responses are unchanged (created_id alone). Test: HTTP bulk create_entity returns entity id + each column id in order; single create has created_id and no created_ids.
Merged
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.
Create entities and add attributes in bulk via MCP
Building a wide entity through the agent/MCP surface was create_entity + N separate add_attribute calls. For a 54-column entity that’s 55 round trips and 55 full load → mutate → save → validate cycles, and any mid-sequence failure left a half-built entity. (This came from real Copilot usage.)
What it does — one validated transaction, both create and update paths
create_entity(..., attributes=[...]) builds the entity shell and all its columns in a single call. Pass [{name, domain?, role?, nullable?}] (domain defaults to string, nullable to true).
update_entity’s add_attribute now accepts a list as well as a single object — widening an existing entity by many columns in one transaction.
Both are all-or-nothing: a duplicate column name (against existing columns or earlier in the same batch) rejects the whole batch before anything is written.
New ids come back as created_ids / attribute_ids (entity first, then each column in order) so an agent can feed them straight into create_key_group with no re-read — the composite-PK “money path.”
Backward compatibility
created_id (scalar) is preserved as the first id, so existing single-create callers are unchanged. The bulk ids are surfaced as created_ids on both the MCP tools and the HTTP /api/command response (added in 6b37fe0), so a canvas/API caller can reference new columns without a re-read. The CLI has no bulk path; the preview/propose map intentionally keeps one primary id per change.