Tencent/WeKnora · error

argument %d exceeds maximum length (1024 characters)

Error message

argument %d exceeds maximum length (1024 characters)

What it means

ValidateStdioArgs limits each argument for MCP stdio transport to 1024 characters. This prevents oversized arguments from being used for buffer abuse, command-line injection payloads, or accidental resource exhaustion. The index of the offending argument (0-based) is included in the message.

Source

Thrown at internal/utils/security.go:568

	// Additional check: command should not contain path traversal
	if strings.Contains(command, "..") {
		return fmt.Errorf("command path contains invalid characters")
	}

	return nil
}

// ValidateStdioArgs validates the arguments for MCP stdio transport
// Returns an error if any argument contains dangerous patterns
func ValidateStdioArgs(args []string) error {
	if len(args) == 0 {
		return nil
	}

	for i, arg := range args {
		// Check length
		if len(arg) > 1024 {
			return fmt.Errorf("argument %d exceeds maximum length (1024 characters)", i)
		}

		// Check against dangerous patterns
		for _, pattern := range DangerousArgPatterns {
			if pattern.MatchString(arg) {
				return fmt.Errorf("argument %d contains potentially dangerous pattern: %s", i, SanitizeForLog(arg))
			}
		}

		// Check for null bytes
		if strings.Contains(arg, "\x00") {
			return fmt.Errorf("argument %d contains null bytes", i)
		}
	}

	return nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Shorten the argument: move long payloads into a file or env var and pass the path/var name instead
  2. For inline code, write it to a temp script file and pass the file path as the argument
  3. Split oversized arguments into multiple smaller arguments if the target program supports it
  4. Use environment variables (validated separately, 4096-char limit) for long values

Example fix

// before
"args": ["-e", "<1500-char inline script>"]
// after
"args": ["/tmp/mcp-script.js"] // script content moved to file
Defensive patterns

Strategy: validation

Validate before calling

for i, a := range cfg.Args {
    if len(a) > 1024 {
        return fmt.Errorf("args[%d] too long (%d > 1024)", i, len(a))
    }
}

Try / catch

if err := ValidateStdioConfig(cfg); err != nil {
    var tooLongErr string = "exceeds maximum length"
    if strings.Contains(err.Error(), tooLongErr) {
        return fmt.Errorf("shorten stdio args or move payload to a file: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: ValidateStdioConfig called with an args array where at least one element is longer than 1024 bytes (len(arg) in Go counts bytes, so multibyte UTF-8 hits the limit sooner).

Common situations: Passing long inline scripts (node -e, python -c) as arguments; embedding large URLs, tokens, or base64 blobs in args; configs generated programmatically that concatenate many values into one arg.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/cd0bbb2f0827c440. Report an issue: GitHub.