feat (mcp): add the helm_template tool call to the MCP server to render manifests#39
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a new async public tool function Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as Client/UI
participant MCP as MCP Server
participant Helm as Helm CLI
participant FS as Temp File
User->>UI: Request render (release, chart, ns?, values?, include_crds?)
UI->>MCP: Call helm_template(params)
alt values provided
MCP->>FS: Create temp file with YAML values
MCP->>Helm: helm template <release> <chart> [-n ns] -f <temp> [--include-crds]
Helm-->>MCP: Rendered YAML or error
MCP->>FS: Cleanup temp file
else no values
MCP->>Helm: helm template <release> <chart> [-n ns] [--include-crds]
Helm-->>MCP: Rendered YAML or error
end
alt success
MCP-->>UI: ToolOutput { content: rendered YAML }
else error
MCP-->>UI: ToolOutput { error: message }
end
rect rgba(200,235,255,0.25)
note right of MCP: Read-only operation (annotation)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
mcp/tools/helm.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.13.3)
mcp/tools/helm.py
358-358: Consider moving this statement to an else block
(TRY300)
359-359: Do not catch blind exception: Exception
(BLE001)
363-363: Do not use bare except
(E722)
363-364: try-except-pass detected, consider logging the exception
(S110)
365-365: Use explicit conversion flag
Replace with conversion flag
(RUF010)
🔇 Additional comments (3)
mcp/tools/helm.py (3)
323-338: LGTM! Signature and decorator align with requirements.The function signature correctly implements all parameters specified in issue #25, and the
readOnlyHint: Trueannotation properly marks this as a read-only tool.
339-346: LGTM! Command construction is correct.The command building logic properly handles optional parameters and follows the established pattern in this file.
366-367: LGTM! Clean fallback for the no-values case.The implementation correctly handles rendering without custom values.
KaranJagtiani
left a comment
There was a problem hiding this comment.
Great! Now just squash your commits into one
…er manifests Remove comments feat (mcp): add the helm_template tool call to the MCP server to render manifests#
8c52446 to
7ff76d9
Compare
Done |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
mcp/tools/helm.py (1)
348-367: Exception handling issues persist from previous review.The exception handling has the same issues previously flagged for similar code in
helm_install_with_values:
- Line 359: Catching bare
Exceptionmasks unexpected errors (should catchOSErrorfor file I/O)- Line 363: Bare
except:silently swallows cleanup exceptions (should catchOSError)- No logging means silent failures hinder debugging
- Line 358: Return should be in else block (TRY300)
- Line 365: Use f-string conversion flag (
!s) instead ofstr()Apply this diff to fix the exception handling:
if values: try: with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: f.write(values) values_file = f.name cmd += f" -f {values_file}" result = await run_helm_command(cmd) os.unlink(values_file) - return result - except Exception as e: + except OSError as e: + # Handle file I/O errors specifically if "values_file" in locals(): try: os.unlink(values_file) - except: + except OSError: + # Log but don't fail if cleanup fails pass - return {"output": f"Error rendering Helm template: {str(e)}", "error": True} - else: - return await run_helm_command(cmd) + return {"output": f"Error rendering Helm template: {e!s}", "error": True} + else: + return result + return await run_helm_command(cmd)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
mcp/tools/helm.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.13.3)
mcp/tools/helm.py
358-358: Consider moving this statement to an else block
(TRY300)
359-359: Do not catch blind exception: Exception
(BLE001)
363-363: Do not use bare except
(E722)
363-364: try-except-pass detected, consider logging the exception
(S110)
365-365: Use explicit conversion flag
Replace with conversion flag
(RUF010)
🔇 Additional comments (2)
mcp/tools/helm.py (2)
323-339: LGTM! Function signature and metadata match requirements.The function signature correctly implements all required parameters from issue #25, and the tool is properly annotated as read-only with
{"readOnlyHint": True}.
340-346: Command building logic is correct.The command construction properly handles optional namespace and include_crds flags according to Helm CLI conventions.
Description
Please include a summary of the changes and which issue is fixed. Explain the motivation for the changes.
Implement the read-only Helm rendering capability by adding a new helm_template tool to the MCP server.
Related Issue(s)
Fixes #25
Type of Change
Testing
Please describe the tests you've added/performed to verify your changes.
Checklist
Screenshots (if applicable)
Additional Notes