googleapis/mcp-toolbox · error

failed to unmarshal environmentConfig: %w

Error message

failed to unmarshal environmentConfig: %w

What it means

Same mechanism as the runtimeConfig error but for the environmentConfig section of the createbatch tool config: the YAML-decoded value is JSON-marchaled and parsed with protojson into dataprocpb.EnvironmentConfig. A mismatch with the proto schema (unknown fields, bad types/enums) yields this wrapped error at config load time.

Source

Thrown at internal/tools/serverlessspark/createbatch/config.go:91

			Description:  ymlCfg.Description,
			AuthRequired: ymlCfg.AuthRequired,
		},
		Type:   ymlCfg.Type,
		Source: ymlCfg.Source,
	}

	if ymlCfg.RuntimeConfig != nil {
		rc := &dataprocpb.RuntimeConfig{}
		if err := unmarshalProto(ymlCfg.RuntimeConfig, rc); err != nil {
			return Config{}, fmt.Errorf("failed to unmarshal runtimeConfig: %w", err)
		}
		cfg.RuntimeConfig = rc
	}

	if ymlCfg.EnvironmentConfig != nil {
		ec := &dataprocpb.EnvironmentConfig{}
		if err := unmarshalProto(ymlCfg.EnvironmentConfig, ec); err != nil {
			return Config{}, fmt.Errorf("failed to unmarshal environmentConfig: %w", err)
		}
		cfg.EnvironmentConfig = ec
	}

	return cfg, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped protojson error after 'failed to unmarshal environmentConfig:' to locate the bad field
  2. Validate keys against the dataprocpb.EnvironmentConfig schema (executionConfig, peripheralsConfig, networkConfig, etc.)
  3. Use exact lowerCamelCase proto JSON field names and correct nested structure
  4. Move runtime-related fields (properties, serviceAccount) into runtimeConfig where they belong

Example fix

# before
environmentConfig:
  execution_config:
    serviceAccount: sa@proj.iam.gserviceaccount.com
# after
environmentConfig:
  executionConfig:
    serviceAccount: sa@proj.iam.gserviceaccount.com
Defensive patterns

Strategy: validation

Validate before calling

var ec dataprocpb.EnvironmentConfig
b, _ := json.Marshal(rawEnvConfig)
if err := protojson.Unmarshal(b, &ec); err != nil {
    return fmt.Errorf("bad environmentConfig: %w", err)
}

Type guard

func validEnvironmentConfig(v any) bool {
    var ec dataprocpb.EnvironmentConfig
    b, err := json.Marshal(v)
    return err == nil && protojson.Unmarshal(b, &ec) == nil
}

Try / catch

cfg, err := createbatch.NewConfig(ctx, ymlCfg)
if err != nil && strings.Contains(err.Error(), "failed to unmarshal environmentConfig") {
    log.Fatalf("environmentConfig schema mismatch: %v", err)
}

Prevention

When it happens

Trigger: A createbatch tool YAML has an environmentConfig block containing keys not in dataprocpb.EnvironmentConfig (e.g. misspelled ExecutionConfig/Templates/PeripheralsConfig) or values of the wrong type, processed by NewConfig at startup.

Common situations: Putting runtime-only fields inside environmentConfig, typos like 'executionconfig', wrong nesting of PeripheralsConfig sub-fields, or using snake_case instead of proto JSON lowerCamelCase names.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/068676aa12680a3c. Report an issue: GitHub.