Skip to main content
Glama
Scrapbox Cosense MCP Server

Scrapbox Cosense MCP Server

scrapbox-cosense-mcp

日本語ドキュメント / Japanese

概述

面向 Cosense(原 Scrapbox) 的 MCP 服务器。

工具

描述

需要认证

get_page

获取页面内容、元数据和链接

私有项目需要

list_pages

分页浏览页面,支持排序和分页(最多 1000)

私有项目需要

search_pages

全文搜索,带关键词高亮(最多 100 条结果)

私有项目需要

create_page

通过 WebSocket API 创建页面,支持 Markdown/Scrapbox 正文

是

get_page_url

生成页面的直接 URL

否

insert_lines

在页面指定行后插入文本

是

edit_lines

替换精确匹配的行,包括多行块(首个匹配,或通过 matchAll 全部匹配)

是

delete_lines

删除精确匹配的行,包括多行块(首个匹配,或通过 matchAll 全部匹配)

是

delete_page

通过清空所有行删除页面——可选启用,见下文

是

rewrite_page

替换页面全部内容——可选启用,见下文

是

get_smart_context

以 AI 优化格式获取页面及其链接页面(1跳/2跳)

是

create_page、insert_lines、edit_lines 和 rewrite_page 支持 format 参数("markdown" 或 "scrapbox")来控制内容转换。

edit_lines 默认只替换第一个匹配的行。设置 matchAll: true 可替换所有匹配项。这个默认行为是刻意保守的:类似项目符号或空行这样的行在页面中可能重复多次,而一次性全部替换很少是调用者的本意。

targetLineText 可以包含换行符以匹配连续的多行块。该块作为一个整体被替换,因此 n 行可以变成 m 行(例如,将多行合并为一行)。使用 matchAll: true 时,块匹配不重叠。

delete_lines 使用相同的精确匹配(及块)语义,但删除匹配的行而不是替换它们。它拒绝删除标题行(第一行),因为那会重命名或移除页面本身——请使用 delete_page 来执行该操作。

delete_page 和 rewrite_page 可选启用

delete_page 和 rewrite_page 只有在设置 COSENSE_ENABLE_DELETE=true 时才会注册。没有该设置,这两个工具根本不会出现在工具列表中,因此代理即使误操作也无法调用它们。此服务器经常被添加到共享的 MCP 配置中,因此整页销毁仅对故意启用它的人开放。

理由:insert_lines、edit_lines 和 delete_lines 都要求精确匹配,这只有在调用者确实读过页面时才可能实现——它们只能删除调用者已知的行。而 delete_page 和 rewrite_page 无论调用者是否读过页面都会作用于整个页面,因此它们需要单独的启用开关。

delete_page 会清空页面的所有行,而 Cosense 会在页面的所有行为空后删除该页面。此操作无法撤销。还内置了两道额外保护:

  • 页面必须已存在。页面不存在时返回错误,而非静默成功。(REST API 即使对从未创建的页面也会返回标题行,因此检查会像 create_page 一样查看 persistent。)

  • dryRun: true 会报告将删除多少行,并显示前五行,且不会改动页面。

rewrite_page 替换页面的全部内容(标题保留为第一行)。它拥有相同的保护,还有两项额外的保护:

  • 页面必须已存在——persistent 检查与 create_page 相反,因此拼写错误不会静默创建新页面。

  • 拒绝空内容——删除页面是 delete_page 的职责。

  • dryRun: true 会报告前后行数并预览,且不会改动页面。

当你为不同项目运行此服务器的多个实例时,请在允许删除的每个实例上设置该变量:

{
  "mcpServers": {
    "cosense-notes": {
      "command": "npx",
      "args": ["-y", "scrapbox-cosense-mcp"],
      "env": {
        "COSENSE_PROJECT_NAME": "notes",
        "COSENSE_SID": "s:your-session-id",
        "COSENSE_TOOL_SUFFIX": "notes",
        "COSENSE_ENABLE_DELETE": "true"
      }
    },
    "cosense-archive": {
      "command": "npx",
      "args": ["-y", "scrapbox-cosense-mcp"],
      "env": {
        "COSENSE_PROJECT_NAME": "archive",
        "COSENSE_SID": "s:your-session-id",
        "COSENSE_TOOL_SUFFIX": "archive"
      }
    }
  }
}

这里,notes 实例暴露了 delete_page_notes,而 archive 实例不暴露任何删除工具。

请注意,当目标行不存在时,insert_lines 和 edit_lines 的行为不同。insert_lines 会追加到页面末尾,因为“把这段文本加到某处”仍然有合理的结果。edit_lines 会返回错误并保持页面不变,因为“替换这一特定行”没有有意义的回退——追加替换文本会静默生成一个调用者从未要求的页面。

Related MCP server: scrapbox-cosense-mcp-editable

快速开始

桌面扩展(.mcpb)— 最简单

  1. 从 GitHub Releases 下载 scrapbox-cosense-mcp.mcpb

  2. 双击——Claude Desktop 会打开安装对话框

  3. 输入你的项目名(私有项目还需要会话 ID)

Claude Code 插件

  1. 添加 marketplace:

    /plugin marketplace add worldnine/scrapbox-cosense-mcp
  2. 安装插件:

    /plugin install scrapbox-cosense@worldnine-scrapbox-cosense-mcp

    默认全局安装。如需其他范围,请使用 --scope project 或 --scope local。

  3. 在设置文件中设置环境变量:

    {
      "env": {
        "COSENSE_PROJECT_NAME": "your_project_name",
        "COSENSE_SID": "your_sid"
      }
    }

    文件

    范围

    ~/.claude/settings.json

    所有项目(全局)

    .claude/settings.local.json

    仅当前项目(git 已忽略)

该插件包含 MCP 服务器配置,以及用于 CLI 操作的 /cosense 技能。

Claude Code(手动 MCP 设置)

如果你更倾向于手动配置而不是使用插件:

claude mcp add scrapbox-cosense-mcp \
  -e COSENSE_PROJECT_NAME=your_project \
  -e COSENSE_SID=your_sid \
  -- npx -y scrapbox-cosense-mcp

Claude Desktop / 其他 MCP 客户端

添加到你的配置文件:

客户端

配置文件

Claude Desktop (macOS)

~/Library/Application Support/Claude/claude_desktop_config.json

Claude Desktop (Windows)

%APPDATA%/Claude/claude_desktop_config.json

Cursor

.cursor/mcp.json(项目根目录)

Windsurf

~/.codeium/windsurf/mcp_config.json

{
  "mcpServers": {
    "scrapbox-cosense-mcp": {
      "command": "npx",
      "args": ["-y", "scrapbox-cosense-mcp"],
      "env": {
        "COSENSE_PROJECT_NAME": "your_project_name",
        "COSENSE_SID": "your_sid"
      }
    }
  }
}

从源码构建

git clone https://github.com/worldnine/scrapbox-cosense-mcp.git
cd scrapbox-cosense-mcp
npm install && npm run build

配置

必需

变量

描述

COSENSE_PROJECT_NAME

你的 Scrapbox/Cosense 项目名

COSENSE_SID

私有项目的会话 ID(connect.sid cookie)— 如何获取

可选

变量

默认值

描述

API_DOMAIN

scrapbox.io

API 域名

SERVICE_LABEL

cosense (scrapbox)

工具描述中的显示名称

COSENSE_PAGE_LIMIT

100

初始页面获取限制(1–1000)

COSENSE_SORT_METHOD

updated

初始排序:updated、created、accessed、linked、views、title

COSENSE_TOOL_SUFFIX

—

多实例时的工具名后缀(例如 main → get_page_main)

COSENSE_CONVERT_NUMBERED_LISTS

false

在 Markdown 转换中将编号列表转换为项目符号列表

COSENSE_EXCLUDE_PINNED

false

从初始资源列表中排除固定页面

COSENSE_ENABLE_DELETE

false

注册 delete_page 和 rewrite_page 工具(以及 delete / rewrite CLI 命令)。未设置时,这些均不可用

CLI 用法

同一个二进制文件也可以作为独立的 CLI 使用:

scrapbox-cosense-mcp get "Page Title"
scrapbox-cosense-mcp search "keyword"
scrapbox-cosense-mcp list --sort=updated --limit=20
scrapbox-cosense-mcp create "New Page" --body="Markdown content"
scrapbox-cosense-mcp insert "Page" --after="target line" --text="new text"
scrapbox-cosense-mcp edit "Page" --target="old line" --text="new text"
scrapbox-cosense-mcp delete-lines "Page" --target="old line"
scrapbox-cosense-mcp delete "Page" --dry-run   # needs COSENSE_ENABLE_DELETE=true
scrapbox-cosense-mcp rewrite "Page" --body="new content" --dry-run   # needs COSENSE_ENABLE_DELETE=true
scrapbox-cosense-mcp url "Page Title"

标志

描述

--compact

节省 token 的紧凑输出(推荐用于 AI 代理)

--project=NAME

覆盖项目名

--json

以 JSON 格式输出

--help

显示帮助(支持 <command> --help 查看详情)

多项目

所有工具都接受可选的 projectName 参数,以便从单个服务器指向不同的项目。对于使用不同凭据的多个私有项目,请使用 COSENSE_TOOL_SUFFIX 运行独立的服务器实例。

有关详细的配置示例,请参阅 docs/multiple-projects.md。

开发

命令

描述

npm run build

构建(TypeScript → JavaScript)

npm run watch

开发期间自动重新构建

npm test

运行测试套件

npm run lint

运行 ESLint

npm run inspector

使用 MCP Inspector 调试

贡献

  1. 从 main 创建功能分支

  2. 为你的更改添加测试

  3. 运行 npm run lint && npm test

  4. 创建拉取请求——CI 会自动运行

许可证

MIT


Available Tools

9 tools
create_pageB

Create a new page in Scrapbox project on cosense (scrapbox). Creates a new page with the specified title and optional body text. Returns the page creation URL without opening browser. Uses my-cosense-project project as default if projectName is not specified.

Inputs: title (required), body, format, projectName, +1 more.

delete_linesA

Delete one or more lines from a Scrapbox page on cosense (scrapbox). Matches the target by exact text. If targetLineText contains newline characters, it is matched as a contiguous block of lines and removed as a whole. By default only the first match is removed; set matchAll to remove every (non-overlapping) occurrence. Refuses to delete the title line (the first line), which would rename or remove the page — use delete_page for that. Returns an error if no match is found. Requires COSENSE_MCP_PAT or COSENSE_SID. Uses my-cosense-project project as default if projectName is not specified.

Inputs: pageTitle (required), targetLineText (required), matchAll, projectName.

edit_linesA

Replace one or more lines in a Scrapbox page on cosense (scrapbox). Matches the target by exact text and substitutes it with new content (which may span multiple lines). If targetLineText contains newline characters, it is matched as a contiguous block of lines, so any n lines can be replaced with m lines. By default only the first match is replaced; set matchAll to replace every (non-overlapping) occurrence. Returns an error if no match is found. Requires COSENSE_MCP_PAT or COSENSE_SID. Uses my-cosense-project project as default if projectName is not specified.

Inputs: newText (required), pageTitle (required), targetLineText (required), format, +2 more.

get_pageB

Get a page from Scrapbox project on cosense (scrapbox). Returns page content and its linked pages. Page content includes title and description in plain text format. Uses my-cosense-project project as default if projectName is not specified.

Inputs: pageTitle (required), projectName.

get_page_urlA

Generate URL for a page in Scrapbox project on cosense (scrapbox). Returns the direct URL to the specified page without opening it in browser. Uses my-cosense-project project as default if projectName is not specified.

Inputs: title (required), projectName.

get_smart_contextA

Get smart context for a page on cosense (scrapbox). Returns the target page and its linked pages (1-hop or 2-hop) with full content in AI-optimized format. Useful for understanding the context and related knowledge around a specific topic. Requires COSENSE_MCP_PAT or COSENSE_SID. Uses my-cosense-project project as default if projectName is not specified.

Inputs: title (required), hopCount, projectName.

insert_linesA

Insert text after a specified line in a Scrapbox page on cosense (scrapbox). If target line not found, text is appended to the end of the page. Uses my-cosense-project project as default if projectName is not specified.

Inputs: text (required), pageTitle (required), targetLineText (required), format, +1 more.

list_pagesA

Browse and list pages from Scrapbox project on cosense (scrapbox) with flexible sorting and pagination. Use this tool to discover pages by recency, popularity, or alphabetically. Returns page metadata and first 5 lines of content. Available sorting methods: updated (last update time), created (creation time), accessed (access time), linked (number of incoming links), views (view count), title (alphabetical). Different from search_pages which finds content by keywords. Uses my-cosense-project project as default if projectName is not specified.

Inputs: skip, sort, limit, projectName, +1 more.

search_pagesA

Search for content within pages in Scrapbox project on cosense (scrapbox). Use this tool to find pages containing specific keywords or phrases. Returns matching pages with highlighted search terms and content snippets. Limited to 100 results maximum. Supports basic search ("keyword"), multiple keywords ("word1 word2" for AND search), exclude words ("word1 -word2"), and exact phrases (""exact phrase""). Different from list_pages which browses pages by metadata. Uses my-cosense-project project as default if projectName is not specified.

Inputs: query (required), projectName.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 9 tools

    Disambiguation4/5

    Most tools target distinct operations (URL, create, edit, delete, insert, list, search). However, get_page and get_smart_context overlap notably since both return page content plus linked pages, differing mainly in formatting and hop depth, which could cause misselection.

    Naming Consistency5/5

    All tools follow a consistent snake_case verb_noun pattern (get_page_url, get_smart_context, create_page, edit_lines, delete_lines, get_page, insert_lines, list_pages, search_pages). No mixed conventions or vague verbs.

    Tool Count5/5

    Nine tools is well-scoped for a note-taking/wiki server, with each tool earning its place across read, write, discovery, and navigation operations.

    Completeness3/5

    The surface covers create, read, line-level edit/insert/delete, list, and search, but lacks a page-level delete or rename tool—ironically delete_lines explicitly references a delete_page tool that is not present, creating a dead end for removing or renaming whole pages.

    Maintenance

    ActivityActive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server for Wiki.js projects that enables full-text search, page retrieval, and page management capabilities. It allows LLMs to interact with wiki content through specialized tools for searching, listing, and creating pages.
      ISC
    • A
      license
      Not graded
      quality
      C
      maintenance
      MCP server for Cosense (formerly Scrapbox) that enables page creation, editing, deletion, and searching with WebSocket-based operations. Extends the original server with page-deletion and line-editing tools.
      2 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Read-only MCP server for the Cosense project 'shiyui' that provides tools for fetching pages, full-text search, vector search, and related page retrieval. It uses Cloudflare Access OAuth for authentication.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A stateless Remote MCP server on Cloudflare Workers for operating a single Cosense (formerly Scrapbox) project. It enables page retrieval, listing, full-text search, and line insertion via natural language, protected by Cloudflare Access Managed OAuth and JWT validation.
      MIT