scrapbox-cosense-mcp
CLAUDE.md54 starsChanged 18 months agoMITView on GitHub
MCP server for Cosense (Scrapbox). Also works as a CLI. All tools are also available as CLI subcommands (get, list, search, create, url, insert, edit, delete-lines, delete, rewrite, context). delete and rewrite require COSENSE_ENABLE_DELETE=true and support --dry-run. Run scrapbox-cosense-mcp <command> --help for usage. Key flags: skills/scrapbox/SKILL.md defines a Claude Code skill that wraps the CLI. When users invoke /cosense, Claude Code reads SKILL.md and executes CLI commands via Bash. Keep SKILL.md concise — details should be discoverable via --help. .claude-plugin/…
- Reads credentials
- Installs packages
In this repositoryOne other file it gives its agents.
- cosenseSkill
The file
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
All tools are also available as CLI subcommands (get, list, search, create, url, insert, edit, delete-lines, delete, rewrite, context).
- Very specific: line 111
Create release/vX.Y.Z branch, bump version in package.json + manifest.json + .claude-plugin/plugin.json
- Distinctive: line 113
Create PR → CI passes → merge
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
MCP server for Cosense (Scrapbox). Also works as a CLI.
Commands
npm run build # TypeScript → JavaScript (uses tsconfig.build.json)
npm run watch # Auto-rebuild during development
npm run test # Run Jest tests (no real API calls)
COSENSE_E2E=true npm run test # Also run the E2E tests against the real Cosense API — sparingly, e.g. once before merging
npm run lint # ESLint (console.log triggers warning)
npm run inspector # Debug with MCP InspectorArchitecture
Tools (11, or 9 without COSENSE_ENABLE_DELETE)
| Tool | Description | Auth |
get_page | Retrieve page content, metadata, and links | - |
list_pages | List pages with sorting and pagination (max 1000) | - |
search_pages | Keyword search (API limit: 100 results) | - |
create_page | Create new page. Rejects if page already exists | SID |
get_page_url | Generate URL from page title | - |
insert_lines | Insert text after a target line (exact match). Appends to end if not found | SID |
edit_lines | Replace target line(s) (exact match, multi-line block supported). Errors if not found. matchAll replaces every occurrence | SID |
delete_lines | Delete target line(s) (exact match, multi-line block supported). Refuses to delete the title line. Errors if not found. matchAll deletes every occurrence | SID |
delete_page | Delete a page by emptying every line. Registered only when COSENSE_ENABLE_DELETE=true. Errors if the page does not exist. dryRun previews | SID |
rewrite_page | Replace a page's entire content. Registered only when COSENSE_ENABLE_DELETE=true. Errors if the page does not exist or content is empty. dryRun previews before/after | SID |
get_smart_context | Get page + linked pages (1-hop/2-hop) in AI-optimized format | SID |
CLI
All tools are also available as CLI subcommands (get, list, search, create, url, insert, edit, delete-lines, delete, rewrite, context). delete and rewrite require COSENSE_ENABLE_DELETE=true and support --dry-run. Run scrapbox-cosense-mcp <command> --help for usage. Key flags:
--compact— Token-efficient output (85% smaller for list)--json— JSON output--project=NAME— Override project name
Skill (SKILL.md)
skills/scrapbox/SKILL.md defines a Claude Code skill that wraps the CLI. When users invoke /cosense, Claude Code reads SKILL.md and executes CLI commands via Bash. Keep SKILL.md concise — details should be discoverable via --help.
Claude Code Plugin
.claude-plugin/ (plugin.json + marketplace.json) enables installation via /plugin marketplace add worldnine/scrapbox-cosense-mcp. The marketplace resolves the plugin from the npm package, so .claude-plugin/, .mcp.json, and skills/ must be listed in package.json files — a plugin fix only takes effect after the next npm release.
Desktop Extensions (.mcpb)
manifest.json + .mcpbignore enable Claude Desktop Extensions packaging. The .mcpb file is auto-built and attached to GitHub Releases by release-mcpb.yml. To build locally: npm install --omit=dev && npx @anthropic-ai/mcpb pack.
Directory Structure
src/cosense.ts— Scrapbox REST API clientsrc/routes/handlers/— One handler module per toolsrc/utils/format.ts— Response formatting,stringifyError,formatErrorsrc/utils/sort.ts— Sorting with pinned page filteringsrc/utils/project.ts—COSENSE_PROJECT_ALLOW_LISTcheck (checkProjectAllowed)src/utils/markdown-converter.ts— Markdown → Scrapbox conversion (usesmd2sb)src/types/— API response and MCP request/response type definitionssrc/cli.ts— CLI entry point (args → CLI mode, no args → MCP server)src/index.ts— Server entry point
Design Decisions
- WebSocket API (
@cosense/std) is used for all page writes (create_page/insert_lines/edit_lines/delete_lines/delete_page/rewrite_page) because the REST API has no page creation/editing endpoints create_pagerejects existing pages (persistent === true). Without this check,patch()silently replaces all content since it's a diff-update APIinsert_linesuses exact match. Partial match risks inserting at unintended linesedit_lines/delete_linesdefault tomatchAll: false. Repeated lines (bullet markers, blank lines) are common, so replacing/deleting every occurrence by default would exceed what the caller asked foredit_lines/delete_linestreat a newline-containingtargetLineTextas a contiguous block. Matching is non-overlapping withmatchAll, so n lines can become m lines (edit) or be removed together (delete)delete_linesrefuses to delete the title line (the first line). Deleting it would rename the page — or remove it entirely if nothing else remains — which would bypass theCOSENSE_ENABLE_DELETEgate ondelete_page. It returns an error pointing todelete_pageinsteaddelete_pageandrewrite_pageare gated byCOSENSE_ENABLE_DELETEat tool-registration time, not just at call time. This server is often placed in a shared MCP configuration, so an unset variable means the tools never appear in the tool list and cannot be called by mistake. The handlers check the variable again, so the CLI and direct calls are covered too- The gate boundary is "does the caller have to name the content it destroys".
insert_lines/edit_lines/delete_linesrequire exact matches, which only succeed if the caller has read the page.delete_page/rewrite_pageact on the whole page regardless, so they get the opt-in gate delete_pagechecks existence before deleting. The REST API returns a title line even for a page that was never created, so line count cannot tell existence apart —persistentdoes, the same waycreate_pagedecides. Without this check a delete against a missing page reports successrewrite_pageinverts the existence check: it rejects pages that do NOT exist (persistent !== true). A title typo must not silently create a new page, and it must reject empty content (deletion isdelete_page's job)delete_pageandrewrite_pagesupportdryRun, which report the line counts (and previews) without callingpatch()at all. There is no undo, so an agent should be able to look before it actsinsert_linesandedit_lines/delete_linesdiffer when the target is missing, deliberately.insert_linesappends to the end, since "add this text" still has a sensible landing spot.edit_lines/delete_lineserror and leave the page untouched, since "replace/delete this line" has no fallbackCOSENSE_PROJECT_ALLOW_LISTis checked in every handler, right after the project name is resolved, viacheckProjectAllowed()insrc/utils/project.ts. Handlers are the only point shared by the MCP dispatcher, the CLI, and direct calls, so a check in the dispatcher alone would miss the other two. The helper returns an error message instead of throwing because four handlers resolve the project name outside theirtry.src/__tests__/handlers/project-allow-list.test.tsenumerates every handler file, so adding a tool without the check fails the test- The implicit allowance of the default project reads
process.env.COSENSE_PROJECT_NAME, not the handler'sdefaultProjectNameargument. The CLI passes--project=NAMEasdefaultProjectNametoo, so comparing against the argument would let every CLI call through - An allow list that is set but empty (
"",",,,") restricts to the default project rather than falling back to unrestricted. Whoever set the variable meant to restrict, and only an unset variable means "no fence" patch()returnsResult<string, PushError>, not throw. Must checkresult.okuseris the page's creator andlastUpdateUserits last editor (as@cosense/typesdefines them). Every output builds the creator/editor lines throughformatEditorLinesinsrc/utils/format.ts, which omits a line when the name is unknown instead of printingundefined- Default sort is
updated. Aligned across API, display, and user expectations - Keep the request count low; Cosense is a free API, not ours to load.
list_pagesand the startup resource list use the page-list API as is and never fetch each page (that used to send 100–1000+ concurrent requests per call). Page reads use/api/pages/v2/, which returns the same body as v1 minusrelatedPages— unused here, and most of v1's payload (364 KB against 13.7 KB for villagepump's 井戸端). Creator and editor names come from the project member list (/api/projects/:project/users, cached per process for 5 minutes, failures included), because the page and page-list APIs return user IDs only since January 2026;get_pagetherefore costs one extra request only when the cache is cold, and--compactoutputs never look names up. The E2E tests run only withCOSENSE_E2E=true, because running them whenever credentials sit in the shell hit the Smart Context rate limit (429) during development
Environment Variables
See README.md. Key variables:
COSENSE_PROJECT_NAME— Target project (required)COSENSE_SID— Session ID for private projects and write operationsCOSENSE_TOOL_SUFFIX— Tool name suffix for multiple server instancesCOSENSE_CONVERT_NUMBERED_LISTS— Convert numbered lists to bullet listsCOSENSE_ENABLE_DELETE— Registerdelete_page/rewrite_pageand thedelete/rewriteCLI commands (opt-in)COSENSE_PROJECT_ALLOW_LIST— Comma-separated projects thatprojectName/--projectmay target.COSENSE_PROJECT_NAMEis always allowed. Unset = unrestricted; set but empty = default project only (opt-in)
CI/CD & Release
GitHub Actions
- pr.yml — Quality check on PRs (lint → test → build)
- security-scan.yml — Security scan
- auto-release.yml —
release/v*PR merge → auto-create tag + GitHub Release - publish-npm.yml —
v*tag push → auto-publish to npm - release-mcpb.yml — GitHub Release → auto-build and attach .mcpb
Release Process
- Create
release/vX.Y.Zbranch, bump version inpackage.json+manifest.json+.claude-plugin/plugin.json- Note: the MCP
serverInfo.versionis read frompackage.jsonat runtime, so no separate bump is needed forsrc/index.ts
- Note: the MCP
- Create PR → CI passes → merge
- Everything after merge is automatic (tag → npm → GitHub Release → .mcpb)
TypeScript
- Strict mode: includes
exactOptionalPropertyTypes: true - Path aliases:
@/→src/(configured in both TypeScript and Jest; runtime uses relative paths) - ESM: imports use
.jsextensions - Dual config:
tsconfig.json(dev) andtsconfig.build.json(prod, excludes tests)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

