feat(mcp): read_artifact + preview_patch + patch_artifact MCP tools — G2c (closes #61)#93
Merged
Merged
Conversation
… G2c (closes #61) Three new devagentic-mutations MCP tools, shipped together because ``patch_artifact`` is unworkable without ``preview_patch`` outside dev-scoped contexts (the confirm_token gate makes them a unit). ## Tools registered | Tool | Wraps | Notes | |---|---|---| | ``read_artifact(path, ctx_id?, strategy?="raw")`` | ``readArtifact`` mutation | 32K cap, or 256K when ctx_id is dev-scoped | | ``preview_patch(path, find, replace)`` | ``previewPatch`` query field | Returns ``{confirm_token, diff, ...}``; read-only | | ``patch_artifact(path, find, replace, confirm_token?, ctx_id?)`` | ``patchArtifact`` mutation | Requires ``confirm_token`` outside dev-scoped/sandbox-backend ctx | #61's scope was nominally 2 tools (read + patch). Reality: the confirm_token gate makes ``patch_artifact`` unusable without ``preview_patch`` — so the three are shipped as the natural unit. ``previewPatch`` is a strawberry field on Query (not Mutation); client + wrapper handle that distinction transparently. ## Devagentic-side resolver verification Schemas read directly from the devagentic api.py via gh api: - ``readArtifact(path, ctx_id?, strategy?, strategy_args?) -> JSON`` - ``previewPatch(path, find, replace) -> JSON`` - ``patchArtifact(path, find, replace, confirm_token?, ctx_id?) -> JSON`` The arg-name camelCase conversion (ctx_id → ctxId, confirm_token → confirmToken) matches strawberry's default snake-to-camel behavior. ## Tests - 12 new client-level tests (4 per tool) in ``tests/plugins/devagentic-mutations/test_client.py``: empty-arg fail-soft, happy-path round-trip with arg threading, strategy / ctx_id / confirm_token threading, in-band errors, non-dict response fail-soft. - Contract test in ``test_mcp_defensive_registrars.py`` extended: ``read_artifact`` / ``preview_patch`` / ``patch_artifact`` added to the required-G2 tool set. - 190 total green across affected suites (mutations + MCP + canvas + docs + subset-filter + autowire). No regression. ## Tracking - Closes #61 (G2c). - G2d (#62 fetchUrl) remains open as the last G2 sub-issue.
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
Closes #61 (G2c sub-issue of #56). Three new devagentic-mutations MCP tools, shipped together because
patch_artifactis unworkable withoutpreview_patchoutside dev-scoped contexts (theconfirm_tokengate makes them a unit).Tools registered
read_artifact(path, ctx_id?, strategy?="raw")readArtifactmutationpreview_patch(path, find, replace)previewPatchquery field{confirm_token, diff, ...}; read-onlypatch_artifact(path, find, replace, confirm_token?, ctx_id?)patchArtifactmutationconfirm_tokenoutside dev-scoped/sandbox-backend ctxScope-expansion note
#61's body nominally scopes 2 tools (
read_artifact+patch_artifact). Field-checking the devagentic resolver showed thatpatchArtifactrequiresconfirm_tokenfrom a priorpreviewPatchcall unless the ctx is dev-scoped or a sandbox-backend is active. Shipping the trio is the only way the patch tool is usable from a normal worker session.Devagentic-side resolver verification
Schemas read directly from devagentic
api.pyviagh api:readArtifact(path, ctx_id?, strategy?, strategy_args?) -> JSONpreviewPatch(path, find, replace) -> JSONpatchArtifact(path, find, replace, confirm_token?, ctx_id?) -> JSONArg-name camelCase conversion (
ctx_id→ctxId,confirm_token→confirmToken) matches strawberry's default snake-to-camel behavior.Test plan
tests/plugins/devagentic-mutations/test_client.pypass (4 per tool: empty-arg fail-soft, happy-path with arg threading, in-band error / strategy / ctx_id / confirm_token threading, non-dict response fail-soft)test_mcp_defensive_registrars.pyextended:read_artifact/preview_patch/patch_artifactadded to required-G2 setTracking