Skip to content

Commit 832c968

Browse files
authored
Fix args handling for protocol builds (#2630)
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 <[email protected]>
1 parent ffef594 commit 832c968

File tree

7 files changed

+10
-26
lines changed

7 files changed

+10
-26
lines changed

pkg/container/templates/go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ COPY --from=builder --chown=appuser:appgroup /build/ /app/
9999
USER appuser
100100

101101
# Run the pre-built MCP server binary
102-
ENTRYPOINT ["/app/mcp-server"{{range .MCPArgs}}, "{{.}}"{{end}}]
102+
ENTRYPOINT ["/app/mcp-server"]

pkg/container/templates/npx.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ USER appuser
9898
# `MCPPackage` may include a version suffix (e.g., `[email protected]`), which we cannot use here.
9999
# Create a small wrapper script to handle this.
100100
RUN echo "#!/bin/sh" >> entrypoint.sh && \
101-
echo "exec npx $(echo {{.MCPPackage}} | sed 's/@[^@/]*$//'){{range .MCPArgs}}, "{{.}}"{{end}}" >> entrypoint.sh && \
101+
echo "exec npx {{.MCPPackage}} \"\$@\"" >> entrypoint.sh && \
102102
chmod +x entrypoint.sh
103103

104104
# Run the preinstalled MCP package directly using npx.

pkg/container/templates/templates.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ var templateFS embed.FS
1616
type TemplateData struct {
1717
// MCPPackage is the name of the MCP package to run.
1818
MCPPackage string
19-
// MCPArgs are the arguments to pass to the MCP package.
20-
MCPArgs []string
2119
// CACertContent is the content of the custom CA certificate to include in the image.
2220
CACertContent string
2321
// IsLocalPath indicates if the MCPPackage is a local path that should be copied into the container.

pkg/container/templates/templates_test.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
2222
transportType: TransportTypeUVX,
2323
data: TemplateData{
2424
MCPPackage: "example-package",
25-
MCPArgs: []string{"--arg1", "--arg2", "value"},
2625
},
2726
wantContains: []string{
2827
"FROM python:",
@@ -31,7 +30,7 @@ func TestGetDockerfileTemplate(t *testing.T) {
3130
"package_spec=$(echo \"$package\" | sed 's/@/==/')",
3231
"uv tool install \"$package_spec\"",
3332
"COPY --from=builder --chown=appuser:appgroup /opt/uv-tools /opt/uv-tools",
34-
"ENTRYPOINT [\"sh\", \"-c\", \"package='example-package'; exec \\\"${package%%@*}\\\" \\\"--arg1\\\" \\\"--arg2\\\" \\\"value\\\" \\\"$@\\\"\", \"--\"]",
33+
"ENTRYPOINT [\"sh\", \"-c\", \"package='example-package'; exec \\\"${package%%@*}\\\"\", \"--\"]",
3534
},
3635
wantMatches: []string{
3736
`FROM python:\d+\.\d+-slim AS builder`, // Match builder stage
@@ -48,7 +47,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
4847
transportType: TransportTypeUVX,
4948
data: TemplateData{
5049
MCPPackage: "example-package",
51-
MCPArgs: []string{"--arg1", "--arg2", "value"},
5250
CACertContent: "-----BEGIN CERTIFICATE-----\nMIICertificateContent\n-----END CERTIFICATE-----",
5351
},
5452
wantContains: []string{
@@ -58,7 +56,7 @@ func TestGetDockerfileTemplate(t *testing.T) {
5856
"package_spec=$(echo \"$package\" | sed 's/@/==/')",
5957
"uv tool install \"$package_spec\"",
6058
"COPY --from=builder --chown=appuser:appgroup /opt/uv-tools /opt/uv-tools",
61-
"ENTRYPOINT [\"sh\", \"-c\", \"package='example-package'; exec \\\"${package%%@*}\\\" \\\"--arg1\\\" \\\"--arg2\\\" \\\"value\\\" \\\"$@\\\"\", \"--\"]",
59+
"ENTRYPOINT [\"sh\", \"-c\", \"package='example-package'; exec \\\"${package%%@*}\\\"\", \"--\"]",
6260
"Add custom CA certificate BEFORE any network operations",
6361
"COPY ca-cert.crt /tmp/custom-ca.crt",
6462
"cat /tmp/custom-ca.crt >> /etc/ssl/certs/ca-certificates.crt",
@@ -76,13 +74,12 @@ func TestGetDockerfileTemplate(t *testing.T) {
7674
transportType: TransportTypeNPX,
7775
data: TemplateData{
7876
MCPPackage: "example-package",
79-
MCPArgs: []string{"--arg1", "--arg2", "value"},
8077
},
8178
wantContains: []string{
8279
"FROM node:",
8380
"npm install --save example-package",
8481
"COPY --from=builder --chown=appuser:appgroup /build/node_modules /app/node_modules",
85-
"echo \"exec npx $(echo example-package | sed 's/@[^@/]*$//'), \"--arg1\", \"--arg2\", \"value\"\" >> entrypoint.sh",
82+
"echo \"exec npx example-package \\\"\\$@\\\"\" >> entrypoint.sh",
8683
"ENTRYPOINT [\"./entrypoint.sh\"]",
8784
},
8885
wantMatches: []string{
@@ -100,13 +97,12 @@ func TestGetDockerfileTemplate(t *testing.T) {
10097
transportType: TransportTypeNPX,
10198
data: TemplateData{
10299
MCPPackage: "example-package",
103-
MCPArgs: []string{"--arg1", "--arg2", "value"},
104100
CACertContent: "-----BEGIN CERTIFICATE-----\nMIICertificateContent\n-----END CERTIFICATE-----",
105101
},
106102
wantContains: []string{
107103
"FROM node:",
108104
"npm install --save example-package",
109-
"echo \"exec npx $(echo example-package | sed 's/@[^@/]*$//'), \"--arg1\", \"--arg2\", \"value\"\" >> entrypoint.sh",
105+
"echo \"exec npx example-package \\\"\\$@\\\"\" >> entrypoint.sh",
110106
"ENTRYPOINT [\"./entrypoint.sh\"]",
111107
"Add custom CA certificate BEFORE any network operations",
112108
"COPY ca-cert.crt /tmp/custom-ca.crt",
@@ -125,7 +121,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
125121
transportType: TransportTypeGO,
126122
data: TemplateData{
127123
MCPPackage: "example-package",
128-
MCPArgs: []string{"--arg1", "--arg2", "value"},
129124
},
130125
wantContains: []string{
131126
"FROM golang:",
@@ -134,7 +129,7 @@ func TestGetDockerfileTemplate(t *testing.T) {
134129
"go install \"$package\"",
135130
"FROM alpine:",
136131
"COPY --from=builder --chown=appuser:appgroup /app/mcp-server /app/mcp-server",
137-
"ENTRYPOINT [\"/app/mcp-server\", \"--arg1\", \"--arg2\", \"value\"]",
132+
"ENTRYPOINT [\"/app/mcp-server\"]",
138133
},
139134
wantMatches: []string{
140135
`FROM golang:\d+\.\d+-alpine AS builder`, // Match builder stage
@@ -151,7 +146,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
151146
transportType: TransportTypeGO,
152147
data: TemplateData{
153148
MCPPackage: "example-package",
154-
MCPArgs: []string{"--arg1", "--arg2", "value"},
155149
CACertContent: "-----BEGIN CERTIFICATE-----\nMIICertificateContent\n-----END CERTIFICATE-----",
156150
},
157151
wantContains: []string{
@@ -160,7 +154,7 @@ func TestGetDockerfileTemplate(t *testing.T) {
160154
"package=\"${package}@latest\"",
161155
"go install \"$package\"",
162156
"FROM alpine:",
163-
"ENTRYPOINT [\"/app/mcp-server\", \"--arg1\", \"--arg2\", \"value\"]",
157+
"ENTRYPOINT [\"/app/mcp-server\"]",
164158
"Add custom CA certificate BEFORE any network operations",
165159
"COPY ca-cert.crt /tmp/custom-ca.crt",
166160
"cat /tmp/custom-ca.crt >> /etc/ssl/certs/ca-certificates.crt",
@@ -178,7 +172,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
178172
transportType: TransportTypeGO,
179173
data: TemplateData{
180174
MCPPackage: "./cmd/server",
181-
MCPArgs: []string{"--arg1", "value"},
182175
IsLocalPath: true,
183176
},
184177
wantContains: []string{
@@ -188,7 +181,7 @@ func TestGetDockerfileTemplate(t *testing.T) {
188181
"FROM alpine:",
189182
"COPY --from=builder --chown=appuser:appgroup /app/mcp-server /app/mcp-server",
190183
"COPY --from=builder --chown=appuser:appgroup /build/ /app/",
191-
"ENTRYPOINT [\"/app/mcp-server\", \"--arg1\", \"value\"]",
184+
"ENTRYPOINT [\"/app/mcp-server\"]",
192185
},
193186
wantMatches: []string{
194187
`FROM golang:\d+\.\d+-alpine AS builder`, // Match builder stage
@@ -204,7 +197,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
204197
transportType: TransportTypeGO,
205198
data: TemplateData{
206199
MCPPackage: ".",
207-
MCPArgs: []string{},
208200
IsLocalPath: true,
209201
},
210202
wantContains: []string{
@@ -229,7 +221,6 @@ func TestGetDockerfileTemplate(t *testing.T) {
229221
transportType: "unsupported",
230222
data: TemplateData{
231223
MCPPackage: "example-package",
232-
MCPArgs: []string{"--arg1", "--arg2", "value"},
233224
},
234225
wantContains: nil,
235226
wantNotContains: nil,

pkg/container/templates/uvx.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ USER appuser
118118
# We use sh -c to allow the package name to be resolved from PATH
119119
# Strip version specifier (if present) from package name for execution
120120
# Handles format like package@version
121-
ENTRYPOINT ["sh", "-c", "package='{{.MCPPackage}}'; exec \"${package%%@*}\" {{range .MCPArgs}}\"{{.}}\" {{end}}\"$@\"", "--"]
121+
ENTRYPOINT ["sh", "-c", "package='{{.MCPPackage}}'; exec \"${package%%@*}\"", "--"]

pkg/runner/protocol.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func createTemplateData(transportType templates.TransportType, packageName, caCe
9191

9292
templateData := templates.TemplateData{
9393
MCPPackage: packageName,
94-
MCPArgs: []string{}, // No additional arguments for now
9594
IsLocalPath: isLocalPath,
9695
}
9796

pkg/runner/protocol_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ func TestTemplateDataWithLocalPath(t *testing.T) {
188188
packageName: "github.com/example/package",
189189
expected: templates.TemplateData{
190190
MCPPackage: "github.com/example/package",
191-
MCPArgs: []string{},
192191
IsLocalPath: false,
193192
},
194193
},
@@ -197,7 +196,6 @@ func TestTemplateDataWithLocalPath(t *testing.T) {
197196
packageName: "./cmd/server",
198197
expected: templates.TemplateData{
199198
MCPPackage: "./cmd/server",
200-
MCPArgs: []string{},
201199
IsLocalPath: true,
202200
},
203201
},
@@ -206,7 +204,6 @@ func TestTemplateDataWithLocalPath(t *testing.T) {
206204
packageName: ".",
207205
expected: templates.TemplateData{
208206
MCPPackage: ".",
209-
MCPArgs: []string{},
210207
IsLocalPath: true,
211208
},
212209
},
@@ -220,7 +217,6 @@ func TestTemplateDataWithLocalPath(t *testing.T) {
220217

221218
templateData := templates.TemplateData{
222219
MCPPackage: tt.packageName,
223-
MCPArgs: []string{},
224220
IsLocalPath: isLocalPath,
225221
}
226222

0 commit comments

Comments
 (0)