@atikk-co-jp/notion-mcp-server 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.ja.md +95 -4
  2. package/README.md +95 -4
  3. package/dist/bin/cli.js +10 -10
  4. package/dist/src/converters/__tests__/block-to-markdown.test.d.ts +2 -0
  5. package/dist/src/converters/__tests__/block-to-markdown.test.d.ts.map +1 -0
  6. package/dist/src/converters/__tests__/block-to-markdown.test.js +611 -0
  7. package/dist/src/converters/__tests__/page-to-markdown.test.d.ts +2 -0
  8. package/dist/src/converters/__tests__/page-to-markdown.test.d.ts.map +1 -0
  9. package/dist/src/converters/__tests__/page-to-markdown.test.js +567 -0
  10. package/dist/src/converters/__tests__/rich-text-to-markdown.test.d.ts +2 -0
  11. package/dist/src/converters/__tests__/rich-text-to-markdown.test.d.ts.map +1 -0
  12. package/dist/src/converters/__tests__/rich-text-to-markdown.test.js +353 -0
  13. package/dist/src/converters/block-to-markdown.d.ts +38 -0
  14. package/dist/src/converters/block-to-markdown.d.ts.map +1 -0
  15. package/dist/src/converters/block-to-markdown.js +484 -0
  16. package/dist/src/converters/index.d.ts +9 -0
  17. package/dist/src/converters/index.d.ts.map +1 -0
  18. package/dist/src/converters/index.js +11 -0
  19. package/dist/src/converters/page-to-markdown.d.ts +64 -0
  20. package/dist/src/converters/page-to-markdown.d.ts.map +1 -0
  21. package/dist/src/converters/page-to-markdown.js +189 -0
  22. package/dist/src/converters/rich-text-to-markdown.d.ts +61 -0
  23. package/dist/src/converters/rich-text-to-markdown.d.ts.map +1 -0
  24. package/dist/src/converters/rich-text-to-markdown.js +95 -0
  25. package/dist/src/index.d.ts +6 -6
  26. package/dist/src/index.d.ts.map +1 -1
  27. package/dist/src/index.js +5 -5
  28. package/dist/src/notion-client.d.ts +58 -15
  29. package/dist/src/notion-client.d.ts.map +1 -1
  30. package/dist/src/notion-client.js +23 -13
  31. package/dist/src/schemas/block.d.ts +2158 -622
  32. package/dist/src/schemas/block.d.ts.map +1 -1
  33. package/dist/src/schemas/block.js +283 -76
  34. package/dist/src/schemas/common.d.ts +518 -6
  35. package/dist/src/schemas/common.d.ts.map +1 -1
  36. package/dist/src/schemas/common.js +120 -42
  37. package/dist/src/schemas/database.d.ts +687 -0
  38. package/dist/src/schemas/database.d.ts.map +1 -0
  39. package/dist/src/schemas/database.js +264 -0
  40. package/dist/src/schemas/filter.d.ts +509 -3
  41. package/dist/src/schemas/filter.d.ts.map +1 -1
  42. package/dist/src/schemas/filter.js +110 -13
  43. package/dist/src/schemas/index.d.ts +5 -4
  44. package/dist/src/schemas/index.d.ts.map +1 -1
  45. package/dist/src/schemas/index.js +7 -5
  46. package/dist/src/schemas/page.d.ts +2152 -19
  47. package/dist/src/schemas/page.d.ts.map +1 -1
  48. package/dist/src/schemas/page.js +216 -22
  49. package/dist/src/schemas/schemas.test.d.ts +2 -0
  50. package/dist/src/schemas/schemas.test.d.ts.map +1 -0
  51. package/dist/src/schemas/schemas.test.js +418 -0
  52. package/dist/src/server.d.ts +2 -2
  53. package/dist/src/server.d.ts.map +1 -1
  54. package/dist/src/server.js +6 -6
  55. package/dist/src/tools/append-block-children.d.ts +2 -2
  56. package/dist/src/tools/append-block-children.d.ts.map +1 -1
  57. package/dist/src/tools/append-block-children.js +16 -10
  58. package/dist/src/tools/create-comment.d.ts +2 -2
  59. package/dist/src/tools/create-comment.d.ts.map +1 -1
  60. package/dist/src/tools/create-comment.js +15 -9
  61. package/dist/src/tools/create-database.d.ts +4 -0
  62. package/dist/src/tools/create-database.d.ts.map +1 -0
  63. package/dist/src/tools/create-database.js +57 -0
  64. package/dist/src/tools/create-page.d.ts +2 -2
  65. package/dist/src/tools/create-page.d.ts.map +1 -1
  66. package/dist/src/tools/create-page.js +22 -24
  67. package/dist/src/tools/get-block-children.d.ts +2 -2
  68. package/dist/src/tools/get-block-children.d.ts.map +1 -1
  69. package/dist/src/tools/get-block-children.js +39 -6
  70. package/dist/src/tools/index.d.ts +13 -11
  71. package/dist/src/tools/index.d.ts.map +1 -1
  72. package/dist/src/tools/index.js +13 -9
  73. package/dist/src/tools/query-database.d.ts +2 -2
  74. package/dist/src/tools/query-database.d.ts.map +1 -1
  75. package/dist/src/tools/query-database.js +27 -18
  76. package/dist/src/tools/retrieve-page.d.ts +2 -2
  77. package/dist/src/tools/retrieve-page.d.ts.map +1 -1
  78. package/dist/src/tools/retrieve-page.js +44 -4
  79. package/dist/src/tools/search.d.ts +2 -2
  80. package/dist/src/tools/search.d.ts.map +1 -1
  81. package/dist/src/tools/search.js +18 -12
  82. package/dist/src/tools/update-database.d.ts +4 -0
  83. package/dist/src/tools/update-database.d.ts.map +1 -0
  84. package/dist/src/tools/update-database.js +74 -0
  85. package/dist/src/tools/update-page.d.ts +2 -2
  86. package/dist/src/tools/update-page.d.ts.map +1 -1
  87. package/dist/src/tools/update-page.js +23 -18
  88. package/dist/src/utils/error-handler.d.ts +1 -1
  89. package/dist/src/utils/error-handler.d.ts.map +1 -1
  90. package/dist/src/utils/error-handler.js +14 -14
  91. package/dist/src/utils/index.d.ts +2 -2
  92. package/dist/src/utils/index.d.ts.map +1 -1
  93. package/dist/src/utils/index.js +2 -2
  94. package/dist/src/utils/response-formatter.d.ts +13 -1
  95. package/dist/src/utils/response-formatter.d.ts.map +1 -1
  96. package/dist/src/utils/response-formatter.js +46 -3
  97. package/package.json +11 -2
package/README.ja.md CHANGED
@@ -9,10 +9,11 @@ Notion API用のMCP(Model Context Protocol)サーバー。AIアシスタン
9
9
  ## 特徴
10
10
 
11
11
  - **ページ操作**: Notionページの作成、取得、更新
12
- - **データベースクエリ**: フィルターやソートを使ったデータベース検索
12
+ - **データベース操作**: データベースの作成、更新、フィルター/ソートを使ったクエリ
13
13
  - **ブロック操作**: ブロックの子要素の取得と追加
14
14
  - **検索**: ページとデータベースの横断検索
15
15
  - **コメント**: ページへのコメント追加
16
+ - **トークン効率化**: マークダウン/シンプル形式でトークン使用量を約96%削減
16
17
 
17
18
  ## インストール
18
19
 
@@ -76,9 +77,18 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
76
77
 
77
78
  ページIDでNotionページを取得します。
78
79
 
80
+ **パラメータ:**
81
+ - `page_id` (必須): 取得するページのID
82
+ - `format` (任意): 出力形式 - `"simple"` (デフォルト) または `"json"`
83
+ - `simple`: トークン使用量を削減した簡略化されたプロパティ値を返す
84
+ - `json`: Notion APIのレスポンスをそのまま返す
85
+ - `include_content` (任意): ページコンテンツをマークダウンで含める(デフォルト: true)
86
+
79
87
  ```json
80
88
  {
81
- "page_id": "ページのUUID"
89
+ "page_id": "ページのUUID",
90
+ "format": "simple",
91
+ "include_content": true
82
92
  }
83
93
  ```
84
94
 
@@ -119,6 +129,16 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
119
129
 
120
130
  フィルターやソートを使ってデータベースをクエリします。
121
131
 
132
+ **パラメータ:**
133
+ - `database_id` (必須): クエリするデータベースのID
134
+ - `filter` (任意): フィルター条件(JSONオブジェクト)
135
+ - `sorts` (任意): ソート条件(配列)
136
+ - `start_cursor` (任意): ページネーション用カーソル
137
+ - `page_size` (任意): 返す結果の数 (1-100)
138
+ - `format` (任意): 出力形式 - `"simple"` (デフォルト) または `"json"`
139
+ - `simple`: トークン使用量を削減した簡略化されたプロパティ値を返す
140
+ - `json`: Notion APIのレスポンスをそのまま返す
141
+
122
142
  ```json
123
143
  {
124
144
  "database_id": "データベースのUUID",
@@ -128,7 +148,55 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
128
148
  },
129
149
  "sorts": [
130
150
  { "property": "Created", "direction": "descending" }
131
- ]
151
+ ],
152
+ "format": "simple"
153
+ }
154
+ ```
155
+
156
+ ### create-database
157
+
158
+ 既存のページのサブページとして新しいデータベースを作成します。
159
+
160
+ **パラメータ:**
161
+ - `parent_page_id` (必須): 親ページのID
162
+ - `properties` (必須): 少なくとも1つのtitleプロパティを含むデータベーススキーマ
163
+ - `title` (任意): データベースタイトル(リッチテキスト配列)
164
+ - `icon` (任意): データベースのアイコン
165
+ - `cover` (任意): データベースのカバー画像
166
+ - `is_inline` (任意): trueの場合、インラインデータベースとして作成
167
+
168
+ ```json
169
+ {
170
+ "parent_page_id": "親ページのUUID",
171
+ "properties": {
172
+ "Name": { "title": {} },
173
+ "Status": { "select": { "options": [{ "name": "未着手" }, { "name": "完了" }] } },
174
+ "Priority": { "number": {} }
175
+ },
176
+ "title": [{ "type": "text", "text": { "content": "タスクデータベース" } }]
177
+ }
178
+ ```
179
+
180
+ ### update-database
181
+
182
+ 既存のデータベースのプロパティ、タイトル、スキーマを更新します。
183
+
184
+ **パラメータ:**
185
+ - `database_id` (必須): 更新するデータベースのID
186
+ - `title` (任意): 新しいタイトル(リッチテキスト配列)
187
+ - `description` (任意): 新しい説明(リッチテキスト配列)
188
+ - `properties` (任意): 追加、更新、削除するプロパティ(nullで削除)
189
+ - `icon` (任意): アイコン(nullで削除)
190
+ - `cover` (任意): カバー画像(nullで削除)
191
+ - `archived` (任意): trueでアーカイブ
192
+
193
+ ```json
194
+ {
195
+ "database_id": "データベースのUUID",
196
+ "properties": {
197
+ "NewColumn": { "rich_text": {} },
198
+ "OldColumn": null
199
+ }
132
200
  }
133
201
  ```
134
202
 
@@ -147,9 +215,20 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
147
215
 
148
216
  ページまたはブロックの子ブロックを取得します。
149
217
 
218
+ **パラメータ:**
219
+ - `block_id` (必須): 子ブロックを取得するブロックまたはページのID
220
+ - `start_cursor` (任意): ページネーション用カーソル
221
+ - `page_size` (任意): 返す結果の数 (1-100)
222
+ - `format` (任意): 出力形式 - `"markdown"` (デフォルト) または `"json"`
223
+ - `markdown`: トークン使用量を大幅に削減(約96%削減)した人間が読みやすいマークダウン形式
224
+ - `json`: Notion APIのレスポンスをそのまま返す
225
+ - `fetch_nested` (任意): `format="markdown"`の時、ネストされた子ブロックを再帰的に取得する(デフォルト: false)
226
+
150
227
  ```json
151
228
  {
152
- "block_id": "ページまたはブロックのUUID"
229
+ "block_id": "ページまたはブロックのUUID",
230
+ "format": "markdown",
231
+ "fetch_nested": true
153
232
  }
154
233
  ```
155
234
 
@@ -196,6 +275,18 @@ pnpm build
196
275
 
197
276
  # 型チェック
198
277
  pnpm typecheck
278
+
279
+ # リント
280
+ pnpm lint
281
+
282
+ # コードフォーマット
283
+ pnpm format
284
+
285
+ # テスト実行
286
+ pnpm test
287
+
288
+ # ウォッチモードでテスト実行
289
+ pnpm test:watch
199
290
  ```
200
291
 
201
292
  ## ライセンス
package/README.md CHANGED
@@ -9,10 +9,11 @@ MCP (Model Context Protocol) server for Notion API. Enables AI assistants to int
9
9
  ## Features
10
10
 
11
11
  - **Page Operations**: Create, retrieve, and update Notion pages
12
- - **Database Queries**: Query databases with filters and sorts
12
+ - **Database Operations**: Create, update, and query databases with filters and sorts
13
13
  - **Block Operations**: Get and append block children
14
14
  - **Search**: Search across pages and databases
15
15
  - **Comments**: Add comments to pages
16
+ - **Token-Efficient Output**: Markdown/simple format reduces token usage by ~96%
16
17
 
17
18
  ## Installation
18
19
 
@@ -76,9 +77,18 @@ Add to your `.mcp.json`:
76
77
 
77
78
  Retrieve a Notion page by its ID.
78
79
 
80
+ **Parameters:**
81
+ - `page_id` (required): The ID of the page to retrieve
82
+ - `format` (optional): Output format - `"simple"` (default) or `"json"`
83
+ - `simple`: Returns simplified property values with reduced token usage
84
+ - `json`: Returns raw Notion API response
85
+ - `include_content` (optional): Include page content as markdown (default: true)
86
+
79
87
  ```json
80
88
  {
81
- "page_id": "page-uuid-here"
89
+ "page_id": "page-uuid-here",
90
+ "format": "simple",
91
+ "include_content": true
82
92
  }
83
93
  ```
84
94
 
@@ -119,6 +129,16 @@ Update a page's properties.
119
129
 
120
130
  Query a database with optional filters and sorts.
121
131
 
132
+ **Parameters:**
133
+ - `database_id` (required): The ID of the database to query
134
+ - `filter` (optional): Filter conditions as a JSON object
135
+ - `sorts` (optional): Sort conditions as an array
136
+ - `start_cursor` (optional): Cursor for pagination
137
+ - `page_size` (optional): Number of results to return (1-100)
138
+ - `format` (optional): Output format - `"simple"` (default) or `"json"`
139
+ - `simple`: Returns simplified property values with reduced token usage
140
+ - `json`: Returns raw Notion API response
141
+
122
142
  ```json
123
143
  {
124
144
  "database_id": "database-uuid-here",
@@ -128,7 +148,55 @@ Query a database with optional filters and sorts.
128
148
  },
129
149
  "sorts": [
130
150
  { "property": "Created", "direction": "descending" }
131
- ]
151
+ ],
152
+ "format": "simple"
153
+ }
154
+ ```
155
+
156
+ ### create-database
157
+
158
+ Create a new database as a subpage of an existing page.
159
+
160
+ **Parameters:**
161
+ - `parent_page_id` (required): The ID of the parent page
162
+ - `properties` (required): Database schema with at least one title property
163
+ - `title` (optional): Database title as rich text array
164
+ - `icon` (optional): Icon for the database
165
+ - `cover` (optional): Cover image for the database
166
+ - `is_inline` (optional): If true, creates an inline database
167
+
168
+ ```json
169
+ {
170
+ "parent_page_id": "parent-page-uuid",
171
+ "properties": {
172
+ "Name": { "title": {} },
173
+ "Status": { "select": { "options": [{ "name": "Todo" }, { "name": "Done" }] } },
174
+ "Priority": { "number": {} }
175
+ },
176
+ "title": [{ "type": "text", "text": { "content": "Task Database" } }]
177
+ }
178
+ ```
179
+
180
+ ### update-database
181
+
182
+ Update an existing database's properties, title, or schema.
183
+
184
+ **Parameters:**
185
+ - `database_id` (required): The ID of the database to update
186
+ - `title` (optional): New title as rich text array
187
+ - `description` (optional): New description as rich text array
188
+ - `properties` (optional): Properties to add, update, or delete (set to null)
189
+ - `icon` (optional): Icon (set to null to remove)
190
+ - `cover` (optional): Cover image (set to null to remove)
191
+ - `archived` (optional): Set to true to archive
192
+
193
+ ```json
194
+ {
195
+ "database_id": "database-uuid-here",
196
+ "properties": {
197
+ "NewColumn": { "rich_text": {} },
198
+ "OldColumn": null
199
+ }
132
200
  }
133
201
  ```
134
202
 
@@ -147,9 +215,20 @@ Search across all pages and databases.
147
215
 
148
216
  Get the child blocks of a page or block.
149
217
 
218
+ **Parameters:**
219
+ - `block_id` (required): The ID of the block or page to get children from
220
+ - `start_cursor` (optional): Cursor for pagination
221
+ - `page_size` (optional): Number of results to return (1-100)
222
+ - `format` (optional): Output format - `"markdown"` (default) or `"json"`
223
+ - `markdown`: Returns human-readable markdown with significantly reduced token usage (~96% reduction)
224
+ - `json`: Returns raw Notion API response
225
+ - `fetch_nested` (optional): When `format="markdown"`, fetch nested children blocks recursively (default: false)
226
+
150
227
  ```json
151
228
  {
152
- "block_id": "page-or-block-uuid-here"
229
+ "block_id": "page-or-block-uuid-here",
230
+ "format": "markdown",
231
+ "fetch_nested": true
153
232
  }
154
233
  ```
155
234
 
@@ -196,6 +275,18 @@ pnpm build
196
275
 
197
276
  # Type check
198
277
  pnpm typecheck
278
+
279
+ # Lint
280
+ pnpm lint
281
+
282
+ # Format code
283
+ pnpm format
284
+
285
+ # Run tests
286
+ pnpm test
287
+
288
+ # Run tests in watch mode
289
+ pnpm test:watch
199
290
  ```
200
291
 
201
292
  ## License
package/dist/bin/cli.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { startServer } from "../src/server.js";
2
+ import { startServer } from '../src/server.js';
3
3
  async function main() {
4
4
  // Validate environment
5
5
  if (!process.env.NOTION_TOKEN) {
6
- console.error("Error: NOTION_TOKEN environment variable is required.");
7
- console.error("");
8
- console.error("To fix this:");
9
- console.error("1. Create a Notion integration at https://www.notion.so/my-integrations");
10
- console.error("2. Copy the Internal Integration Token");
11
- console.error("3. Set it as NOTION_TOKEN environment variable");
12
- console.error("");
13
- console.error("Example:");
6
+ console.error('Error: NOTION_TOKEN environment variable is required.');
7
+ console.error('');
8
+ console.error('To fix this:');
9
+ console.error('1. Create a Notion integration at https://www.notion.so/my-integrations');
10
+ console.error('2. Copy the Internal Integration Token');
11
+ console.error('3. Set it as NOTION_TOKEN environment variable');
12
+ console.error('');
13
+ console.error('Example:');
14
14
  console.error(' NOTION_TOKEN="ntn_xxx..." npx notion-mcp-server');
15
15
  process.exit(1);
16
16
  }
@@ -18,7 +18,7 @@ async function main() {
18
18
  await startServer();
19
19
  }
20
20
  catch (error) {
21
- console.error("Failed to start server:", error);
21
+ console.error('Failed to start server:', error);
22
22
  process.exit(1);
23
23
  }
24
24
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=block-to-markdown.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-to-markdown.test.d.ts","sourceRoot":"","sources":["../../../../src/converters/__tests__/block-to-markdown.test.ts"],"names":[],"mappings":""}