Skip to content

Commit 57d4335

Browse files
committed
Add graphiti mcp manager
1 parent 9e3febb commit 57d4335

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

modules/home-manager/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
gh
4040
git-coauthor
4141
gnupg
42+
graphiti-mcp
4243
k9s
4344
k3d
4445
kubectl

packages/graphiti-mcp/default.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
writers,
3+
fetchurl,
4+
runCommand,
5+
gnused,
6+
}:
7+
8+
let
9+
version = "0.24.1";
10+
11+
dockerComposeRaw = fetchurl {
12+
url = "https://raw.githubusercontent.com/getzep/graphiti/v${version}/mcp_server/docker/docker-compose.yml";
13+
hash = "sha256-zO46+LvTMa2XR9b3QNut6VRJfEnDxohroSZLwP9lJ6E=";
14+
};
15+
16+
# Patch the compose file to:
17+
# 1. Remove env_file directive (which uses relative path)
18+
# 2. Add OPENAI_API_KEY to environment section for substitution via --env-file
19+
# 3. Change FalkorDB UI port from 3000 to 3030 (avoid conflict with dev servers)
20+
dockerCompose = runCommand "docker-compose.yml" { } ''
21+
${gnused}/bin/sed \
22+
-e '/env_file:/,/required:/d' \
23+
-e 's/environment:/environment:\n - OPENAI_API_KEY=''${OPENAI_API_KEY}/' \
24+
-e 's/"3000:3000"/"3030:3000"/' \
25+
${dockerComposeRaw} > $out
26+
'';
27+
in
28+
writers.writeNuBin "graphiti-mcp" ''
29+
const COMPOSE_FILE = "${dockerCompose}"
30+
31+
${builtins.readFile ./graphiti-mcp.nu}
32+
''
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
}

packages/overlay.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
final: prev: {
22
beads = prev.callPackage ./beads { };
33
git-coauthor = prev.callPackage ./git-coauthor { };
4+
graphiti-mcp = prev.callPackage ./graphiti-mcp { };
45
system-update = prev.callPackage ./system-update { };
56
zsm = prev.callPackage ./zsm { };
67
}

0 commit comments

Comments
 (0)