Notetion

mcp
Guvenlik Denetimi
Basarisiz
Health Uyari
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 5 GitHub stars
Code Basarisiz
  • rm -rf — Recursive force deletion command in package.json
  • network request — Outbound network request in public/sw.js
  • network request — Outbound network request in src/api.ts
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

Private markdown notepad running entirely on the Cloudflare Workers Free plan

README.md

Notetion

Private markdown notepad running entirely on the Cloudflare Workers Free plan —
focused writing, live preview, keyword (and optional private semantic) search, wiki-links,
offline editing, multi-device sync, private AI access (MCP), public sharing, and off-site backups.

Status: M9 complete — all milestones delivered. Private markdown notepad on Cloudflare Workers Free plan with focused writing, live preview, keyword and semantic search, wiki-links, offline editing, multi-device sync, private AI access (MCP), public sharing, and off-site backups.

Stack

Layer Choice
Frontend Vite + TypeScript + Preact (+ @preact/signals). CodeMirror 6, markdown-it, PrismJS, KaTeX, Mermaid, d3-force land in later milestones
Backend Hono on Cloudflare Workers (via @cloudflare/vite-plugin, local workerd)
Data D1 (accounts, notes, folders, tags, settings, versions; later FTS5 + per-account AI vectors + OAuth state), KV FILES_KV (attachments), Durable Objects SQLite backend (SyncHub realtime, CredentialVault backup keys), browser IndexedDB (offline, M3)

Design decision — no OAUTH_KV: OAuth 2.1 state (codes/tokens/grants) will live in D1
(strong consistency — KV's ~60 s eventual propagation breaks the authorize→token exchange;
free-plan KV also only allows 1k writes/day; SQL makes per-account grant management trivial).

Local development

npm install
npm run types              # generate worker-configuration.d.ts (binding types)
npm run db:migrate:local   # apply migrations/*.sql to local D1 (.wrangler/state)
cp .dev.vars.example .dev.vars   # first time only — then EDIT the password
npm run dev                # http://localhost:5173

Sign in with the credentials from .dev.vars (shipped defaults: admin / notetion-local-dev).
First successful login creates the sole admin account and seeds the two standard starter notes
(Traditional Chinese + English). Registration is closed by design.

Note for this machine's shell: the environment exports NPM_CONFIG_GLOBAL=true — prefix npm
installs with NPM_CONFIG_GLOBAL=false or packages go to the global prefix instead of the project.

Scripts

Script Purpose
dev Vite dev server + local workerd (D1/KV/DO simulated; state in .wrangler/)
build Production build (client → dist/client, worker → dist/notetion + output wrangler.json)
preview Run the built app in local workerd
deploy Build + wrangler deploy (requires auth and real resource ids — see below)
typecheck tsc --noEmit for src/ and worker/
types Regenerate worker-configuration.d.ts from wrangler.jsonc (+ .dev.vars secrets)
db:migrate:local Apply pending migrations to the local D1
db:reset:local Wipe .wrangler/state and re-migrate

API surface (M0)

  • GET /api/health
  • POST /api/auth/login · POST /api/auth/logout · GET /api/auth/me
  • GET/POST /api/notes · GET/PATCH/DELETE /api/notes/:id · POST /api/notes/:id/restore · DELETE /api/notes/:id?permanent=1
  • GET/POST /api/folders · PATCH/DELETE /api/folders/:id
  • GET/PUT /api/settings

PATCH /api/notes/:id takes base_version for optimistic concurrency; a stale write returns
409 {error:"version_conflict"}. Content edits snapshot the previous state into note_versions.

Type checking

npm run typecheck needs the generated Env types, which include secrets only when .dev.vars exists:
cp .dev.vars.example .dev.vars && npm run types && npm run typecheck
(the script runs src/ first and stops on its first error, so worker/ errors can appear only after src/ is clean).

Deploy checklist (when ready)

  1. npx wrangler login (or export CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID)
  2. npx wrangler d1 create notetion-db → replace database_id in wrangler.jsonc
  3. npx wrangler kv namespace create FILES_KV → replace id in wrangler.jsonc
  4. npx wrangler d1 migrations apply notetion-db --remote
  5. npx wrangler secret put ADMIN_PASSWORD (choose a strong password; ADMIN_USERNAME defaults to admin via vars)
  6. openssl rand -base64 48 → npx wrangler secret put BACKUP_ENCRYPTION_KEY (only needed for off-site backups; credentials are stored AES-GCM-encrypted with it. Losing/rotating it makes saved backup configs unreadable — re-create them)
  7. npm run deploy

Deploy from the Cloudflare dashboard (Git-connected, no local wrangler login)

Notetion is a Worker with static assets (not a Pages project), so it is deployed through
Workers & Pages → Create → Import a repository (Workers Builds). Button labels may differ slightly between dashboard versions.

1. Create the resources once (dashboard → Storage & databases)

  • D1 → Create database notetion-db → copy its Database ID.
  • KV → Create namespace FILES_KV → copy its Namespace ID.
  • Queues → Create queue embedding-queue (the Worker binds to it; deploy fails if it does not exist).
    Embeddings use Workers AI, which is optional — search works without it.

2. Put the IDs in wrangler.jsonc and push to your Git repo

  • d1_databases[0].database_id ← the D1 ID
  • kv_namespaces[0].id ← the KV ID
    (IDs are identifiers, not secrets, so committing them is fine.)

3. Import the repository

  • Workers & Pages → Create → Import a repository → pick the repo, branch main.
  • Worker name must equal "name" in wrangler.jsonc (notetion).
  • Build command: npm run build
  • Deploy command: npx wrangler d1 migrations apply notetion-db --remote && npx wrangler deploy
    (applies new migrations on every deploy, then publishes; already-applied migrations are skipped).
  • If the build says vite: not found, dev dependencies were skipped: add a build variable NODE_ENV=development
    (or change the build command to npm install --include=dev && npm run build).

4. Set secrets (Worker → Settings → Variables and Secrets → type Secret, not plain text)

  • ADMIN_PASSWORD — required.
  • BACKUP_ENCRYPTION_KEY — only for off-site backups; generate with openssl rand -base64 48, keep a copy
    (losing it makes saved backup configs unreadable).
  • Optional plain variables: ADMIN_USERNAME (default admin; the vars block in wrangler.jsonc is re-applied on each
    deploy, so change it there), ENABLE_MCP_OAUTH (true to enable MCP/OAuth/API keys).
    Secrets set in the dashboard survive deploys.

5. Redeploy and verify

  • Trigger a deploy (push a commit or Retry deployment) after setting secrets.
  • Open https://notetion.<your-subdomain>.workers.dev, check /api/health, sign in with ADMIN_USERNAME / ADMIN_PASSWORD.
  • Cron triggers (wrangler.jsonc) are registered by the deploy; no dashboard setup needed.

Dashboard-only alternative for the database: instead of the migrations command above, open D1 → notetion-db → Console
and paste each file from migrations/ in numeric order (0001 … 0009). Prefer the command; it tracks what was applied.

Roadmap

  • M0 scaffold: env-credential admin auth, notes/folders API + UI, autosave, version snapshots, trash/restore, i18n (zh-TW/en), themes, starter-note seeding, DO stubs, cleanup cron
  • M1 writing core: CodeMirror 6, independent title, desktop dual panes, per-pane edit/split/preview, sync scroll, outline, focus & typewriter modes, drag-sort folders, body tags, attachments (KV), favorite/pin/archive UI
  • M2 search & history: D1 FTS5 (unicode61 tokenizer, CJK character-by-character), command palette (Ctrl/Cmd+K), recents, version-history UI with restore, version retention cron (default 50 snapshots/note)
  • M3 offline & sync: installable PWA (manifest.json + sw.js), IndexedDB cache (notes/folders/pending writes), offline write queue with auto-sync on reconnect, optimistic concurrency (local-first then sync), SyncHub DO WebSocket (Hibernation API), online/offline state tracking
  • M4 wiki: WikiLinks ([[title]]), backlinks panel, block refs ([[title#^id]]), embeds (![[title]]), Obsidian comments (%%...%%), callouts (> [!tip]), KaTeX math, Mermaid diagrams, knowledge graph view
  • M5 MCP & API: API keys (ink_... prefix, revocable, scoped permissions), OAuth 2.1 + PKCE (D1 state), MCP endpoints (/mcp/notes, /mcp/search), chunked reading (10k chars/chunk), version-safe writes, API key management UI
  • M6 AI search: Workers AI embeddings (@cf/baai/bge-small-en-v1.5, 384-dim), per-note vectors in D1 (JSON), hybrid search (FTS5 + cosine similarity with RRF), background embedding queue (Queues), semantic search toggle () in command palette
  • M7 sharing & export: public share links (/s/:slug with optional passphrase + expiry), JSON/Markdown export, share management UI, export manager UI
  • M8 backups: CredentialVault DO (AES-GCM-256 encrypted credentials), WebDAV client, S3 client (SigV4), backup API (manual + scheduled via cron), backup history tracking, backup manager UI
  • M9 polish: mobile layout optimization, accent color picker (6 colors), complete zh-TW/en UI coverage, admin-only version update notices, settings panel

Security notes (M0)

  • Session tokens: 32 random bytes; only SHA-256 hashes stored; HttpOnly + SameSite=Lax
    (+ Secure / __Host- prefix in production), 30-day expiry, daily cron purge.
  • Admin password comparison is constant-time (digest XOR).
  • TODO before public deploy: login rate limiting (e.g. Turnstile, free), CSP headers,
    and request size limits.

To-dos, reminders & chat bots

To-dos are ordinary Markdown task items inside notes — no extra tables, and they stay portable
(the emoji spelling follows the Obsidian Tasks plugin):

- [ ] Pay the power bill 📅 2026-12-05             due date (optionally "📅 2026-12-05 18:00")
- [ ] Stand-up ⏰ 2026-12-05 09:00                  reminder; "⏰ 09:00" = at 09:00 on the due date
- [ ] Call mum @due(2026-12-05) @remind(18:30)     ASCII spelling of the same
- [x] Done thing ✅ 2026-12-04                      ticking from the To-do view / a bot stamps ✅ <date>
  • To-do view (sidebar → 待辦 / To-dos; on phones the 待辦 tab): every open task grouped as overdue / today /
    upcoming / no date (+ completed), folder filter, quick add (buy milk tomorrow 9am, 買牛奶 明天 9:00, 12/10,
    下午3點, +30m …) into the "待辦收件匣 / To-do inbox" note. Ticking writes the checkbox back into the note through
    the normal save pipeline (version snapshot, optimistic version check); if the line changed meanwhile you get a
    conflict and the list refreshes instead of ticking the wrong line. Needs a connection (checkboxes inside notes work offline).
  • Reminders: a cron trigger (* * * * *) sends each ⏰ reminder once to the linked Telegram chat and/or Slack,
    in the time zone from Settings → 待辦與提醒 (defaults to the browser's zone). Optional daily digest of overdue + today.
    Optional browser notifications while the app is open.
  • State: kept in the existing settings table under server-only sys: keys (per-note reminder index, chat
    bindings, one-time link code). No schema change / migration.

Telegram

  1. Create a bot with @BotFather → copy the token.
  2. npx wrangler secret put TELEGRAM_BOT_TOKEN and npx wrangler secret put TELEGRAM_WEBHOOK_SECRET
    (any random string, 1–256 chars of A-Za-z0-9_-, e.g. openssl rand -hex 32). Redeploy.
  3. Notetion → Settings → 聊天機器人 → 註冊 Webhook (calls setWebhook for https://<your-worker>/api/hooks/telegram
    with the secret; Telegram then signs every update with it).
  4. 產生綁定碼 → open the bot and send /start <code> (or tap the link). Codes are single-use and expire in 10 minutes.
  5. Commands: /todo <text> [time] (plain text works too), /today, /done <n|text>, /note <text>, /help.
    Reminder messages have a ✅ button that ticks the task.

Slack (custom app in your own workspace — no App Directory review needed)

  1. https://api.slack.com/apps → Create New App → From scratch.
  2. Slash Commands → /notetion, Request URL https://<your-worker>/api/hooks/slack (shown in Settings).
  3. OAuth & Permissions → bot scopes commands, chat:write → Install to Workspace → copy the Bot User OAuth Token.
  4. npx wrangler secret put SLACK_SIGNING_SECRET (Basic Information → Signing Secret) and
    npx wrangler secret put SLACK_BOT_TOKEN (xoxb-…). Redeploy.
  5. In Slack: /notetion bind <code> (code from Settings). Then /notetion todo …, /notetion today, /notetion done 2,
    /notetion note …. Reminders arrive as a DM from the app.
    Reminders only, no commands: set just SLACK_WEBHOOK_URL (an Incoming Webhook URL on hooks.slack.com).

All bot endpoints are off (404) until their secrets exist. Telegram updates are accepted only with the
X-Telegram-Bot-Api-Secret-Token header; Slack requests only with a valid X-Slack-Signature (≤ 5 minutes old).

MCP / OAuth / API keys (disabled by default)

The /mcp, /oauth, /api/oauth and /api/api-keys endpoints only serve external tools and return 404 unless
ENABLE_MCP_OAUTH is "true" (set it under vars in wrangler.jsonc, or in .dev.vars locally).

Using the MCP server

POST /mcp is a Model Context Protocol server (JSON-RPC 2.0, Streamable HTTP transport, stateless, JSON responses).

  1. Set ENABLE_MCP_OAUTH=true (dashboard: Worker → Settings → Variables and Secrets, or vars in wrangler.jsonc) and redeploy.
  2. In the app: sidebar → key icon (API Keys) → create a key (read, plus write / delete if the AI may edit / trash notes). Copy the ink_… token.
  3. Point an MCP client at https://<your-worker>/mcp with the header Authorization: Bearer ink_…:
# Claude Code
claude mcp add --transport http notetion https://notetion.<sub>.workers.dev/mcp --header "Authorization: Bearer ink_..."
// Cursor (~/.cursor/mcp.json) / other clients that accept remote servers with headers
{ "mcpServers": { "notetion": { "url": "https://notetion.<sub>.workers.dev/mcp", "headers": { "Authorization": "Bearer ink_..." } } } }

// Claude Desktop (stdio only) via the mcp-remote bridge
{ "mcpServers": { "notetion": { "command": "npx", "args": ["mcp-remote", "https://notetion.<sub>.workers.dev/mcp", "--header", "Authorization: Bearer ink_..."] } } }

Tools: search_notes, list_notes, read_note (10k-char chunks), list_folders, create_note, update_note
(pass base_version to avoid overwriting newer edits), append_to_note, delete_note (to trash), and for to-dos
list_todos, add_todo, complete_todo. Writes go through
the same pipeline as the app: version snapshot (source api, restorable in Version history), tags, wiki links,
embeddings and live sync. The older REST endpoints (/mcp/notes…, /mcp/search) still work with the same key.

Not implemented yet: OAuth discovery metadata (/.well-known/oauth-protected-resource, dynamic client registration),
so clients that only connect through OAuth (e.g. claude.ai custom connectors) cannot use it; use a client that sends a
Bearer header.

Yorumlar (0)

Sonuc bulunamadi