summaryrefslogtreecommitdiff
path: root/cmd/hexai-mcp-server/main.go
blob: 557172f00d79d0faa990cc16e6891b50b2699f1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Summary: Hexai MCP server entrypoint; parses flags and delegates to internal/hexaimcp.
package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"codeberg.org/snonux/hexai/internal"
	"codeberg.org/snonux/hexai/internal/appconfig"
	"codeberg.org/snonux/hexai/internal/hexaimcp"
)

// printDeprecationWarning outputs a deprecation notice to stderr explaining
// that hexai-mcp-server is experimental and not actively maintained.
func printDeprecationWarning() {
	warning := `
⚠️  DEPRECATION NOTICE ⚠️

hexai-mcp-server is currently EXPERIMENTAL and NOT ACTIVELY MAINTAINED.

The author does not have a real use case for this MCP server at this time.
Prompts are now managed through slash commands and meta-commands in the
main hexai agent system, making this MCP server's prompt management
functionality redundant.

This code is kept in the repository for potential future enhancements
(possibly adding more useful functionality than prompt management), but
no guarantees are made about its stability or continued support.

Use at your own risk.

────────────────────────────────────────────────────────────────────────
`
	fmt.Fprintln(os.Stderr, warning)
}

func main() {
	printDeprecationWarning()

	defaultLog := defaultLogPath()
	logPath := flag.String("log", defaultLog, "path to log file (optional)")
	configPath := flag.String("config", "", "path to config file (optional)")
	promptsDir := flag.String("prompts-dir", "", "path to prompts directory (optional)")
	slashCommandSync := flag.Bool("slashcommand-sync", false, "enable slash command sync")
	slashCommandDir := flag.String("slashcommand-dir", "", "directory for slash command files")
	syncAll := flag.Bool("sync-all", false, "backfill all existing prompts and exit")
	showVersion := flag.Bool("version", false, "print version and exit")
	flag.Parse()

	if *showVersion {
		fmt.Println(internal.Version)
		return
	}

	// If prompts-dir is specified, set environment variable for RunWithFactory
	if *promptsDir != "" {
		os.Setenv("HEXAI_MCP_PROMPTS_DIR", *promptsDir)
	}
	if *slashCommandSync {
		os.Setenv("HEXAI_MCP_SLASHCOMMAND_SYNC", "true")
	}
	if *slashCommandDir != "" {
		os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", *slashCommandDir)
	}

	// Handle backfill operation
	if *syncAll {
		if err := hexaimcp.RunBackfill(*logPath, *configPath); err != nil {
			log.Fatalf("backfill error: %v", err)
		}
		return
	}

	if err := hexaimcp.Run(*logPath, *configPath, os.Stdin, os.Stdout, os.Stderr); err != nil {
		log.Fatalf("server error: %v", err)
	}
}

// defaultLogPath returns the default MCP log file path in the state directory.
// Panics if state directory cannot be created.
func defaultLogPath() string {
	stateDir, err := appconfig.StateDir()
	if err != nil {
		panic(fmt.Sprintf("cannot create state directory: %v", err))
	}
	return fmt.Sprintf("%s/hexai-mcp-server.log", stateDir)
}