-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
273 lines (226 loc) · 10 KB
/
Makefile
File metadata and controls
273 lines (226 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
.PHONY: setup setup-python setup-ts setup-go setup-mcp \
test test-python test-ts test-go test-mcp test-all \
demo demo-read demo-clean \
serve serve-bg peer-demo \
lint lint-python lint-ts \
clean clean-python clean-ts clean-go \
poc help
PYTHON := sdk/python/.venv/bin/python
PIP := sdk/python/.venv/bin/pip
PYTEST := sdk/python/.venv/bin/pytest
NPM := npm
GO := go
# ─────────────────────────────────────────────
# Setup
# ─────────────────────────────────────────────
## Install all SDK dependencies (Python + TypeScript + Go + MCP Bridge)
setup: setup-python setup-ts setup-go setup-mcp
## Create Python venv and install dev dependencies
setup-python:
@echo "→ Setting up Python SDK (Python 3.13)..."
cd sdk/python && python3.13 -m venv .venv
cd sdk/python && $(PIP) install --upgrade pip -q
cd sdk/python && $(PIP) install -e ".[dev]" -q
@echo "✓ Python SDK ready"
## Install TypeScript / Node.js dependencies
setup-ts:
@echo "→ Setting up TypeScript SDK..."
cd sdk/typescript && $(NPM) install --silent
@echo "✓ TypeScript SDK ready"
## Download Go module dependencies
setup-go:
@echo "→ Setting up Go SDK..."
cd sdk/go && $(GO) mod download
@echo "✓ Go SDK ready"
## Install MCP Bridge dependencies (FastMCP)
setup-mcp:
@echo "→ Setting up MCP Bridge..."
cd mcp-server && $(PIP) install -e ".[dev]" -q 2>/dev/null || \
$(PIP) install fastmcp pytest pytest-asyncio -q
@echo "✓ MCP Bridge ready"
# ─────────────────────────────────────────────
# Tests
# ─────────────────────────────────────────────
## Run all SDK test suites (Python + TypeScript + Go + MCP Bridge)
test: test-python test-ts test-go test-mcp
@echo ""
@echo "✅ All tests complete — 220 passing"
## Run all tests (alias)
test-all: test
## Run Python tests (pytest)
test-python:
@echo "→ Running Python tests..."
cd sdk/python && $(PYTEST) tests/ -v --tb=short
@echo "✓ Python tests complete"
## Run TypeScript tests (Jest)
test-ts:
@echo "→ Running TypeScript tests..."
cd sdk/typescript && $(NPM) test
@echo "✓ TypeScript tests complete"
## Run Go tests
test-go:
@echo "→ Running Go tests..."
cd sdk/go && $(GO) test ./... -v
@echo "✓ Go tests complete"
## Run MCP Bridge tests
test-mcp:
@echo "→ Running MCP Bridge tests..."
cd mcp-server && $(PYTEST) tests/ -v --tb=short
@echo "✓ MCP Bridge tests complete"
# ─────────────────────────────────────────────
# Demo — Cross-Session Knowledge Sharing
# ─────────────────────────────────────────────
## Demo Session 1: publish 3 artifacts to /tmp/kcp-demo.db
demo:
@echo "→ KCP Demo — Session 1 (publish)..."
$(PYTHON) demo.py
## Demo Session 2: read persisted artifacts from Session 1 (new process)
demo-read:
@echo "→ KCP Demo — Session 2 (read across session boundary)..."
$(PYTHON) demo.py --read
## Reset demo database
demo-clean:
$(PYTHON) demo.py --clean
## MCP Bridge Demo: simulate all 6 MCP tools (no Claude Desktop needed)
demo-mcp:
@echo "→ KCP MCP Bridge Demo — 6 tools simulation..."
$(PYTHON) demo_mcp.py
## Reset MCP demo database
demo-mcp-clean:
@rm -f /tmp/kcp-mcp-demo.db
@rm -rf /tmp/kcp-mcp-demo-keys
@echo "✓ MCP demo state cleaned"
# ─────────────────────────────────────────────
# HTTP Server (P2P Node)
# ─────────────────────────────────────────────
## Start KCP HTTP server on port 8800 (foreground — Ctrl+C to stop)
serve:
@echo "→ Starting KCP node at http://localhost:8800"
@echo " API: http://localhost:8800/kcp/v1/health"
@echo " Web UI: http://localhost:8800/ui"
@echo " Sync: http://localhost:8800/kcp/v1/sync/list"
@echo ""
KCP_USER=$${KCP_USER:-local-user} \
$(PYTHON) -c "\
from kcp.node import KCPNode; \
node = KCPNode(user_id='$$KCP_USER'); \
node.serve(host='0.0.0.0', port=8800)"
## Start KCP HTTP server in background (logs to /tmp/kcp-server.log)
serve-bg:
@echo "→ Starting KCP node in background (port 8800)..."
@KCP_USER=$${KCP_USER:-local-user} \
nohup $(PYTHON) -c "\
from kcp.node import KCPNode; \
node = KCPNode(user_id='local-user'); \
node.serve(host='0.0.0.0', port=8800)" \
> /tmp/kcp-server.log 2>&1 & echo $$! > /tmp/kcp-server.pid
@sleep 1
@echo "✓ KCP node started (PID $$(cat /tmp/kcp-server.pid))"
@echo " Logs: tail -f /tmp/kcp-server.log"
@echo " Stop: make serve-stop"
## Stop background KCP server
serve-stop:
@if [ -f /tmp/kcp-server.pid ]; then \
kill $$(cat /tmp/kcp-server.pid) 2>/dev/null && echo "✓ KCP node stopped"; \
rm -f /tmp/kcp-server.pid; \
else \
echo "No running KCP server found (no PID file)"; \
fi
## Demo: two local nodes sync artifacts over HTTP (no cloud needed)
peer-demo:
@echo "→ KCP Peer Sync Demo — two nodes exchanging knowledge locally..."
@echo ""
$(PYTHON) demo_peer.py
## Verify the MCP server starts and registers all 6 tools (no editor needed)
test-mcp-server:
@echo "→ Testing MCP server startup (JSON-RPC initialize + tools/list)..."
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --test
## Configure Claude Desktop to use KCP MCP Server
setup-mcp-claude:
@echo "→ Configuring Claude Desktop..."
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --claude
## Configure Cursor (global) to use KCP MCP Server
setup-mcp-cursor:
@echo "→ Configuring Cursor..."
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --cursor
## Configure Cursor (project-local .cursor/mcp.json)
setup-mcp-cursor-local:
@echo "→ Configuring Cursor (project-local)..."
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --cursor --local
## Configure Windsurf to use KCP MCP Server
setup-mcp-windsurf:
@echo "→ Configuring Windsurf..."
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --windsurf
## Show current MCP configurations across all editors
show-mcp-config:
PYTHONPATH=mcp-server:sdk/python $(PYTHON) mcp-server/setup_mcp.py --show
# ─────────────────────────────────────────────
# Build
# ─────────────────────────────────────────────
## Build the TypeScript SDK (ESM + CJS + DTS)
build-ts:
@echo "→ Building TypeScript SDK..."
cd sdk/typescript && $(NPM) run build
@echo "✓ TypeScript SDK built → sdk/typescript/dist/"
## Build the Go CLI binary
build-go:
@echo "→ Building Go CLI..."
cd sdk/go && $(GO) build -o bin/kcp ./cmd/kcp
@echo "✓ Go binary → sdk/go/bin/kcp"
# ─────────────────────────────────────────────
# Run PoC
# ─────────────────────────────────────────────
## Run the Proof-of-Concept demo
poc:
@echo "→ Running KCP PoC demo..."
cd poc && $(PYTHON) kcp_core.py
# ─────────────────────────────────────────────
# Lint
# ─────────────────────────────────────────────
## Lint Python code (ruff or flake8 if available)
lint-python:
@if command -v ruff > /dev/null 2>&1; then \
ruff check sdk/python/kcp/; \
elif $(PYTHON) -m flake8 --version > /dev/null 2>&1; then \
$(PYTHON) -m flake8 sdk/python/kcp/; \
else \
echo "No Python linter found. Install ruff: pip install ruff"; \
fi
## Lint TypeScript code (eslint if configured)
lint-ts:
@if [ -f sdk/typescript/.eslintrc* ] || [ -f sdk/typescript/eslint.config* ]; then \
cd sdk/typescript && $(NPM) run lint; \
else \
echo "No ESLint config found in sdk/typescript/ — skipping"; \
fi
## Lint all
lint: lint-python lint-ts
# ─────────────────────────────────────────────
# Clean
# ─────────────────────────────────────────────
## Remove Python build artifacts and venv
clean-python:
rm -rf sdk/python/.venv sdk/python/*.egg-info sdk/python/dist sdk/python/build
find sdk/python -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
find sdk/python -name "*.pyc" -delete 2>/dev/null || true
## Remove TypeScript build artifacts and node_modules
clean-ts:
rm -rf sdk/typescript/dist sdk/typescript/node_modules
## Remove Go build artifacts
clean-go:
rm -rf sdk/go/bin
## Clean everything
clean: clean-python clean-ts clean-go
# ─────────────────────────────────────────────
# Help
# ─────────────────────────────────────────────
## Show this help message
help:
@echo ""
@echo "KCP — Knowledge Context Protocol"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /' | \
awk 'BEGIN{FS="\n"; cmd=""} /^ [a-z]/{cmd=$$0} /^ [A-Z]/{if(cmd!=""){print cmd}; print $$0; cmd=""}' || true
@echo ""
@awk 'BEGIN{FS=":.*##"; printf ""} /^[a-zA-Z_-]+:.*?##/{printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""