summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-10 19:28:27 +0200
committerPaul Buetow <paul@buetow.org>2026-02-10 19:28:27 +0200
commit5551695f3b0d10c9a22cfacdb10c2cf7bd572421 (patch)
tree282611eacf1fd4c38d54d5cea87decdf2b1cbdb7 /cmd
parentec745129258ae800065e302a2a40b54488cbca08 (diff)
Add MCP server implementation with comprehensive test coverage
Implements a full Model Context Protocol (MCP) server for managing and serving prompts to LLM applications. The server provides CRUD operations for prompts with automatic backups and template rendering support. Key additions: - cmd/hexai-mcp-server: Main MCP server binary entrypoint - internal/hexaimcp: Server orchestrator with configuration and setup - internal/mcp: Core MCP protocol implementation (JSON-RPC 2.0) - internal/promptstore: Prompt storage with JSONL backend and automatic backups - Comprehensive test suites achieving 80%+ coverage for all MCP packages - Magefile targets for building and installing the MCP server - Complete documentation for setup, API, prompts, and backups Test coverage: - internal/hexaimcp: 84.3% - internal/mcp: 80.3% - internal/promptstore: 81.2% - Overall project: 81.5% Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hexai-mcp-server/main.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmd/hexai-mcp-server/main.go b/cmd/hexai-mcp-server/main.go
new file mode 100644
index 0000000..65335f7
--- /dev/null
+++ b/cmd/hexai-mcp-server/main.go
@@ -0,0 +1,46 @@
+// 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"
+)
+
+func main() {
+ 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)")
+ 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 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)
+}