@@ -108,14 +108,18 @@ Dynamic client registration (automatic OAuth client setup):
108108 thv proxy my-server --target-uri https://protected-api.com \
109109 --remote-auth --remote-auth-issuer https://auth.example.com` ,
110110 Args : cobra .ExactArgs (1 ),
111+ PreRunE : func (_ * cobra.Command , _ []string ) error {
112+ return validateProxyMaxRequestBodySize (proxyMaxRequestBodySize )
113+ },
111114 RunE : proxyCmdFunc ,
112115}
113116
114117var (
115- proxyHost string
116- proxyPort int
117- proxyTargetURI string
118- proxyAllowedOrigins []string
118+ proxyHost string
119+ proxyPort int
120+ proxyTargetURI string
121+ proxyAllowedOrigins []string
122+ proxyMaxRequestBodySize int64
119123
120124 resourceURL string // Explicit resource URL for OAuth discovery endpoint (RFC 9728)
121125
@@ -140,6 +144,8 @@ func init() {
140144 "Exact-match allowlist for the HTTP Origin header (repeatable). Recommended when binding publicly; " +
141145 "loopback binds derive a default allowlist automatically, non-loopback binds log a warning when " +
142146 "no value is supplied. Example: https://my-mcp.example.com" )
147+ proxyCmd .Flags ().Int64Var (& proxyMaxRequestBodySize , "max-request-body-size" , 0 ,
148+ "Maximum inbound request body size in bytes; zero uses the default (8 MiB)" )
143149 proxyCmd .Flags ().StringVar (
144150 & proxyTargetURI ,
145151 "target-uri" ,
@@ -238,7 +244,7 @@ func proxyCmdFunc(cmd *cobra.Command, args []string) error {
238244 // runner's addBodyLimitMiddleware. See pkg/bodylimit.
239245 middlewares = append (middlewares , types.NamedMiddleware {
240246 Name : bodylimit .MiddlewareType ,
241- Function : bodylimit .Middleware (bodylimit . DefaultMaxRequestBodySize ),
247+ Function : bodylimit .Middleware (proxyMaxRequestBodySize ),
242248 })
243249
244250 // Origin-header validation (DNS-rebinding protection per MCP 2025-11-25
@@ -323,6 +329,13 @@ func proxyCmdFunc(cmd *cobra.Command, args []string) error {
323329 return proxy .Stop (shutdownCtx )
324330}
325331
332+ func validateProxyMaxRequestBodySize (maxBytes int64 ) error {
333+ if maxBytes < 0 {
334+ return fmt .Errorf ("max-request-body-size must be non-negative, got %d" , maxBytes )
335+ }
336+ return nil
337+ }
338+
326339// getProxyOIDCConfig returns the OIDC token validator config from CLI flags, or nil if OIDC is not enabled.
327340func getProxyOIDCConfig (cmd * cobra.Command ) * auth.TokenValidatorConfig {
328341 if ! IsOIDCEnabled (cmd ) {
0 commit comments