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-hop/2-hop)を取得します

はい

create_page、insert_lines、edit_lines、rewrite_page は、コンテンツ変換を制御する format パラメータ("markdown" または "scrapbox")をサポートしています。

edit_lines はデフォルトでは最初に一致した行のみを置換します。すべての出現箇所を置換するには matchAll: true を設定します。デフォルトは意図的に慎重になっています。箇条書きマーカーや空行などの行はページ内で何度も繰り返される可能性があり、一度にすべてを置換することは呼び出し側の意図と一致しないことがほとんどだからです。

targetLineText は改行を含めて連続する複数行のブロックに一致させることができます。ブロックは全体として置換されるため、n 行を m 行にできます(例: 複数行を1行にまとめる)。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 はすべての行が空になるとページを削除します。元に戻すことはできません。さらに2つのガードが組み込まれています:

  • ページが存在している必要があります。存在しないページは、黙って成功するのではなくエラーを返します。(REST API は作成されていないページでもタイトル行を返すため、create_page と同じ方法で persistent を確認します。)

  • dryRun: true は、削除される行数と最初の5行を表示しますが、ページには触れません。

rewrite_page はページの全コンテンツを置き換えます(タイトルは最初の行として保持されます)。同じガードに加えて、独自のガードが2つあります:

  • ページが存在している必要があります — 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. マーケットプレイスを追加:

    /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

    このプロジェクトのみ(gitignore 対象)

プラグインには 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 クッキー)— 取得方法

オプション

変数

デフォルト

説明

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

トークン効率の良いコンパクトな出力(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