Add dry_run to tool schemas for editing tools#153
Conversation
📝 WalkthroughWalkthroughAdded an optional Changes
Sequence Diagram(s)(omitted — changes are schema and validation only, not multi-component control flow) Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
src/clojure_mcp/tools/file_edit/tool.clj (1)
35-46:⚠️ Potential issue | 🟡 MinorValidate
dry_runvalues invalidate-inputs.The schema now exposes
dry_run, but invalid values can still flow into the pipeline and produce unclear errors. Add an explicit guard when:dry_runis present.(when (contains? inputs :dry_run) (when-not (#{"diff" "new-source"} dry_run) (throw (ex-info (str "Invalid dry_run: " dry_run ". Supported values: diff, new-source") {:inputs inputs}))))As per coding guidelines, "Validate inputs and provide helpful error messages in MCP tool implementations".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/clojure_mcp/tools/file_edit/tool.clj` around lines 35 - 46, Add explicit validation for the :dry_run input in the validate-inputs function so invalid values are rejected early: in validate-inputs, when (contains? inputs :dry_run) check that the value (get inputs :dry_run) is one of "diff" or "new-source", and if not throw an explanatory ex-info containing the bad value and the inputs map (e.g., "Invalid dry_run: ... Supported values: diff, new-source"). This guard should reference the inputs map and :dry_run key and ensure only the allowed enum values flow into the rest of the file-edit pipeline.src/clojure_mcp/tools/form_edit/tool.clj (1)
48-69:⚠️ Potential issue | 🟡 MinorAdd explicit
dry_runvalidation.
dry_runis now part of the public schema, but invalid values aren’t rejected invalidate-inputs. Please add a guard so callers get a clear error.(when (contains? inputs :dry_run) (when-not (#{"diff" "new-source"} dry_run) (throw (ex-info (str "Invalid dry_run: " dry_run ". Supported values: diff, new-source") {:inputs inputs}))))As per coding guidelines, "Validate inputs and provide helpful error messages in MCP tool implementations".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/clojure_mcp/tools/form_edit/tool.clj` around lines 48 - 69, Add explicit validation for the dry_run input in the tool's input validation path (the validate-inputs function used by the :clojure-update-sexp tool) so invalid values are rejected with a clear error; specifically, in the input validation logic referenced by tool-system/tool-schema :clojure-update-sexp, check (when (contains? inputs :dry_run)) and throw an ex-info if the value is not one of "diff" or "new-source" (include the offending value and inputs in the exception data) to mirror the schema and provide a helpful error message to callers.src/clojure_mcp/tools/form_edit/combined_edit_tool.clj (1)
101-118:⚠️ Potential issue | 🟡 MinorValidate
dry_runinvalidate-inputs.The new schema parameter isn’t validated, so invalid values can make it to the pipeline. Add an explicit check before building the validated map.
(when (contains? inputs "dry_run") (when-not (#{"diff" "new-source"} dry_run) (throw (ex-info (str "Invalid dry_run: " dry_run ". Supported values: diff, new-source") {:inputs inputs}))))As per coding guidelines, "Validate inputs and provide helpful error messages in MCP tool implementations".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/clojure_mcp/tools/form_edit/combined_edit_tool.clj` around lines 101 - 118, In validate-inputs, add an explicit validation for the "dry_run" key: if (contains? inputs "dry_run") check that the value bound to dry_run is one of "diff" or "new-source" and throw an ex-info with a clear message and the inputs map when it is not; locate the check in the validate-inputs function before the validated map is constructed and reference the "dry_run" symbol and inputs map so invalid values never proceed into the pipeline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/clojure_mcp/tools/file_edit/tool.clj`:
- Around line 35-46: Add explicit validation for the :dry_run input in the
validate-inputs function so invalid values are rejected early: in
validate-inputs, when (contains? inputs :dry_run) check that the value (get
inputs :dry_run) is one of "diff" or "new-source", and if not throw an
explanatory ex-info containing the bad value and the inputs map (e.g., "Invalid
dry_run: ... Supported values: diff, new-source"). This guard should reference
the inputs map and :dry_run key and ensure only the allowed enum values flow
into the rest of the file-edit pipeline.
In `@src/clojure_mcp/tools/form_edit/combined_edit_tool.clj`:
- Around line 101-118: In validate-inputs, add an explicit validation for the
"dry_run" key: if (contains? inputs "dry_run") check that the value bound to
dry_run is one of "diff" or "new-source" and throw an ex-info with a clear
message and the inputs map when it is not; locate the check in the
validate-inputs function before the validated map is constructed and reference
the "dry_run" symbol and inputs map so invalid values never proceed into the
pipeline.
In `@src/clojure_mcp/tools/form_edit/tool.clj`:
- Around line 48-69: Add explicit validation for the dry_run input in the tool's
input validation path (the validate-inputs function used by the
:clojure-update-sexp tool) so invalid values are rejected with a clear error;
specifically, in the input validation logic referenced by
tool-system/tool-schema :clojure-update-sexp, check (when (contains? inputs
:dry_run)) and throw an ex-info if the value is not one of "diff" or
"new-source" (include the offending value and inputs in the exception data) to
mirror the schema and provide a helpful error message to callers.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/clojure_mcp/tools/file_edit/tool.cljsrc/clojure_mcp/tools/form_edit/combined_edit_tool.cljsrc/clojure_mcp/tools/form_edit/tool.clj
fefdd91 to
7409ecd
Compare
|
Thanks for the review! Added explicit |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/clojure_mcp/tools/file_edit/tool.clj`:
- Around line 72-76: The dry_run validation incorrectly checks membership using
a set that includes nil, causing nil to be treated as invalid due to Clojure's
truthiness rules; update the guard so you only validate when :dry_run is present
and non-nil (use some? on (:dry_run inputs)) and then check membership against
the allowed values set #{"diff" "new-source"} before throwing the ex-info; refer
to the existing symbols inputs and :dry_run and the throw/ex-info block to
locate and change the conditional.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/clojure_mcp/tools/file_edit/tool.cljsrc/clojure_mcp/tools/form_edit/combined_edit_tool.cljsrc/clojure_mcp/tools/form_edit/tool.clj
🚧 Files skipped from review as they are similar to previous changes (1)
- src/clojure_mcp/tools/form_edit/tool.clj
…edit_replace_sexp The dry_run parameter was already supported in the pipeline and execution code (PR bhauman#121) but was missing from the tool-schema definitions, so MCP clients like Claude Code couldn't discover or pass the parameter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7409ecd to
f0b638b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/clojure_mcp/tools/form_edit/tool.clj (1)
71-117: Use kebab-case for localdry-runbinding.Local symbol
dry_runviolates the kebab-case naming guideline. Consider aliasing todry-runwhile keeping the input key:dry_run.♻️ Minimal refactor
(defmethod tool-system/validate-inputs :clojure-update-sexp [{:keys [nrepl-client-atom multi-op]} inputs] (let [file-path (validate-file-path inputs nrepl-client-atom) - {:keys [match_form new_form operation replace_all whitespace_sensitive dry_run]} inputs] + {:keys [match_form new_form operation replace_all whitespace_sensitive] :as inputs} inputs + dry-run (:dry_run inputs)] ... - (when (and dry_run (not (#{"diff" "new-source"} dry_run))) - (throw (ex-info (str "Invalid dry_run: " dry_run + (when (and dry-run (not (#{"diff" "new-source"} dry-run))) + (throw (ex-info (str "Invalid dry_run: " dry-run ". Supported values: diff, new-source") {:inputs inputs}))) {:file_path file-path :match_form match_form :new_form new_form :operation operation :replace_all (boolean (if (#{"insert_before" "insert_after"} operation) false (or replace_all false))) :whitespace_sensitive (boolean (or whitespace_sensitive false)) - :dry_run dry_run})) + :dry_run dry-run}))As per coding guidelines, use kebab-case for variable and function names in Clojure.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/clojure_mcp/tools/form_edit/tool.clj` around lines 71 - 117, The local binding dry_run in the defmethod for tool-system/validate-inputs :clojure-update-sexp violates kebab-case; change the destructuring to stop binding :dry_run directly (keep :dry_run key in inputs) and introduce a kebab-case local like dry-run (e.g., remove dry_run from :keys and add (let [dry-run (:dry_run inputs)] ...) or bind it with :or/rename style), then update all references from dry_run to dry-run inside the method (affecting the dry_run validation near the end). Ensure only the local symbol name changes; the input key :dry_run remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/clojure_mcp/tools/form_edit/tool.clj`:
- Around line 71-117: The local binding dry_run in the defmethod for
tool-system/validate-inputs :clojure-update-sexp violates kebab-case; change the
destructuring to stop binding :dry_run directly (keep :dry_run key in inputs)
and introduce a kebab-case local like dry-run (e.g., remove dry_run from :keys
and add (let [dry-run (:dry_run inputs)] ...) or bind it with :or/rename style),
then update all references from dry_run to dry-run inside the method (affecting
the dry_run validation near the end). Ensure only the local symbol name changes;
the input key :dry_run remains unchanged.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/clojure_mcp/tools/file_edit/tool.cljsrc/clojure_mcp/tools/form_edit/combined_edit_tool.cljsrc/clojure_mcp/tools/form_edit/tool.clj
🚧 Files skipped from review as they are similar to previous changes (2)
- src/clojure_mcp/tools/file_edit/tool.clj
- src/clojure_mcp/tools/form_edit/combined_edit_tool.clj
|
Generally, yes kebab case, but in this case, it seems like there is already an established pattern of using underscore, for example file_path, new_string, old_string. I'm guessing the underscore is more conventional for the agent interface. |
Summary
PR #121 added
dry_runsupport to the editing tool pipelines (file_edit,clojure_edit,clojure_edit_replace_sexp), allowing clients to preview changes as a diff or full source without writing to disk. However, thedry_runparameter was only added to the pipeline and execution code — it was not added to thetool-schemadefinitions.This means MCP clients that rely on the advertised tool schema to discover available parameters — such as Claude Code — have no way to know
dry_runexists. Claude Code will only send parameters that appear in the tool's JSON schema, so in practicedry_runis unusable from Claude Code despite the backend fully supporting it.This PR adds
dry_runto the:propertiesmap of thetool-schemamultimethod for all three affected tools::file-edit(file_edit/tool.clj):clojure-edit-form(form_edit/combined_edit_tool.clj):clojure-update-sexp(form_edit/tool.clj)The parameter is optional (not in
:required) withenum ["diff" "new-source"], matching the existing pipeline behavior.Test plan
dry_run: "diff"returns a diff without writing the file for each of the three toolsdry_run: "new-source"returns full modified source without writingdry_runwrites the file as before (no regression)tools/list)🤖 Generated with Claude Code
Summary by CodeRabbit