-
-
Notifications
You must be signed in to change notification settings - Fork 67
Add paren_repair MCP tool for fixing delimiter errors #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- New tool that detects and fixes unbalanced parentheses, brackets, and braces - Uses parinfer indent mode for repair - Optionally formats with cljfmt based on config setting - Returns status message with unified diff of changes - Validates file paths using existing valid-paths utility
📝 WalkthroughWalkthroughAdds a new parenthesis-repair tool: a registry entry in Changes
Sequence DiagramsequenceDiagram
autonumber
actor User
participant ToolSys as Tool System
participant Repair as Paren Repair Core
participant Delim as Delimiter Detector
participant Parinfer as Parinfer Repair
participant Format as Formatter
participant FileUtil as File Utility
participant Diff as Diff Utility
User->>ToolSys: invoke paren-repair-tool (file_path)
ToolSys->>ToolSys: validate inputs & normalize path
ToolSys->>Repair: repair-file!(file-path, nrepl-map)
Repair->>FileUtil: read file (UTF-8)
FileUtil-->>Repair: original content
Repair->>Delim: detect delimiter errors
Delim-->>Repair: errors? (yes/no)
alt Errors detected
Repair->>Parinfer: parinfer-repair(content)
Parinfer-->>Repair: repaired content
end
alt Formatting enabled
Repair->>Format: format-code(content, project-options)
Format-->>Repair: formatted content
end
alt Content changed
Repair->>FileUtil: write file (UTF-8)
FileUtil-->>Repair: write complete
end
Repair->>Diff: generate unified diff(original, final)
Diff-->>Repair: diff text
Repair-->>ToolSys: result map {success, status, delim-fixed?, formatting?, diff}
ToolSys-->>User: formatted response (status + diff)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
Pre-merge checks✅ Passed checks (3 passed)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/clojure_mcp/tools/paren_repair/core.clj (1)
114-120: Minor edge case in status message.If
delimiter/delimiter-error?returns true butparinfer-repairproduces identical content (unlikely but theoretically possible), the message "No changes needed (no delimiter errors)" would be slightly misleading. Consider a more generic message like "No changes needed" if this edge case matters.src/clojure_mcp/tools/paren_repair/tool.clj (2)
20-32: Consider documenting the optional cljfmt formatting in the description.The
core/repair-file!function also applies cljfmt formatting when enabled in config, but the tool description only mentions parinfer repair. Users may be surprised to see formatting changes in the diff output. Based on learnings, the:descriptionshould provide clear guidance for LLM usage.🔎 Suggested description update
(defmethod tool-system/tool-description :paren-repair [_] "Fix delimiter errors (unbalanced parentheses, brackets, braces) in a Clojure file using parinfer. Use this tool when: - A file has unbalanced delimiters causing parse errors - You need to repair a file after an incomplete edit - The file won't compile due to missing closing parens/brackets The tool will: 1. Detect delimiter errors using edamame parser 2. Repair using parinfer's indent mode +3. Optionally format with cljfmt if enabled in project config Returns a status message and diff showing what changed.")
61-68: Minor: Misleading comment.The comment "Backward compatibility function" appears copied from another tool. Since this is a new tool, consider updating to just describe that it returns the registration map.
🔎 Suggested comment update
-;; Backward compatibility function that returns the registration map +;; Public API function that returns the registration map (defn paren-repair-tool
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/clojure_mcp/tools.cljsrc/clojure_mcp/tools/paren_repair/core.cljsrc/clojure_mcp/tools/paren_repair/tool.clj
🧰 Additional context used
📓 Path-based instructions (1)
**/*.clj
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.clj: Use:requirewith ns aliases in Clojure imports (e.g.,[clojure.string :as string])
Use kebab-case for variable and function names in Clojure
End Clojure predicate functions with?(e.g.,is-top-level-form?)
Usetry/catchwith specific exception handling in Clojure; use atom for tracking errors
Use 2-space indentation in Clojure code and maintain whitespace in edited forms
Align Clojure namespaces with directory structure (e.g.,clojure-mcp.repl-tools)
Include clear tool:descriptionin MCP tools for LLM guidance
Validate inputs and provide helpful error messages in MCP tool implementations
Return structured data with both result and error status in MCP tool responses
Maintain atom-based state for consistent service access in MCP tool implementations
Files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools.cljsrc/clojure_mcp/tools/paren_repair/core.clj
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Include clear tool `:description` in MCP tools for LLM guidance
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Validate inputs and provide helpful error messages in MCP tool implementations
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Align Clojure namespaces with directory structure (e.g., `clojure-mcp.repl-tools`)
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Return structured data with both result and error status in MCP tool responses
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Include clear tool `:description` in MCP tools for LLM guidance
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools.cljsrc/clojure_mcp/tools/paren_repair/core.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Align Clojure namespaces with directory structure (e.g., `clojure-mcp.repl-tools`)
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools.cljsrc/clojure_mcp/tools/paren_repair/core.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Validate inputs and provide helpful error messages in MCP tool implementations
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools/paren_repair/core.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Maintain atom-based state for consistent service access in MCP tool implementations
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Return structured data with both result and error status in MCP tool responses
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools/paren_repair/core.clj
📚 Learning: 2025-12-27T06:54:07.157Z
Learnt from: nandoolle
Repo: bhauman/clojure-mcp PR: 138
File: src/clojure_mcp/agent/langchain/model.clj:91-97
Timestamp: 2025-12-27T06:54:07.157Z
Learning: When reviewing Clojure code (e.g., in src/clojure_mcp/... ), verify calls to presets/get-preset follow the two arities: [preset-key] and [preset-key overrides]. The 2-arg version should merge the provided overrides map with the preset defaults and return the resulting configuration. Check for correct map merging, preservation of immutability, and validation of overrides keys to ensure predictable configuration outcomes.
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.cljsrc/clojure_mcp/tools.cljsrc/clojure_mcp/tools/paren_repair/core.clj
🔇 Additional comments (10)
src/clojure_mcp/tools/paren_repair/core.clj (4)
1-11: LGTM!Namespace aligns with directory structure and imports use
:asaliases per coding guidelines.
13-21: LGTM!The predicate function follows naming conventions with
?suffix. Using a set for extensions andsomefor matching is idiomatic.
59-96: Well-structured repair logic with good defensive programming.The sequential repair steps (delimiter fix → format) with proper fallbacks on formatting failure is resilient. The structured return values align with MCP tool response guidelines.
122-136: LGTM!Good separation of
ExceptionInfo(for controlled errors withex-info) vs generalExceptionhandling. Both paths return structured error maps per MCP tool guidelines.src/clojure_mcp/tools.clj (1)
25-26: LGTM!The
paren-repair-toolis appropriately placed inediting-tool-symssince it modifies files. The symbol path correctly references the new tool namespace.src/clojure_mcp/tools/paren_repair/tool.clj (5)
1-15: LGTM!Namespace correctly aligns with directory structure. The tool configuration stores the
nrepl-client-atomfor consistent state access per guidelines.
34-38: LGTM!Schema is well-defined with clear property description including supported file extensions.
40-48: LGTM!Input validation follows guidelines with clear error messages. Path validation delegates to the existing utility function. The transformation from
file_path(JSON convention) tofile-path(Clojure convention) is appropriate.
50-51: LGTM!Clean delegation to core logic.
53-59: LGTM!Result formatting follows MCP tool response guidelines, returning structured data with both result and error status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/clojure_mcp/tools/paren_repair/tool.clj (1)
57-64: Consider clarifying "backward compatibility" wording.The comment describes this as a "backward compatibility function," but it appears to be the primary public entry point for registering the tool. Unless there's a newer registration approach this is maintaining compatibility with, consider rewording to something like "Public function that returns the registration map for the paren-repair tool" to avoid confusion.
🔎 Suggested docstring clarification
-(defn paren-repair-tool - "Returns the registration map for the paren-repair tool. +;; Public API for registering the tool +(defn paren-repair-tool + "Returns the registration map for the paren-repair tool.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/clojure_mcp/tools/paren_repair/tool.clj
🧰 Additional context used
📓 Path-based instructions (1)
**/*.clj
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.clj: Use:requirewith ns aliases in Clojure imports (e.g.,[clojure.string :as string])
Use kebab-case for variable and function names in Clojure
End Clojure predicate functions with?(e.g.,is-top-level-form?)
Usetry/catchwith specific exception handling in Clojure; use atom for tracking errors
Use 2-space indentation in Clojure code and maintain whitespace in edited forms
Align Clojure namespaces with directory structure (e.g.,clojure-mcp.repl-tools)
Include clear tool:descriptionin MCP tools for LLM guidance
Validate inputs and provide helpful error messages in MCP tool implementations
Return structured data with both result and error status in MCP tool responses
Maintain atom-based state for consistent service access in MCP tool implementations
Files:
src/clojure_mcp/tools/paren_repair/tool.clj
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Include clear tool `:description` in MCP tools for LLM guidance
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Validate inputs and provide helpful error messages in MCP tool implementations
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Align Clojure namespaces with directory structure (e.g., `clojure-mcp.repl-tools`)
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Return structured data with both result and error status in MCP tool responses
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Include clear tool `:description` in MCP tools for LLM guidance
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Align Clojure namespaces with directory structure (e.g., `clojure-mcp.repl-tools`)
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Validate inputs and provide helpful error messages in MCP tool implementations
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Maintain atom-based state for consistent service access in MCP tool implementations
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
📚 Learning: 2026-01-02T16:18:02.404Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-02T16:18:02.404Z
Learning: Applies to **/*.clj : Return structured data with both result and error status in MCP tool responses
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
📚 Learning: 2025-12-27T06:54:07.157Z
Learnt from: nandoolle
Repo: bhauman/clojure-mcp PR: 138
File: src/clojure_mcp/agent/langchain/model.clj:91-97
Timestamp: 2025-12-27T06:54:07.157Z
Learning: When reviewing Clojure code (e.g., in src/clojure_mcp/... ), verify calls to presets/get-preset follow the two arities: [preset-key] and [preset-key overrides]. The 2-arg version should merge the provided overrides map with the preset defaults and return the resulting configuration. Check for correct map merging, preservation of immutability, and validation of overrides keys to ensure predictable configuration outcomes.
Applied to files:
src/clojure_mcp/tools/paren_repair/tool.clj
🔇 Additional comments (3)
src/clojure_mcp/tools/paren_repair/tool.clj (3)
1-6: LGTM! Namespace and imports follow conventions.The namespace correctly uses hyphens while the directory path uses underscores (standard Clojure convention), and all requires use aliases as per coding guidelines.
8-34: Excellent tool metadata! Clear description and schema.The tool description provides helpful context about when to use the tool, and the schema clearly documents the required file_path parameter with supported file extensions. This follows the coding guideline to include clear tool descriptions for LLM guidance.
36-55: Update contract specification forcore/repair-file!.The
validate-path-with-clientcontract is correctly specified. However,repair-file!returns a map with six fields, not four:
:success- boolean indicating overall success:file-path- the processed file path:message- human-readable status message:delimiter-fixed- boolean (was delimiter error fixed?):formatted- boolean (was cljfmt applied?):diff- unified diff of changes (or nil)The
format-resultsimplementation safely ignores the extra fields through destructuring, so the code works correctly, but the contract documentation should be complete.Likely an incorrect or invalid review comment.
Summary
paren_repairMCP tool that fixes unbalanced parentheses, brackets, and braces in Clojure filesFiles
src/clojure_mcp/tools/paren_repair/core.clj- Core repair logicsrc/clojure_mcp/tools/paren_repair/tool.clj- MCP tool definitionsrc/clojure_mcp/tools.clj- Registered the new toolExample Output
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.