-
Notifications
You must be signed in to change notification settings - Fork 145
Fix "CLI args are not handled for protocol builds" #2627
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
## Summary Fixes #2623: CLI arguments passed via `-- <args>` are now properly forwarded to MCP server containers built from protocol schemes (npx://, uvx://, go://) Verified that `./bin/thv run npx://@launchdarkly/mcp-server -- start` successfully starts the server, where it did not before. ## Changes ### Core Protocol Handling - **[pkg/runner/protocol.go](pkg/runner/protocol.go)**: Added `cmdArgs` parameter throughout the protocol build pipeline - `HandleProtocolScheme()` and `BuildFromProtocolSchemeWithName()` now accept and forward command arguments - `createTemplateData()` populates `MCPArgs` field with user-provided arguments instead of empty slice ### Retriever Layer - **[pkg/runner/retriever/retriever.go](pkg/runner/retriever/retriever.go)**: Threaded `cmdArgs` through the retrieval pipeline - Updated `Retriever` function signature to include command arguments parameter - Modified `GetMCPServer()` and `handleProtocolScheme()` to pass arguments to protocol handler ### CLI Integration - **[cmd/thv/app/run_flags.go](cmd/thv/app/run_flags.go)**: Forward parsed command arguments to image retrieval - `BuildRunnerConfig()` and `handleImageRetrieval()` now accept and forward command arguments - **[cmd/thv/app/build.go](cmd/thv/app/build.go)**: Pass empty args array for build-only operations ### API Changes - **[pkg/api/v1/workload_service.go](pkg/api/v1/workload_service.go)**: Pass `CmdArguments` to retriever for protocol builds - **[pkg/api/v1/workloads_test.go](pkg/api/v1/workloads_test.go)**: Updated mock retriever signature ### Template Updates - **[pkg/container/templates/npx.tmpl](pkg/container/templates/npx.tmpl)**: Fixed entrypoint generation to properly quote and space-separate command arguments - Updated comment clarifying runtime CMD argument pass-through behavior ### Testing - **[pkg/runner/protocol_test.go](pkg/runner/protocol_test.go)**: Added comprehensive test coverage - `TestCreateTemplateDataWithCmdArgs`: Validates command arguments are properly passed to template data across all transport types - `TestParseProtocolScheme`: Validates protocol parsing for various schemes and package formats - **[cmd/thv/app/run_flags_test.go](cmd/thv/app/run_flags_test.go)**: Added `TestParseCommandArguments` to validate CLI argument parsing - **[pkg/container/templates/templates_test.go](pkg/container/templates/templates_test.go)**: - Added test case for NPX transport with no arguments (registry image case) - Updated existing NPX test expectations to match corrected template output - **[pkg/runner/retriever/retriever_test.go](pkg/runner/retriever/retriever_test.go)**: Updated tests to pass empty `cmdArgs` parameter - **[pkg/mcp/server/run_server.go](pkg/mcp/server/run_server.go)**: Updated vMCP `RunServer` to pass empty args array ## Impact This fix enables users to: - Run LaunchDarkly MCP server: `thv run npx://@launchdarkly/mcp-server -- start` - Pass configuration flags: `thv run npx://@upstash/context7-mcp@latest -- --transport stdio` - Use any protocol-based MCP server that requires command-line arguments ## Test Plan - [x] All existing tests pass - [x] New test coverage for command argument handling across all transport types - [x] Template tests validate proper argument quoting and spacing - [x] CLI argument parsing tests cover various separator and format scenarios
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2627 +/- ##
==========================================
+ Coverage 55.47% 55.52% +0.04%
==========================================
Files 312 312
Lines 29715 29716 +1
==========================================
+ Hits 16485 16499 +14
+ Misses 11790 11776 -14
- Partials 1440 1441 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Claude finished @tgrunnagle's task —— View job Code Review SummaryI've completed a thorough review of the changes to confirm they fix issue #2623 (CLI arguments not being forwarded to protocol-built containers). ✅ Overall AssessmentThe implementation correctly fixes the issue and follows good practices. The changes properly thread 🎯 Key Changes Reviewed1. Core Protocol Handling (
|
danbarr
left a 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.
I did some testing, and found an issue...in the UVX template, "$@" is already included after the MCPArgs expansion. But this leads to a problem now that MCPArgs is actually fixed...the args get duplicated.
These templates take three different approaches:
- npx builds an entrypoint.sh script that is set as the entrypoint, but doesn't handle $@.
- Go constructs an exec-style ENTRYPOINT and the args are appended - so this already worked because additional args were added by Docker as expected
- UVX also does similar (though less directly because of the
"sh -c"approach
BUT there's a side effect of fixing the build-time MCPArgs expansion in the templates. For Go and UVX, now the args are duplicated. See this example:
./bin/thv run go://github.com/aantti/mcp-netbird/cmd/mcp-netbird@latest -- --some-arg true
docker ps --no-trunc | grep netbirdThe full command is now:
"/app/mcp-server --some-arg true --some-arg true"
I think we can solve this more simply by removing all the Arguments handling at build-time (i.e., most of this PR 🙃) and just fixing up the templates. I'll open an alternate PR.
|
|
||
| # `MCPPackage` may include a version suffix (e.g., `[email protected]`), which we cannot use here. | ||
| # Create a small wrapper script to handle this. | ||
| # If no MCPArgs are baked in, we add "$@" to allow runtime CMD arguments to be passed through |
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.
This comment doesn't appear to be true?
Summary
Fixes #2623: CLI arguments passed via
-- <args>are now properly forwarded to MCP server containers built from protocol schemes (npx://, uvx://, go://)Verified that
./bin/thv run npx://@launchdarkly/mcp-server -- startsuccessfully starts the server, where it did not before.Changes
Core Protocol Handling
cmdArgsparameter throughout the protocol build pipelineHandleProtocolScheme()andBuildFromProtocolSchemeWithName()now accept and forward command argumentscreateTemplateData()populatesMCPArgsfield with user-provided arguments instead of empty sliceRetriever Layer
cmdArgsthrough the retrieval pipelineRetrieverfunction signature to include command arguments parameterGetMCPServer()andhandleProtocolScheme()to pass arguments to protocol handlerCLI Integration
BuildRunnerConfig()andhandleImageRetrieval()now accept and forward command argumentsAPI Changes
CmdArgumentsto retriever for protocol buildsTemplate Updates
Testing
TestCreateTemplateDataWithCmdArgs: Validates command arguments are properly passed to template data across all transport typesTestParseProtocolScheme: Validates protocol parsing for various schemes and package formatsTestParseCommandArgumentsto validate CLI argument parsingcmdArgsparameterRunServerto pass empty args arrayImpact
This fix enables users to:
thv run npx://@launchdarkly/mcp-server -- startthv run npx://@upstash/context7-mcp@latest -- --transport stdioTest Plan