@atikk-co-jp/notion-mcp-server 0.1.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.
- package/LICENSE +21 -0
- package/README.ja.md +203 -0
- package/README.md +203 -0
- package/dist/bin/cli.d.ts +3 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +25 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/notion-client.d.ts +82 -0
- package/dist/src/notion-client.d.ts.map +1 -0
- package/dist/src/notion-client.js +93 -0
- package/dist/src/schemas/block.d.ts +2250 -0
- package/dist/src/schemas/block.d.ts.map +1 -0
- package/dist/src/schemas/block.js +195 -0
- package/dist/src/schemas/common.d.ts +126 -0
- package/dist/src/schemas/common.d.ts.map +1 -0
- package/dist/src/schemas/common.js +85 -0
- package/dist/src/schemas/filter.d.ts +105 -0
- package/dist/src/schemas/filter.d.ts.map +1 -0
- package/dist/src/schemas/filter.js +125 -0
- package/dist/src/schemas/index.d.ts +5 -0
- package/dist/src/schemas/index.d.ts.map +1 -0
- package/dist/src/schemas/index.js +8 -0
- package/dist/src/schemas/page.d.ts +474 -0
- package/dist/src/schemas/page.d.ts.map +1 -0
- package/dist/src/schemas/page.js +134 -0
- package/dist/src/server.d.ts +5 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +16 -0
- package/dist/src/tools/append-block-children.d.ts +4 -0
- package/dist/src/tools/append-block-children.d.ts.map +1 -0
- package/dist/src/tools/append-block-children.js +32 -0
- package/dist/src/tools/create-comment.d.ts +4 -0
- package/dist/src/tools/create-comment.d.ts.map +1 -0
- package/dist/src/tools/create-comment.js +35 -0
- package/dist/src/tools/create-page.d.ts +4 -0
- package/dist/src/tools/create-page.d.ts.map +1 -0
- package/dist/src/tools/create-page.js +50 -0
- package/dist/src/tools/get-block-children.d.ts +4 -0
- package/dist/src/tools/get-block-children.d.ts.map +1 -0
- package/dist/src/tools/get-block-children.js +30 -0
- package/dist/src/tools/index.d.ts +13 -0
- package/dist/src/tools/index.d.ts.map +1 -0
- package/dist/src/tools/index.js +24 -0
- package/dist/src/tools/query-database.d.ts +4 -0
- package/dist/src/tools/query-database.d.ts.map +1 -0
- package/dist/src/tools/query-database.js +51 -0
- package/dist/src/tools/retrieve-page.d.ts +4 -0
- package/dist/src/tools/retrieve-page.d.ts.map +1 -0
- package/dist/src/tools/retrieve-page.js +16 -0
- package/dist/src/tools/search.d.ts +4 -0
- package/dist/src/tools/search.d.ts.map +1 -0
- package/dist/src/tools/search.js +58 -0
- package/dist/src/tools/update-page.d.ts +4 -0
- package/dist/src/tools/update-page.d.ts.map +1 -0
- package/dist/src/tools/update-page.js +47 -0
- package/dist/src/utils/error-handler.d.ts +11 -0
- package/dist/src/utils/error-handler.d.ts.map +1 -0
- package/dist/src/utils/error-handler.js +64 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/src/utils/response-formatter.d.ts +5 -0
- package/dist/src/utils/response-formatter.d.ts.map +1 -0
- package/dist/src/utils/response-formatter.js +30 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# notion-mcp-server
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 日本語
|
|
4
|
+
|
|
5
|
+
Notion API用のMCP(Model Context Protocol)サーバー。AIアシスタントがNotionのページ、データベース、ブロックを操作できるようにします。
|
|
6
|
+
|
|
7
|
+
> ⚠️ **注意**: これは初期リリースです。APIは変更される可能性があります。
|
|
8
|
+
|
|
9
|
+
## 特徴
|
|
10
|
+
|
|
11
|
+
- **ページ操作**: Notionページの作成、取得、更新
|
|
12
|
+
- **データベースクエリ**: フィルターやソートを使ったデータベース検索
|
|
13
|
+
- **ブロック操作**: ブロックの子要素の取得と追加
|
|
14
|
+
- **検索**: ページとデータベースの横断検索
|
|
15
|
+
- **コメント**: ページへのコメント追加
|
|
16
|
+
|
|
17
|
+
## インストール
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @atikk-co-jp/notion-mcp-server
|
|
21
|
+
# または
|
|
22
|
+
pnpm add @atikk-co-jp/notion-mcp-server
|
|
23
|
+
# または
|
|
24
|
+
yarn add @atikk-co-jp/notion-mcp-server
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 使い方
|
|
28
|
+
|
|
29
|
+
### Claude Desktopで使用する
|
|
30
|
+
|
|
31
|
+
Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_desktop_config.json`)に追加:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"notion": {
|
|
37
|
+
"command": "npx",
|
|
38
|
+
"args": ["-y", "@atikk-co-jp/notion-mcp-server"],
|
|
39
|
+
"env": {
|
|
40
|
+
"NOTION_TOKEN": "your-notion-integration-token"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Claude Codeで使用する
|
|
48
|
+
|
|
49
|
+
`.mcp.json`に追加:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"notion": {
|
|
55
|
+
"command": "npx",
|
|
56
|
+
"args": ["-y", "@atikk-co-jp/notion-mcp-server"],
|
|
57
|
+
"env": {
|
|
58
|
+
"NOTION_TOKEN": "your-notion-integration-token"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Notionトークンの取得方法
|
|
66
|
+
|
|
67
|
+
1. [Notion Integrations](https://www.notion.so/my-integrations)にアクセス
|
|
68
|
+
2. 「新しいインテグレーション」をクリック
|
|
69
|
+
3. 名前を入力し、ワークスペースを選択
|
|
70
|
+
4. 「内部インテグレーションシークレット」をコピー(`ntn_`で始まる)
|
|
71
|
+
5. アクセスしたいページ/データベースをインテグレーションと共有
|
|
72
|
+
|
|
73
|
+
## 利用可能なツール
|
|
74
|
+
|
|
75
|
+
### retrieve-page
|
|
76
|
+
|
|
77
|
+
ページIDでNotionページを取得します。
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"page_id": "ページのUUID"
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### create-page
|
|
86
|
+
|
|
87
|
+
データベースに新しいページを作成します。
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"database_id": "データベースのUUID",
|
|
92
|
+
"properties": {
|
|
93
|
+
"Name": {
|
|
94
|
+
"title": [{ "text": { "content": "新しいページタイトル" } }]
|
|
95
|
+
},
|
|
96
|
+
"Status": {
|
|
97
|
+
"status": { "name": "進行中" }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### update-page
|
|
104
|
+
|
|
105
|
+
ページのプロパティを更新します。
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"page_id": "ページのUUID",
|
|
110
|
+
"properties": {
|
|
111
|
+
"Status": {
|
|
112
|
+
"status": { "name": "完了" }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### query-database
|
|
119
|
+
|
|
120
|
+
フィルターやソートを使ってデータベースをクエリします。
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"database_id": "データベースのUUID",
|
|
125
|
+
"filter": {
|
|
126
|
+
"property": "Status",
|
|
127
|
+
"status": { "equals": "進行中" }
|
|
128
|
+
},
|
|
129
|
+
"sorts": [
|
|
130
|
+
{ "property": "Created", "direction": "descending" }
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### search
|
|
136
|
+
|
|
137
|
+
すべてのページとデータベースを横断検索します。
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"query": "検索キーワード",
|
|
142
|
+
"filter": { "value": "page", "property": "object" }
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### get-block-children
|
|
147
|
+
|
|
148
|
+
ページまたはブロックの子ブロックを取得します。
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"block_id": "ページまたはブロックのUUID"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### append-block-children
|
|
157
|
+
|
|
158
|
+
ページまたはブロックに新しいブロックを追加します。
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"block_id": "ページまたはブロックのUUID",
|
|
163
|
+
"children": [
|
|
164
|
+
{
|
|
165
|
+
"type": "paragraph",
|
|
166
|
+
"paragraph": {
|
|
167
|
+
"rich_text": [{ "text": { "content": "新しい段落" } }]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### create-comment
|
|
175
|
+
|
|
176
|
+
ページにコメントを追加します。
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"page_id": "ページのUUID",
|
|
181
|
+
"rich_text": [{ "type": "text", "text": { "content": "これはコメントです" } }]
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 開発
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# 依存関係のインストール
|
|
189
|
+
pnpm install
|
|
190
|
+
|
|
191
|
+
# 開発モードで実行
|
|
192
|
+
pnpm dev
|
|
193
|
+
|
|
194
|
+
# 本番用ビルド
|
|
195
|
+
pnpm build
|
|
196
|
+
|
|
197
|
+
# 型チェック
|
|
198
|
+
pnpm typecheck
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## ライセンス
|
|
202
|
+
|
|
203
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# notion-mcp-server
|
|
2
|
+
|
|
3
|
+
English | [日本語](./README.ja.md)
|
|
4
|
+
|
|
5
|
+
MCP (Model Context Protocol) server for Notion API. Enables AI assistants to interact with Notion pages, databases, and blocks.
|
|
6
|
+
|
|
7
|
+
> ⚠️ **Note**: This is an early release. API may change.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Page Operations**: Create, retrieve, and update Notion pages
|
|
12
|
+
- **Database Queries**: Query databases with filters and sorts
|
|
13
|
+
- **Block Operations**: Get and append block children
|
|
14
|
+
- **Search**: Search across pages and databases
|
|
15
|
+
- **Comments**: Add comments to pages
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @atikk-co-jp/notion-mcp-server
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @atikk-co-jp/notion-mcp-server
|
|
23
|
+
# or
|
|
24
|
+
yarn add @atikk-co-jp/notion-mcp-server
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### With Claude Desktop
|
|
30
|
+
|
|
31
|
+
Add to your Claude Desktop configuration (`~/.config/claude/claude_desktop_config.json` on macOS):
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"notion": {
|
|
37
|
+
"command": "npx",
|
|
38
|
+
"args": ["-y", "@atikk-co-jp/notion-mcp-server"],
|
|
39
|
+
"env": {
|
|
40
|
+
"NOTION_TOKEN": "your-notion-integration-token"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### With Claude Code
|
|
48
|
+
|
|
49
|
+
Add to your `.mcp.json`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"notion": {
|
|
55
|
+
"command": "npx",
|
|
56
|
+
"args": ["-y", "@atikk-co-jp/notion-mcp-server"],
|
|
57
|
+
"env": {
|
|
58
|
+
"NOTION_TOKEN": "your-notion-integration-token"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Getting a Notion Token
|
|
66
|
+
|
|
67
|
+
1. Go to [Notion Integrations](https://www.notion.so/my-integrations)
|
|
68
|
+
2. Click "New integration"
|
|
69
|
+
3. Give it a name and select the workspace
|
|
70
|
+
4. Copy the "Internal Integration Token" (starts with `ntn_`)
|
|
71
|
+
5. Share the pages/databases you want to access with your integration
|
|
72
|
+
|
|
73
|
+
## Available Tools
|
|
74
|
+
|
|
75
|
+
### retrieve-page
|
|
76
|
+
|
|
77
|
+
Retrieve a Notion page by its ID.
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"page_id": "page-uuid-here"
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### create-page
|
|
86
|
+
|
|
87
|
+
Create a new page in a database.
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"database_id": "database-uuid-here",
|
|
92
|
+
"properties": {
|
|
93
|
+
"Name": {
|
|
94
|
+
"title": [{ "text": { "content": "New Page Title" } }]
|
|
95
|
+
},
|
|
96
|
+
"Status": {
|
|
97
|
+
"status": { "name": "In Progress" }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### update-page
|
|
104
|
+
|
|
105
|
+
Update a page's properties.
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"page_id": "page-uuid-here",
|
|
110
|
+
"properties": {
|
|
111
|
+
"Status": {
|
|
112
|
+
"status": { "name": "Done" }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### query-database
|
|
119
|
+
|
|
120
|
+
Query a database with optional filters and sorts.
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"database_id": "database-uuid-here",
|
|
125
|
+
"filter": {
|
|
126
|
+
"property": "Status",
|
|
127
|
+
"status": { "equals": "In Progress" }
|
|
128
|
+
},
|
|
129
|
+
"sorts": [
|
|
130
|
+
{ "property": "Created", "direction": "descending" }
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### search
|
|
136
|
+
|
|
137
|
+
Search across all pages and databases.
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"query": "search term",
|
|
142
|
+
"filter": { "value": "page", "property": "object" }
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### get-block-children
|
|
147
|
+
|
|
148
|
+
Get the child blocks of a page or block.
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"block_id": "page-or-block-uuid-here"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### append-block-children
|
|
157
|
+
|
|
158
|
+
Append new blocks to a page or block.
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"block_id": "page-or-block-uuid-here",
|
|
163
|
+
"children": [
|
|
164
|
+
{
|
|
165
|
+
"type": "paragraph",
|
|
166
|
+
"paragraph": {
|
|
167
|
+
"rich_text": [{ "text": { "content": "New paragraph" } }]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### create-comment
|
|
175
|
+
|
|
176
|
+
Add a comment to a page.
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"page_id": "page-uuid-here",
|
|
181
|
+
"rich_text": [{ "type": "text", "text": { "content": "This is a comment" } }]
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Install dependencies
|
|
189
|
+
pnpm install
|
|
190
|
+
|
|
191
|
+
# Run in development mode
|
|
192
|
+
pnpm dev
|
|
193
|
+
|
|
194
|
+
# Build for production
|
|
195
|
+
pnpm build
|
|
196
|
+
|
|
197
|
+
# Type check
|
|
198
|
+
pnpm typecheck
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../bin/cli.ts"],"names":[],"mappings":""}
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { startServer } from "../src/server.js";
|
|
3
|
+
async function main() {
|
|
4
|
+
// Validate environment
|
|
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:");
|
|
14
|
+
console.error(' NOTION_TOKEN="ntn_xxx..." npx notion-mcp-server');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
await startServer();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error("Failed to start server:", error);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
main();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createNotionClient, type NotionClient } from "./notion-client.js";
|
|
2
|
+
export * from "./schemas/index.js";
|
|
3
|
+
export { startServer } from "./server.js";
|
|
4
|
+
export { registerAllTools, registerAppendBlockChildren, registerCreateComment, registerCreatePage, registerGetBlockChildren, registerQueryDatabase, registerRetrievePage, registerSearch, registerUpdatePage, } from "./tools/index.js";
|
|
5
|
+
export type { McpResponse, McpTextContent } from "./utils/index.js";
|
|
6
|
+
export { formatResponse, formatSuccessMessage, handleError } from "./utils/index.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE3E,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Main exports
|
|
2
|
+
export { createNotionClient } from "./notion-client.js";
|
|
3
|
+
// Schemas
|
|
4
|
+
export * from "./schemas/index.js";
|
|
5
|
+
export { startServer } from "./server.js";
|
|
6
|
+
// Tool registration
|
|
7
|
+
export { registerAllTools, registerAppendBlockChildren, registerCreateComment, registerCreatePage, registerGetBlockChildren, registerQueryDatabase, registerRetrievePage, registerSearch, registerUpdatePage, } from "./tools/index.js";
|
|
8
|
+
// Utils
|
|
9
|
+
export { formatResponse, formatSuccessMessage, handleError } from "./utils/index.js";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface NotionClientOptions {
|
|
2
|
+
token: string;
|
|
3
|
+
}
|
|
4
|
+
export interface NotionRequestOptions {
|
|
5
|
+
method?: "GET" | "POST" | "PATCH" | "DELETE";
|
|
6
|
+
body?: unknown;
|
|
7
|
+
query?: Record<string, string | number | undefined>;
|
|
8
|
+
}
|
|
9
|
+
export interface NotionError {
|
|
10
|
+
object: "error";
|
|
11
|
+
status: number;
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class NotionClient {
|
|
16
|
+
private token;
|
|
17
|
+
constructor(options: NotionClientOptions);
|
|
18
|
+
private request;
|
|
19
|
+
pages: {
|
|
20
|
+
create: <T>(params: {
|
|
21
|
+
parent: {
|
|
22
|
+
database_id: string;
|
|
23
|
+
} | {
|
|
24
|
+
page_id: string;
|
|
25
|
+
};
|
|
26
|
+
properties: Record<string, unknown>;
|
|
27
|
+
children?: unknown[];
|
|
28
|
+
icon?: unknown;
|
|
29
|
+
cover?: unknown;
|
|
30
|
+
}) => Promise<T>;
|
|
31
|
+
retrieve: <T>(params: {
|
|
32
|
+
page_id: string;
|
|
33
|
+
}) => Promise<T>;
|
|
34
|
+
update: <T>(params: {
|
|
35
|
+
page_id: string;
|
|
36
|
+
properties?: Record<string, unknown>;
|
|
37
|
+
archived?: boolean;
|
|
38
|
+
icon?: unknown;
|
|
39
|
+
cover?: unknown;
|
|
40
|
+
}) => Promise<T>;
|
|
41
|
+
};
|
|
42
|
+
databases: {
|
|
43
|
+
query: <T>(params: {
|
|
44
|
+
database_id: string;
|
|
45
|
+
filter?: unknown;
|
|
46
|
+
sorts?: unknown[];
|
|
47
|
+
start_cursor?: string;
|
|
48
|
+
page_size?: number;
|
|
49
|
+
}) => Promise<T>;
|
|
50
|
+
};
|
|
51
|
+
blocks: {
|
|
52
|
+
children: {
|
|
53
|
+
list: <T>(params: {
|
|
54
|
+
block_id: string;
|
|
55
|
+
start_cursor?: string;
|
|
56
|
+
page_size?: number;
|
|
57
|
+
}) => Promise<T>;
|
|
58
|
+
append: <T>(params: {
|
|
59
|
+
block_id: string;
|
|
60
|
+
children: unknown[];
|
|
61
|
+
after?: string;
|
|
62
|
+
}) => Promise<T>;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
comments: {
|
|
66
|
+
create: <T>(params: {
|
|
67
|
+
parent: {
|
|
68
|
+
page_id: string;
|
|
69
|
+
};
|
|
70
|
+
rich_text: unknown[];
|
|
71
|
+
}) => Promise<T>;
|
|
72
|
+
};
|
|
73
|
+
search: <T>(params?: {
|
|
74
|
+
query?: string;
|
|
75
|
+
filter?: unknown;
|
|
76
|
+
sort?: unknown;
|
|
77
|
+
start_cursor?: string;
|
|
78
|
+
page_size?: number;
|
|
79
|
+
}) => Promise<T>;
|
|
80
|
+
}
|
|
81
|
+
export declare function createNotionClient(): NotionClient;
|
|
82
|
+
//# sourceMappingURL=notion-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion-client.d.ts","sourceRoot":"","sources":["../../src/notion-client.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC7C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,EAAE,mBAAmB;YAI1B,OAAO;IAwCrB,KAAK;iBACM,CAAC,UAAU;YAClB,MAAM,EAAE;gBAAE,WAAW,EAAE,MAAM,CAAA;aAAE,GAAG;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE,CAAC;YACtD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACpC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;YACrB,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,KAAK,CAAC,EAAE,OAAO,CAAC;SACjB,KAAG,OAAO,CAAC,CAAC,CAAC;mBAIH,CAAC,UAAU;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,KAAG,OAAO,CAAC,CAAC,CAAC;iBAI7C,CAAC,UAAU;YAClB,OAAO,EAAE,MAAM,CAAC;YAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,KAAK,CAAC,EAAE,OAAO,CAAC;SACjB,KAAG,OAAO,CAAC,CAAC,CAAC;MAId;IAGF,SAAS;gBACC,CAAC,UAAU;YACjB,WAAW,EAAE,MAAM,CAAC;YACpB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;YAClB,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,KAAG,OAAO,CAAC,CAAC,CAAC;MAId;IAGF,MAAM;;mBAEK,CAAC,UAAU;gBAChB,QAAQ,EAAE,MAAM,CAAC;gBACjB,YAAY,CAAC,EAAE,MAAM,CAAC;gBACtB,SAAS,CAAC,EAAE,MAAM,CAAC;aACpB,KAAG,OAAO,CAAC,CAAC,CAAC;qBAOL,CAAC,UAAU;gBAClB,QAAQ,EAAE,MAAM,CAAC;gBACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;gBACpB,KAAK,CAAC,EAAE,MAAM,CAAC;aAChB,KAAG,OAAO,CAAC,CAAC,CAAC;;MAKhB;IAGF,QAAQ;iBACG,CAAC,UAAU;YAAE,MAAM,EAAE;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE,CAAC;YAAC,SAAS,EAAE,OAAO,EAAE,CAAA;SAAE,KAAG,OAAO,CAAC,CAAC,CAAC;MAGtF;IAGF,MAAM,GAAI,CAAC,EAAE,SAAS;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAG,OAAO,CAAC,CAAC,CAAC,CAEZ;CACH;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CASjD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const NOTION_API_BASE = "https://api.notion.com/v1";
|
|
2
|
+
const NOTION_VERSION = "2022-06-28";
|
|
3
|
+
export class NotionClient {
|
|
4
|
+
token;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.token = options.token;
|
|
7
|
+
}
|
|
8
|
+
async request(endpoint, options = {}) {
|
|
9
|
+
const { method = "GET", body, query } = options;
|
|
10
|
+
let url = `${NOTION_API_BASE}${endpoint}`;
|
|
11
|
+
if (query) {
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
for (const [key, value] of Object.entries(query)) {
|
|
14
|
+
if (value !== undefined) {
|
|
15
|
+
params.set(key, String(value));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const queryString = params.toString();
|
|
19
|
+
if (queryString) {
|
|
20
|
+
url += `?${queryString}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const headers = {
|
|
24
|
+
Authorization: `Bearer ${this.token}`,
|
|
25
|
+
"Notion-Version": NOTION_VERSION,
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
};
|
|
28
|
+
const response = await fetch(url, {
|
|
29
|
+
method,
|
|
30
|
+
headers,
|
|
31
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
32
|
+
});
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const error = data;
|
|
36
|
+
throw new Error(`Notion API error: ${error.code} - ${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
// Pages
|
|
41
|
+
pages = {
|
|
42
|
+
create: (params) => {
|
|
43
|
+
return this.request("/pages", { method: "POST", body: params });
|
|
44
|
+
},
|
|
45
|
+
retrieve: (params) => {
|
|
46
|
+
return this.request(`/pages/${params.page_id}`);
|
|
47
|
+
},
|
|
48
|
+
update: (params) => {
|
|
49
|
+
const { page_id, ...body } = params;
|
|
50
|
+
return this.request(`/pages/${page_id}`, { method: "PATCH", body });
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
// Databases
|
|
54
|
+
databases = {
|
|
55
|
+
query: (params) => {
|
|
56
|
+
const { database_id, ...body } = params;
|
|
57
|
+
return this.request(`/databases/${database_id}/query`, { method: "POST", body });
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
// Blocks
|
|
61
|
+
blocks = {
|
|
62
|
+
children: {
|
|
63
|
+
list: (params) => {
|
|
64
|
+
const { block_id, ...query } = params;
|
|
65
|
+
return this.request(`/blocks/${block_id}/children`, {
|
|
66
|
+
query: query,
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
append: (params) => {
|
|
70
|
+
const { block_id, ...body } = params;
|
|
71
|
+
return this.request(`/blocks/${block_id}/children`, { method: "PATCH", body });
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
// Comments
|
|
76
|
+
comments = {
|
|
77
|
+
create: (params) => {
|
|
78
|
+
return this.request("/comments", { method: "POST", body: params });
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
// Search
|
|
82
|
+
search = (params) => {
|
|
83
|
+
return this.request("/search", { method: "POST", body: params || {} });
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function createNotionClient() {
|
|
87
|
+
const token = process.env.NOTION_TOKEN;
|
|
88
|
+
if (!token) {
|
|
89
|
+
throw new Error("NOTION_TOKEN environment variable is required. " +
|
|
90
|
+
"Please set it to your Notion integration token.");
|
|
91
|
+
}
|
|
92
|
+
return new NotionClient({ token });
|
|
93
|
+
}
|