main
1package main
2
3import (
4 "context"
5 "flag"
6 "fmt"
7 "log"
8 "os"
9 "path/filepath"
10
11 "github.com/xlgmokha/mcp/pkg/memory"
12)
13
14func printHelp() {
15 fmt.Printf(`Memory MCP Server
16
17DESCRIPTION:
18 A Model Context Protocol server that provides persistent knowledge graph management.
19 Stores entities, relations, and observations for AI agents to maintain context across sessions.
20
21USAGE:
22 mcp-memory [options]
23
24OPTIONS:
25 --memory-file <path> Path to the memory JSON file (default: ~/.mcp_memory.json)
26 --help Show this help message
27
28ENVIRONMENT VARIABLES:
29 MEMORY_FILE Alternative way to specify memory file path
30
31EXAMPLE USAGE:
32 # Use default memory file
33 mcp-memory
34
35 # Use custom memory file
36 mcp-memory --memory-file /path/to/knowledge.json
37
38 # Test with MCP protocol
39 echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "read_graph", "arguments": {}}}' | mcp-memory
40
41MCP CAPABILITIES:
42 - Tools: create_entities, create_relations, read_graph, search_nodes, add_observations, and more
43 - Resources: memory:// URIs for knowledge graph access
44 - Persistence: JSON file storage with automatic saving
45 - Protocol: JSON-RPC 2.0 over stdio
46
47For detailed documentation, see: cmd/memory/README.md
48`)
49}
50
51func main() {
52 // Parse command line flags
53 var memoryFileFlag = flag.String("memory-file", "", "Path to the memory file (defaults to ~/.mcp_memory.json)")
54 var help = flag.Bool("help", false, "Show help message")
55 flag.Parse()
56
57 if *help {
58 printHelp()
59 return
60 }
61
62 memoryFile := *memoryFileFlag
63 if memoryFile == "" {
64 // Check environment variable
65 memoryFile = os.Getenv("MEMORY_FILE")
66 }
67 if memoryFile == "" {
68 // Default location
69 homeDir, err := os.UserHomeDir()
70 if err != nil {
71 log.Fatalf("Failed to get home directory: %v", err)
72 }
73 memoryFile = filepath.Join(homeDir, ".mcp_memory.json")
74 }
75
76 server := memory.New(memoryFile)
77
78 ctx := context.Background()
79 if err := server.Run(ctx); err != nil {
80 log.Fatalf("Server error: %v", err)
81 }
82}