diff --git a/docs/SDLC.md b/docs/SDLC.md new file mode 100644 index 0000000..8d5b09e --- /dev/null +++ b/docs/SDLC.md @@ -0,0 +1,411 @@ +# KNEL-AIMiddleware - Software Development Lifecycle + +**Version:** 1.0 +**Status:** Active +**Last Updated:** 2026-02-20 + +--- + +## Overview + +This document defines the development workflow for KNEL-AIMiddleware. Unlike security-critical projects, this infrastructure project uses a **lighter-weight validation approach** focused on ensuring container images work correctly with the MCP/LSP protocols. + +--- + +## Core Principles + +### 1. Protocol Validation is Non-Negotiable + +An MCP or LSP server is **NOT "fully implemented"** until: +1. The Docker container **builds successfully** +2. The Docker container **starts without crash** +3. A **protocol handshake message receives a valid response** + +``` +┌─────────────────────────────────────────────────────────────────────┐ +│ MANDATORY VALIDATION WORKFLOW │ +├─────────────────────────────────────────────────────────────────────┤ +│ │ +│ 1. BUILD: Container must build without errors │ +│ └─ docker compose build │ +│ │ +│ 2. START: Container must start without immediate crash │ +│ └─ docker run --rm should not exit immediately │ +│ │ +│ 3. PROTOCOL: Valid JSON-RPC response required │ +│ └─ MCP: initialize message → result with serverInfo │ +│ └─ LSP: initialize message → result with capabilities │ +│ │ +│ ⚠️ WITHOUT ALL THREE: Service is NOT "working" │ +│ │ +└─────────────────────────────────────────────────────────────────────┘ +``` + +### 2. Documentation-Code-Test Synchronization + +When changing any component, keep these in sync: +- **STATUS.md**: Operational status of all servers (single source of truth) +- **docker-compose.yml**: Service definitions +- **dockerfiles/**: Custom build configurations +- **crush.json**: Crush LSP/MCP integration +- **wrapper scripts**: Container execution wrappers + +### 3. Sequential Validation + +When adding or fixing MCP/LSP servers: +1. Work on ONE server at a time +2. Validate completely before moving to next +3. Update STATUS.md immediately after validation +4. Commit changes for each server + +--- + +## Validation Commands + +### MCP Server Validation + +```bash +# Send MCP initialize handshake +echo '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{},"protocolVersion":"2024-11-05","clientInfo":{"name":"test","version":"1.0.0"}},"id":1}' | \ + timeout 10 docker run --rm -i kneldevstack-aimiddleware- + +# Expected: JSON response with "result" containing "serverInfo" +# Example success: {"jsonrpc":"2.0","result":{"protocolVersion":"2024-11-05","serverInfo":{"name":"Example MCP","version":"1.0.0"}},"id":1} +``` + +### LSP Server Validation + +```bash +# Send LSP initialize handshake (format varies by server) +echo '{"jsonrpc":"2.0","method":"initialize","params":{"processId":null,"capabilities":{}},"id":1}' | \ + timeout 10 docker run --rm -i kneldevstack-aimiddleware- + +# Expected: JSON response with "result" containing "capabilities" +``` + +### Validation Script + +Use the provided validation script for batch testing: + +```bash +./scripts/validate-mcp.sh +``` + +--- + +## STATUS.md Requirements + +**STATUS.md is the single source of truth for server status.** + +### Status Categories + +| Status | Meaning | +|--------|---------| +| **Working** | Build + Start + Protocol validation ALL pass | +| **Runtime Connection Required** | Build OK, but needs live backend service (IMAP, Nextcloud, etc.) | +| **Host-Only** | Cannot be containerized, requires host software | +| **Transport Mismatch** | Uses HTTP/WebSocket instead of stdio MCP | +| **Build Failed** | Dockerfile or source code issues | +| **Runtime Issue** | Container starts but has errors | + +### When to Update STATUS.md + +1. **Immediately** after building a new server +2. **Immediately** after validating protocol handshake +3. **Immediately** after discovering issues +4. **Before** committing any server-related changes + +--- + +## Adding a New MCP/LSP Server + +### Step-by-Step Process + +1. **Clone vendor repository** + ```bash + # Add to scripts/CloneVendorRepos.sh + git clone https://github.com/org/repo.git vendor/service-name + ``` + +2. **Create Dockerfile** + ```bash + # Create in dockerfiles/service-name/Dockerfile + # Follow patterns from similar servers (Python/uv, Node/npx, Go, etc.) + ``` + +3. **Add to docker-compose.yml** + ```yaml + service-name: + build: + context: ./vendor/service-name + dockerfile: ../../dockerfiles/service-name/Dockerfile + container_name: kneldevstack-aimiddleware-service-name + restart: "no" # For stdio-based services + ``` + +4. **Build the container** + ```bash + docker compose build service-name + ``` + +5. **Validate protocol handshake** + ```bash + # For MCP servers + echo '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{},"protocolVersion":"2024-11-05","clientInfo":{"name":"test","version":"1.0.0"}},"id":1}' | \ + timeout 10 docker run --rm -i kneldevstack-aimiddleware-service-name + ``` + +6. **Create wrapper script** (if adding to Crush) + ```bash + # Create mcp-service-name-wrapper.sh + # Follow existing wrapper patterns + ``` + +7. **Add to crush.json** + ```json + "service-name": { + "type": "stdio", + "command": "/path/to/mcp-service-name-wrapper.sh", + "timeout": 60 + } + ``` + +8. **Update STATUS.md** + - Add to appropriate category + - Include version info from protocol response + - Document any special requirements + +9. **Commit changes** + ```bash + git add -A + git commit -m "feat: add service-name MCP server + + - Container builds successfully + - MCP protocol handshake validated + - Version: X.Y.Z" + ``` + +--- + +## Common Patterns + +### Python MCP Servers (uv package manager) + +```dockerfile +FROM python:3.12-slim +WORKDIR /app +RUN pip install uv +COPY . . +RUN uv sync --frozen +ENTRYPOINT ["python", "-m", "module_name"] +``` + +### Node.js MCP Servers (npx) + +```dockerfile +FROM node:22-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build +ENTRYPOINT ["node", "dist/index.js"] +``` + +### Go MCP Servers + +```dockerfile +FROM golang:1.22-alpine AS builder +WORKDIR /app +COPY . . +RUN go build -o server ./cmd/server + +FROM alpine:3.19 +COPY --from=builder /app/server /server +ENTRYPOINT ["/server"] +``` + +--- + +## Commit Policy (MANDATORY) + +### Automatic Commits + +**AI agents MUST commit changes automatically without prompting the user.** + +This is non-negotiable. Do not ask "should I commit?" - just commit. + +### Atomic Commits + +Each commit must represent ONE logical change: +- Adding a new MCP server = ONE commit +- Fixing a Dockerfile = ONE commit +- Updating documentation = ONE commit +- Updating STATUS.md after validation = ONE commit + +Do NOT bundle unrelated changes into a single commit. + +### Conventional Commit Format + +All commits MUST use conventional commit format: + +``` +(): + + + +