|
| 1 | +# graphiti-mcp: Manage Graphiti MCP server with FalkorDB |
| 2 | + |
| 3 | +const OP_ITEM_ID = "h4hlt6o5gisjitk2iinjh7h7ya" |
| 4 | +const ENV_FILE = "~/.local/share/graphiti-mcp/.env" |
| 5 | + |
| 6 | +def main [ |
| 7 | + command?: string # start, stop, status, logs, restart, clean, update, fetch-key |
| 8 | + --follow (-f) # Follow logs (for logs command) |
| 9 | +] { |
| 10 | + let cmd = ($command | default "help") |
| 11 | + let data_dir = $"($env.HOME)/.local/share/graphiti-mcp" |
| 12 | + let compose_file = $COMPOSE_FILE |
| 13 | + let env_file = ($ENV_FILE | path expand) |
| 14 | + |
| 15 | + # Ensure data directory exists |
| 16 | + mkdir $data_dir |
| 17 | + |
| 18 | + # Create default .env if it doesn't exist |
| 19 | + if not ($env_file | path exists) { |
| 20 | + [ |
| 21 | + "# Graphiti MCP Configuration" |
| 22 | + "# Get your OpenAI API key from https://platform.openai.com/api-keys" |
| 23 | + "OPENAI_API_KEY=" |
| 24 | + "FALKORDB_PASSWORD=" |
| 25 | + "GRAPHITI_GROUP_ID=main" |
| 26 | + "" |
| 27 | + ] | str join "\n" | save $env_file |
| 28 | + print $"Created ($env_file) - please add your OPENAI_API_KEY" |
| 29 | + } |
| 30 | + |
| 31 | + # Base docker compose args |
| 32 | + let dc_args = [-f $compose_file --env-file $env_file -p graphiti-mcp] |
| 33 | + |
| 34 | + match $cmd { |
| 35 | + "start" => { |
| 36 | + # Check if OPENAI_API_KEY is set |
| 37 | + let env_content = (open $env_file) |
| 38 | + if ($env_content | str contains "OPENAI_API_KEY=\n") or ($env_content | str contains "OPENAI_API_KEY=$") { |
| 39 | + print $"(ansi red)Error: OPENAI_API_KEY not set in ($env_file)(ansi reset)" |
| 40 | + print "Run 'graphiti-mcp fetch-key' to fetch from 1Password" |
| 41 | + exit 1 |
| 42 | + } |
| 43 | + |
| 44 | + print "Starting Graphiti MCP server..." |
| 45 | + docker compose ...$dc_args up -d |
| 46 | + print "" |
| 47 | + print $"(ansi green)Graphiti MCP is running:(ansi reset)" |
| 48 | + print $" FalkorDB: redis://localhost:6379" |
| 49 | + print $" FalkorDB UI: http://localhost:3030" |
| 50 | + print $" MCP Server: http://localhost:8000/mcp/" |
| 51 | + print $" Health: http://localhost:8000/health" |
| 52 | + print "" |
| 53 | + print $"Config: ($env_file)" |
| 54 | + } |
| 55 | + "stop" => { |
| 56 | + print "Stopping Graphiti MCP server..." |
| 57 | + docker compose ...$dc_args down |
| 58 | + } |
| 59 | + "restart" => { |
| 60 | + docker compose ...$dc_args restart |
| 61 | + } |
| 62 | + "status" => { |
| 63 | + docker compose ...$dc_args ps |
| 64 | + } |
| 65 | + "logs" => { |
| 66 | + if $follow { |
| 67 | + docker compose ...$dc_args logs -f |
| 68 | + } else { |
| 69 | + docker compose ...$dc_args logs --tail 100 |
| 70 | + } |
| 71 | + } |
| 72 | + "clean" => { |
| 73 | + print $"(ansi yellow)This will remove all Graphiti data!(ansi reset)" |
| 74 | + let confirm = (input "Are you sure? [y/N]: ") |
| 75 | + if ($confirm | str downcase) == "y" { |
| 76 | + docker compose ...$dc_args down -v |
| 77 | + print "Volumes removed." |
| 78 | + } else { |
| 79 | + print "Cancelled." |
| 80 | + } |
| 81 | + } |
| 82 | + "update" => { |
| 83 | + print "Pulling latest image..." |
| 84 | + docker compose ...$dc_args pull |
| 85 | + docker compose ...$dc_args up -d |
| 86 | + } |
| 87 | + "fetch-key" => { |
| 88 | + print "Fetching OpenAI key from 1Password..." |
| 89 | + let key = (op item get $OP_ITEM_ID --fields credential --format json | from json | get value) |
| 90 | + |
| 91 | + # Read current .env and update OPENAI_API_KEY |
| 92 | + let env_content = (open $env_file) |
| 93 | + let updated = ($env_content | str replace -r 'OPENAI_API_KEY=.*' $"OPENAI_API_KEY=($key)") |
| 94 | + $updated | save -f $env_file |
| 95 | + |
| 96 | + print $"(ansi green)OpenAI key saved to ($env_file)(ansi reset)" |
| 97 | + } |
| 98 | + "help" => { |
| 99 | + print "graphiti-mcp - Manage Graphiti MCP server with FalkorDB" |
| 100 | + print "" |
| 101 | + print "Commands:" |
| 102 | + print " start Start the server" |
| 103 | + print " stop Stop the server" |
| 104 | + print " restart Restart the server" |
| 105 | + print " status Show container status" |
| 106 | + print " logs Show recent logs (use -f to follow)" |
| 107 | + print " update Pull latest image and restart" |
| 108 | + print " clean Remove all data (with confirmation)" |
| 109 | + print " fetch-key Fetch OpenAI key from 1Password" |
| 110 | + print "" |
| 111 | + print $"Config: ($env_file)" |
| 112 | + } |
| 113 | + _ => { |
| 114 | + print $"Unknown command: ($cmd)" |
| 115 | + print "Run 'graphiti-mcp help' for usage" |
| 116 | + exit 1 |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments