- Install rehype-slug (proper heading anchors) + github-slugger (matching TOC) - TOC component: auto-generated from h2/h3 headings, clickable anchors - Dark mode toggle: ThemeToggle (localStorage + system default), class-based - /docs index page (lists all docs by section) - Markdown.tsx uses rehype-slug for stable heading ids - globals.css: @custom-variant dark (.dark class) for class-based dark mode - layout.tsx: nav includes ThemeToggle Note: per user instruction, installed real deps (rehype-slug, github-slugger, @types/hast) instead of hacky inline any-cast hacks.
3.7 KiB
3.7 KiB
MCPedia Phase 11 — CRUD + Auth + UI/UX Improvement
Plan (spec BEFORE implementation, per user rule)
Scope: 4 areas
- CRUD: Create/Read/Update/Delete documents from web UI + MCP
- Auth: Session-based auth for web edits; API key auth for MCP writes
- UI/UX: Polish doc page, edit forms, search UX, dark mode
- Agent integration: MCP tools for CRUD with auth
Requirements:
- Source of truth is the filesystem — each doc is a markdown file under
content/{section}/{slug}.mdwith YAML frontmatter (parsed/striped by gray-matter). - DB mirrors disk —
documentstable has slug/title/section/body/status/tags/etc;document_chunksstores embeddings;document_revisionssnapshots body+meta. - Single indexing path —
indexContentFilein@mcpedia/corewrites DB + revisions + chunks; CRUD ops call it (or its pieces) after writing the file. - Auth — MCP/API writes require
x-webhook-secretmatchingWEBHOOK_SECRET(Phase 4 pattern). Web CRUD uses cookie-based auth (Phase 11 addition:ADMIN_PASSWORD). - Slug rules —
[a-z0-9][a-z0-9/_-]*, no//, no path traversal (..). The slug in the URL is<section>/<slug-parts>. - No breaking existing features — read tools/routes unchanged; existing 32 tests still green.
- UI/UX — edit button on doc pages (auth-gated),
?edit=1inline form,/createpage, login page, table of contents auto-generated from h2, dark mode toggle.
Schema changes:
- Optional:
userstable if auth is user-based - OR: simple
WEB_AUTH_TOKENenv for admin access (simpler, fits single-author KB)
Backend surface:
- Web auth: Cookie-based session OR single admin token in localStorage
- Simpler approach:
POST /api/auth/login(checksADMIN_PASSWORDenv) → sets cookie - Edit UI gated behind cookie check in server components
- Simpler approach:
- MCP auth:
x-api-keyheader for write tools (create/update/delete)- Read tools (list, get, search) — public
- Write tools (create, update, delete, index_document, reindex_all, restore_revision) — require key
createMcpServer(authKey?)threads the header, same pattern asx-webhook-secret
CRUD operations:
- Create:
POST /trpc/createDocument(title, slug, section, body, tags)- Writes markdown file to
content/{section}/{slug}.md - Triggers indexer (enqueues job or calls directly)
- Writes markdown file to
- Update:
POST /trpc/updateDocument(slug, body, title, tags, status)- Updates file + creates revision + reindexes
- Delete:
POST /trpc/deleteDocument(slug)- Removes file, DB rows, chunks; creates revision tombstone
- All mutations require auth (web cookie OR webhook secret OR MCP api-key)
UI improvements:
- Edit button on doc pages (auth-gated) → link to
/docs/{slug}/edit - Create page:
/docs/createwith form (section dropdown, slug, title, tags, markdown editor) - Edit page:
/docs/{slug}/editpre-fills from getDocument - Search page: live search results with keyboard nav, better empty states
- Doc page: table of contents (auto-generated from h2), dark mode toggle
Verification steps:
- TDD: write failing tests for each new API endpoint/method first
bun run typecheck— greenbun run test— 32 existing + new tests greenbun run build— green- CI + Deploy passes
- Browser: create doc → search sees it → edit doc → changes reflect → delete doc → gone
- MCP: create_document tool with key → doc appears; without key → unauthorized
Acceptance criteria:
- createDocument tRPC + MCP
- updateDocument tRPC + MCP
- deleteDocument tRPC + MCP
- Web auth (cookie-based login)
- MCP write-tool auth (api-key)
- UI: edit/create pages
- UI: TOC + dark mode on doc pages
- All tests green, CI+Deploy passes