Skip to content

Commit 0da8c44

Browse files
committed
fix(mcp-profile-gateway): support inline JSON in MCP_PROFILE_GATEWAY_CONFIG
LoadPipelineConfig treated the env var value as a file path in all cases, so e2e tests passing inline JSON triggered os.Stat on the JSON string, causing "no such file or directory" and leaving the filter factory unregistered. Detect values that start with '{' and parse them directly via NewStaticConfig, falling back to the file-based pipeline for paths.
1 parent c3878fc commit 0da8c44

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

examples/mcp-profile-gateway/gateway.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,22 @@ func decodeConfig(data []byte) (Config, error) {
114114
return cfg, nil
115115
}
116116

117-
// LoadPipelineConfig returns a PipelineConfig backed by the file path in
118-
// MCP_PROFILE_GATEWAY_CONFIG. Call RefreshOnce before reading Snapshot().
117+
// LoadPipelineConfig returns a PipelineConfig backed by MCP_PROFILE_GATEWAY_CONFIG.
118+
// If the value starts with '{' it is parsed as inline JSON; otherwise it is
119+
// treated as a file path and read via a cached file source.
119120
func LoadPipelineConfig() (*up.PipelineConfig[Config], error) {
120-
path := strings.TrimSpace(os.Getenv(ConfigEnv))
121-
if path == "" {
121+
raw := strings.TrimSpace(os.Getenv(ConfigEnv))
122+
if raw == "" {
122123
return nil, fmt.Errorf("%s is required", ConfigEnv)
123124
}
124-
pc := up.NewFileConfig[Config](path, decodeConfig, up.PollOptions{})
125+
if strings.HasPrefix(raw, "{") {
126+
cfg, err := decodeConfig([]byte(raw))
127+
if err != nil {
128+
return nil, err
129+
}
130+
return up.NewStaticConfig(cfg), nil
131+
}
132+
pc := up.NewFileConfig[Config](raw, decodeConfig, up.PollOptions{})
125133
if err := pc.RefreshOnce(context.Background()); err != nil {
126134
return nil, err
127135
}

0 commit comments

Comments
 (0)