-
Notifications
You must be signed in to change notification settings - Fork 145
Fix args handling for protocol builds #2630
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
Abandons the unimplemented MCPArgs build-time expansion in favor of simpler runtime args handling. This also eliminates potential duplication of args. Signed-off-by: Dan Barr <6922515+danbarr@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2630 +/- ##
=======================================
Coverage 55.47% 55.47%
=======================================
Files 312 312
Lines 29715 29714 -1
=======================================
Hits 16485 16485
+ Misses 11790 11789 -1
Partials 1440 1440 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Claude finished @danbarr's task —— View job Code Review Complete ✅I've reviewed the changes in this PR and confirmed they correctly fix issue #2623 regarding args handling for protocol builds. SummaryThe PR successfully removes the unimplemented build-time args expansion ( Changes Analysis1. Template Changes (go.tmpl, npx.tmpl, uvx.tmpl)
The npx.tmpl change also correctly removes the complex 2. Code Changes
Verification of FixThe changes correctly address the root cause described in the PR:
Runtime args flow (verified by code review):
For the three protocol builds:
Potential Issues Checked✅ No args duplication: The old approach could have led to args being specified both at build time and runtime. This is now impossible. ✅ Shell script handling: The npx template correctly uses ✅ Version handling: npx template correctly keeps ✅ Test coverage: All tests updated to reflect new behavior, with proper escaping of shell syntax. Minor Observations
RecommendationLGTM ✅ This PR correctly fixes the args handling issue. The changes are:
The fix eliminates potential confusion and makes the system work as users would expect: args provided at |
- Add BuildArgs field to TemplateData struct for baking required CLI arguments into container ENTRYPOINT at build time - Update npx.tmpl to insert BuildArgs before "$@" - Update uvx.tmpl to insert BuildArgs before "$@" - Update go.tmpl to insert BuildArgs in JSON array format BuildArgs are for required subcommands (e.g., 'start') while runtime args passed via '-- <args>' append after. This prevents duplication issues that led to MCPArgs removal in PR #2630. Related to: stacklok/dockyard#189
Previous approach created complex shell scripts with nested quoting to handle
version stripping and buildArgs. This was error-prone and hard to maintain.
New approach:
- Add MCPPackageClean field to TemplateData, auto-populated by stripVersionSuffix()
- NPX: Use simple JSON array ENTRYPOINT with pre-stripped package name
ENTRYPOINT ["npx", "{{.MCPPackageClean}}"{{range .BuildArgs}}, "{{.}}"{{end}}]
- UVX: Simplified to use MCPPackageClean instead of shell parameter expansion
ENTRYPOINT ["sh", "-c", "exec '{{.MCPPackageClean}}'{{range .BuildArgs}} '{{.}}'{{end}} \"$@\"", "--"]
- Add comprehensive unit tests for version stripping logic
Benefits:
- NPX template reduced from 9 lines of shell script to 2 lines of JSON array
- Version stripping logic centralized, testable, and maintainable
- Properly handles scoped packages (@org/package@version -> @org/package)
- BuildArgs safely passed without shell injection risk
- Prevents NPX from re-pulling packages when @latest is specified
Fixes NPX @latest regression from PR #2630.
Previous approach created complex shell scripts with nested quoting to handle
version stripping and buildArgs. This was error-prone and hard to maintain.
New approach:
- Add MCPPackageClean field to TemplateData, auto-populated by stripVersionSuffix()
- NPX: Use simple JSON array ENTRYPOINT with pre-stripped package name
ENTRYPOINT ["npx", "{{.MCPPackageClean}}"{{range .BuildArgs}}, "{{.}}"{{end}}]
- UVX: Simplified to use MCPPackageClean instead of shell parameter expansion
ENTRYPOINT ["sh", "-c", "exec '{{.MCPPackageClean}}'{{range .BuildArgs}} '{{.}}'{{end}} \"$@\"", "--"]
- Add comprehensive unit tests for version stripping logic
Benefits:
- NPX template reduced from 9 lines of shell script to 2 lines of JSON array
- Version stripping logic centralized, testable, and maintainable
- Properly handles scoped packages (@org/package@version -> @org/package)
- BuildArgs safely passed without shell injection risk
- Prevents NPX from re-pulling packages when @latest is specified
Fixes NPX @latest regression from PR #2630.
Fixes #2623
Abandons the unimplemented MCPArgs build-time expansion in favor of simpler runtime args handling. This also eliminates potential
duplication of args.
Root cause: command args were working for Go and uvx protocol builds because their Dockerfile templates implemented direct ENTRYPOINT execution, while npx has an interim shell script that was not handling runtime args. An alternate approach to the fix (#2627) led to duplication of args.
Changes:
All Dockerfile templates now accept arguments at runtime instead of baking them in at build time, making the containers more flexible.
Testing:
I tested with Go, uvx, and npx and confirmed the resulting Docker command was as expected for all three:
Output:
Signed-off-by: Dan Barr 6922515+danbarr@users.noreply.github.com