diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 03:10:55 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 03:10:55 +0200 |
| commit | 1fc1611fa99993cab5dc8bf0844183285296e3b2 (patch) | |
| tree | c5c9b8b5abac5b5d4c0d56ed90b0580184cc4383 /cmd/hexai-mcp-server/main.go | |
| parent | 12090f25a3677291863dbb80277bdad3eaec0324 (diff) | |
Release v0.24.0v0.24.0
Bring unit test coverage from ~75% to 85.1% project-wide. All internal
packages now exceed 80% coverage. Refactored cmd entrypoints to extract
testable run() functions with injectable seams.
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 | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/cmd/hexai-mcp-server/main.go b/cmd/hexai-mcp-server/main.go index 557172f..1f52616 100644 --- a/cmd/hexai-mcp-server/main.go +++ b/cmd/hexai-mcp-server/main.go @@ -4,7 +4,7 @@ package main import ( "flag" "fmt" - "log" + "io" "os" "codeberg.org/snonux/hexai/internal" @@ -12,6 +12,12 @@ import ( "codeberg.org/snonux/hexai/internal/hexaimcp" ) +// Seams for testing: override in tests to avoid launching real MCP server. +var ( + runMCP = hexaimcp.Run + runBackfill = hexaimcp.RunBackfill +) + // printDeprecationWarning outputs a deprecation notice to stderr explaining // that hexai-mcp-server is experimental and not actively maintained. func printDeprecationWarning() { @@ -36,6 +42,17 @@ Use at your own risk. fmt.Fprintln(os.Stderr, warning) } +// mcpOptions holds the parsed command-line flags for the MCP server. +type mcpOptions struct { + logPath string + configPath string + promptsDir string + slashCommandSync bool + slashCommandDir string + syncAll bool + showVersion bool +} + func main() { printDeprecationWarning() @@ -49,33 +66,45 @@ func main() { showVersion := flag.Bool("version", false, "print version and exit") flag.Parse() - if *showVersion { - fmt.Println(internal.Version) - return + opts := mcpOptions{ + logPath: *logPath, + configPath: *configPath, + promptsDir: *promptsDir, + slashCommandSync: *slashCommandSync, + slashCommandDir: *slashCommandDir, + syncAll: *syncAll, + showVersion: *showVersion, + } + if err := run(opts, os.Stdin, os.Stdout, os.Stderr); err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) } +} - // If prompts-dir is specified, set environment variable for RunWithFactory - if *promptsDir != "" { - os.Setenv("HEXAI_MCP_PROMPTS_DIR", *promptsDir) +// run executes the MCP server logic with the given options and I/O streams. +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 *slashCommandSync { + if opts.slashCommandSync { os.Setenv("HEXAI_MCP_SLASHCOMMAND_SYNC", "true") } - if *slashCommandDir != "" { - os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", *slashCommandDir) + if opts.slashCommandDir != "" { + os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", opts.slashCommandDir) } - // Handle backfill operation - if *syncAll { - if err := hexaimcp.RunBackfill(*logPath, *configPath); err != nil { - log.Fatalf("backfill error: %v", err) - } - return + if opts.showVersion { + fmt.Fprintln(stdout, internal.Version) + return nil } - if err := hexaimcp.Run(*logPath, *configPath, os.Stdin, os.Stdout, os.Stderr); err != nil { - log.Fatalf("server error: %v", err) + // Handle backfill operation + if opts.syncAll { + return runBackfill(opts.logPath, opts.configPath) } + + return runMCP(opts.logPath, opts.configPath, stdin, stdout, stderr) } // defaultLogPath returns the default MCP log file path in the state directory. |
