diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 03:25:52 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 03:25:52 +0200 |
| commit | ad988c34181b7234a54d279874f29e126607fad3 (patch) | |
| tree | 0cbae073e0a6b2641477c23129945bcbb33f482c /cmd/hexai-mcp-server/main.go | |
| parent | 5cf8526fd81dadd181f30b1d4c862ba1f1b2a5b1 (diff) | |
Remove os.Setenv from MCP server production code
Replace environment variable communication between cmd and internal
packages with explicit MCPOverrides struct. CLI flag values are now
passed via typed struct fields through Run/RunWithFactory/RunBackfill.
Env var support preserved through appconfig's applyMCPEnv pipeline.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'cmd/hexai-mcp-server/main.go')
| -rw-r--r-- | cmd/hexai-mcp-server/main.go | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/cmd/hexai-mcp-server/main.go b/cmd/hexai-mcp-server/main.go index 32817f3..d2495e6 100644 --- a/cmd/hexai-mcp-server/main.go +++ b/cmd/hexai-mcp-server/main.go @@ -12,7 +12,17 @@ import ( "codeberg.org/snonux/hexai/internal/hexaimcp" ) +// buildOverrides constructs MCPOverrides from parsed CLI options. +func buildOverrides(opts mcpOptions) hexaimcp.MCPOverrides { + return hexaimcp.MCPOverrides{ + PromptsDir: opts.promptsDir, + SlashCommandSync: opts.slashCommandSync, + SlashCommandDir: opts.slashCommandDir, + } +} + // Seams for testing: override in tests to avoid launching real MCP server. +// Signatures match hexaimcp.Run and hexaimcp.RunBackfill respectively. var ( runMCP = hexaimcp.Run runBackfill = hexaimcp.RunBackfill @@ -86,29 +96,21 @@ func main() { } // run executes the MCP server logic with the given options and I/O streams. +// CLI flag values are passed via MCPOverrides instead of environment variables. func run(opts mcpOptions, stdin io.Reader, stdout, stderr io.Writer) error { - // Set environment variables for RunWithFactory based on flag values - if opts.promptsDir != "" { - os.Setenv("HEXAI_MCP_PROMPTS_DIR", opts.promptsDir) - } - if opts.slashCommandSync { - os.Setenv("HEXAI_MCP_SLASHCOMMAND_SYNC", "true") - } - if opts.slashCommandDir != "" { - os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", opts.slashCommandDir) - } - if opts.showVersion { fmt.Fprintln(stdout, internal.Version) return nil } + overrides := buildOverrides(opts) + // Handle backfill operation if opts.syncAll { - return runBackfill(opts.logPath, opts.configPath) + return runBackfill(opts.logPath, opts.configPath, overrides) } - return runMCP(opts.logPath, opts.configPath, stdin, stdout, stderr) + return runMCP(opts.logPath, opts.configPath, overrides, stdin, stdout, stderr) } // defaultLogPath returns the default MCP log file path in the state directory. |
