- Core: createDocument/updateDocument/deleteDocument (file + DB + revision + chunks) - Parser: stringifyFile (serialize markdown with frontmatter to disk) - API: tRPC CRUD routers (auth-gated via requireWriteAuth middleware) - API: createContext now passes expectedSecret from deps (request-scoped auth) - MCP: 3 new write tools (create_document, update_document, delete_document) - Web: /create page + ?edit=1 form, /api/auth/login (cookie-based), /api/docs REST CRUD - Web: Edit buttons on homepage + doc pages (auth-gated) - Tests: 8 new tests (5 tRPC CRUD + 3 MCP CRUD auth), 40 total all green
2.9 KiB
2.9 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
Files to touch:
packages/db/— migrations (users table, if needed)apps/api/src/— auth routes, CRUD tRPC routersapps/mcp/src/— add create/update/delete toolsapps/web/app/— edit/create pages, auth UI
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