GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(demo): add MCP relay demo with sqlite backend · majorcontext/keep@c6abb86

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • examples/mcp-relay-demo
    • demo.sh
    • relay.yaml
    • rules
      • demo.yaml
    • seed.sql
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/mcp-relay-demo/demo.sh‎

Copy file name to clipboard
+116Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Keep MCP Relay Demo
4+
#
5+
# Runs the keep-mcp-relay in front of a sqlite MCP server and demonstrates
6+
# policy enforcement: read-only mode and password redaction.
7+
#
8+
# Usage:
9+
# ./examples/mcp-relay-demo/demo.sh
10+
#
11+
set -euo pipefail
12+
13+
# ── Colors ───────────────────────────────────────────────────────
14+
BOLD='\033[1m'
15+
DIM='\033[2m'
16+
RED='\033[0;31m'
17+
GREEN='\033[0;32m'
18+
YELLOW='\033[0;33m'
19+
BLUE='\033[0;34m'
20+
CYAN='\033[0;36m'
21+
RESET='\033[0m'
22+
23+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
24+
DEMO_DIR=$(mktemp -d)
25+
RELAY_PORT=19090
26+
RELAY_PID=""
27+
28+
cleanup() {
29+
echo ""
30+
echo -e "${DIM}Cleaning up...${RESET}"
31+
[ -n "$RELAY_PID" ] && kill "$RELAY_PID" 2>/dev/null || true
32+
rm -rf "$DEMO_DIR"
33+
}
34+
trap cleanup EXIT
35+
36+
echo ""
37+
echo -e "${BOLD}Keep MCP Relay Demo${RESET}"
38+
echo -e "${DIM}Policy enforcement for MCP tool calls${RESET}"
39+
echo ""
40+
41+
# ── Prerequisites ────────────────────────────────────────────────
42+
if ! command -v sqlite3 &>/dev/null; then
43+
echo -e "${RED}Error:${RESET} sqlite3 is required but not found."
44+
echo " Install it with: brew install sqlite3 (macOS) or apt install sqlite3 (Linux)"
45+
exit 1
46+
fi
47+
48+
MCP_RUNNER=""
49+
if command -v npx &>/dev/null; then
50+
MCP_RUNNER="npx"
51+
elif command -v bunx &>/dev/null; then
52+
MCP_RUNNER="bunx"
53+
else
54+
echo -e "${RED}Error:${RESET} npx or bunx is required but neither was found."
55+
echo " Install Node.js (https://nodejs.org) or Bun (https://bun.sh)"
56+
exit 1
57+
fi
58+
59+
echo -e "${DIM}Using ${MCP_RUNNER} to run MCP sqlite server${RESET}"
60+
61+
# ── Build ────────────────────────────────────────────────────────
62+
echo -e "${DIM}Building relay...${RESET}"
63+
go build -o "$DEMO_DIR/keep-mcp-relay" ./cmd/keep-mcp-relay
64+
65+
# ── Seed database ───────────────────────────────────────────────
66+
DB_PATH="$DEMO_DIR/demo.db"
67+
sqlite3 "$DB_PATH" < "$SCRIPT_DIR/seed.sql"
68+
echo -e "${DIM}Seeded database with 12 users${RESET}"
69+
70+
# ── Generate relay config ───────────────────────────────────────
71+
sed \
72+
-e "s|RULES_DIR|$SCRIPT_DIR/rules|" \
73+
-e "s|LOG_OUTPUT|$DEMO_DIR/audit.jsonl|" \
74+
-e "s|COMMAND|$MCP_RUNNER|" \
75+
-e "s|ARGS|[\"-y\", \"@modelcontextprotocol/server-sqlite\", \"$DB_PATH\"]|" \
76+
"$SCRIPT_DIR/relay.yaml" > "$DEMO_DIR/relay.yaml"
77+
78+
# ── Start relay ─────────────────────────────────────────────────
79+
export KEEP_DEBUG="$DEMO_DIR/debug.log"
80+
81+
if [ -n "${KEEP_VERBOSE:-}" ]; then
82+
"$DEMO_DIR/keep-mcp-relay" --config "$DEMO_DIR/relay.yaml" >/dev/null &
83+
else
84+
"$DEMO_DIR/keep-mcp-relay" --config "$DEMO_DIR/relay.yaml" >/dev/null 2>&1 &
85+
fi
86+
RELAY_PID=$!
87+
sleep 2
88+
89+
if ! kill -0 "$RELAY_PID" 2>/dev/null; then
90+
echo -e "${RED}Error:${RESET} Relay failed to start. Check debug log: $KEEP_DEBUG"
91+
exit 1
92+
fi
93+
94+
echo -e "${GREEN}Relay running${RESET} on :${RELAY_PORT} ${DIM}(PID $RELAY_PID)${RESET}"
95+
echo ""
96+
97+
# ── Instructions ─────────────────────────────────────────────────
98+
echo -e "${BOLD}Connect Claude to the relay:${RESET}"
99+
echo ""
100+
echo -e " ${CYAN}claude mcp add keep-demo --transport http http://localhost:${RELAY_PORT}${RESET}"
101+
echo ""
102+
echo -e "${BOLD}Try these prompts:${RESET}"
103+
echo ""
104+
echo -e " ${BLUE}1.${RESET} \"List all users in the database\""
105+
echo -e " ${DIM}→ passwords will be redacted from the response${RESET}"
106+
echo ""
107+
echo -e " ${BLUE}2.${RESET} \"Add a new user named Test User\""
108+
echo -e " ${DIM}→ write operation will be denied${RESET}"
109+
echo ""
110+
echo -e "${BOLD}Audit log:${RESET} ${DIM}$DEMO_DIR/audit.jsonl${RESET}"
111+
echo -e "${BOLD}Debug log:${RESET} ${DIM}$KEEP_DEBUG${RESET}"
112+
echo ""
113+
echo -e "${DIM}Press Ctrl+C to stop the relay${RESET}"
114+
115+
# ── Wait ─────────────────────────────────────────────────────────
116+
wait "$RELAY_PID"
Collapse file

‎examples/mcp-relay-demo/relay.yaml‎

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
listen: ":19090"
2+
rules_dir: RULES_DIR
3+
4+
routes:
5+
- scope: demo-sqlite
6+
command: COMMAND
7+
args: ARGS
8+
9+
log:
10+
format: json
11+
output: LOG_OUTPUT
Collapse file

‎examples/mcp-relay-demo/rules/demo.yaml‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
scope: demo-sqlite
2+
mode: enforce
3+
4+
rules:
5+
# Block all write operations — database is read-only
6+
- name: block-writes
7+
match:
8+
operation: "write_query"
9+
action: deny
10+
message: "Database is read-only. Write operations are not permitted."
11+
12+
# Redact plaintext passwords from query results
13+
- name: redact-passwords
14+
match:
15+
operation: "read_query"
16+
when: "context.direction == 'response'"
17+
action: redact
18+
redact:
19+
target: "params.content"
20+
patterns:
21+
- match: "hunter2|p@ssw0rd!|letmein123|qwerty456|trustno1!|baseball9|shadow99!|dragon123|master!42|abc123xyz|welcome1!|passw0rd!"
22+
replace: "********"
23+
24+
# Log everything
25+
- name: audit-all
26+
match:
27+
operation: "*"
28+
action: log
Collapse file

‎examples/mcp-relay-demo/seed.sql‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE TABLE users (
2+
id INTEGER PRIMARY KEY,
3+
name TEXT NOT NULL,
4+
email TEXT NOT NULL,
5+
password TEXT NOT NULL,
6+
role TEXT NOT NULL
7+
);
8+
9+
INSERT INTO users VALUES (1, 'Alice Chen', '[email protected]', 'hunter2', 'admin');
10+
INSERT INTO users VALUES (2, 'Bob Park', '[email protected]', 'p@ssw0rd!', 'editor');
11+
INSERT INTO users VALUES (3, 'Carol White', '[email protected]', 'letmein123', 'viewer');
12+
INSERT INTO users VALUES (4, 'Dan Rivera', '[email protected]', 'qwerty456', 'editor');
13+
INSERT INTO users VALUES (5, 'Eve Foster', '[email protected]', 'trustno1!', 'admin');
14+
INSERT INTO users VALUES (6, 'Frank Zhao', '[email protected]', 'baseball9', 'viewer');
15+
INSERT INTO users VALUES (7, 'Grace Kim', '[email protected]', 'shadow99!', 'editor');
16+
INSERT INTO users VALUES (8, 'Hank Patel', '[email protected]', 'dragon123', 'viewer');
17+
INSERT INTO users VALUES (9, 'Iris Novak', '[email protected]', 'master!42', 'admin');
18+
INSERT INTO users VALUES (10, 'Jack Torres', '[email protected]', 'abc123xyz', 'editor');
19+
INSERT INTO users VALUES (11, 'Karen Liu', '[email protected]', 'welcome1!', 'viewer');
20+
INSERT INTO users VALUES (12, 'Leo Santos', '[email protected]', 'passw0rd!', 'editor');

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.