@bitefoundry/onenote 0.3.0 → 0.4.1

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/docs/API.md CHANGED
@@ -1,114 +1,132 @@
1
- # Local HTTP JSON API (`onenote serve`)
2
-
3
- `onenote serve` runs a local Axum HTTP server bound to `127.0.0.1:8793` by default.
4
-
5
- ```sh
6
- # Start with default port (127.0.0.1:8793)
7
- onenote serve
8
-
9
- # Keep a client configured for the previous port
10
- onenote serve --port 8788
11
-
12
- # Set a bind address and require a Bearer token
13
- onenote serve --bind 127.0.0.1 --token my-secret-token
14
- ```
15
-
16
- When `--token` is provided, every endpoint except `/health` requires:
17
-
18
- ```http
19
- Authorization: Bearer my-secret-token
20
- ```
21
-
22
- ## Endpoints
23
-
24
- All OneNote endpoints are served under both `/v1/onenote/...` and the shorter `/onenote/...` alias.
25
-
26
- | Method | Path | Description |
27
- | --- | --- | --- |
28
- | `GET` | `/health` | Health check (`{ ok, service, version }`) |
29
- | `GET` | `/v1/whoami` | Signed-in Microsoft 365 user profile |
30
- | `GET` | `/v1/onenote/notebooks` | List notebooks (`?include_teams=false&refresh=false&offline=false`) |
31
- | `POST` | `/v1/onenote/notebooks` | Create notebook (`{ name, group_id?, site_id? }`) |
32
- | `GET` | `/v1/onenote/sections` | List sections (`?notebook=...&refresh=false&offline=false`) |
33
- | `POST` | `/v1/onenote/sections` | Create section (`{ notebook, name }`) |
34
- | `GET` | `/v1/onenote/pages` | List pages in a section (`?section=...&limit=50&refresh=false&offline=false`) |
35
- | `POST` | `/v1/onenote/pages` | Create a top-level page (`{ section, title, markdown?, level?, image_paths? }`). `level` defaults to 0. |
36
- | `GET` | `/v1/onenote/pages/{page}` | Get structured page detail (`?section=...&offline=false`) |
37
- | `PATCH` | `/v1/onenote/pages/{page}` | Update block or page (`{ block_id?, title?, markdown?, section? }`) |
38
- | `DELETE` | `/v1/onenote/pages/{page}` | Delete page (`?section=...`) |
39
- | `POST` | `/v1/onenote/pages/{page}/append` | Append Markdown/images (`{ markdown, images? \| image_paths?, section? }`) |
40
- | `POST` | `/v1/onenote/pages/{page}/todo` | Set or toggle checkbox (`{ block_id?, index?, completed?, expected_content?, force?, section? }`; alias: `/pages/{page}/toggle-todo`) |
41
- | `GET` | `/v1/onenote/search` | Search local FTS5 cache (`?q=...&section=...&limit=30&refresh=false`) |
42
- | `POST` | `/v1/onenote/resources/download` | Download embedded resource (`{ page, index?, url?, out? \| out_dir?, section? }`; alias: `/pages/{page}/resources/download`) |
43
-
44
- ### Resource Download Response
45
-
46
- ```json
47
- {
48
- "ok": true,
49
- "path": "/Users/you/Downloads/onenote-cli/diagram.png",
50
- "file_name": "diagram.png",
51
- "mime_type": "image/png",
52
- "size_bytes": 48192,
53
- "is_image": true
54
- }
55
- ```
56
-
57
- See [openapi.yaml](openapi.yaml) for the complete OpenAPI 3.1 schema.
58
-
59
- ## Hierarchy operations
60
-
61
- | Operation | Microsoft Graph OneNote v1.0 | Supported alternative |
62
- | --- | --- | --- |
63
- | Move an existing page to another section | Page parent relationships are read-only. Use CLI `copy-page` or MCP `copy_page` to create a separate page through Graph. [Page resource](https://learn.microsoft.com/en-us/graph/api/resources/page?view=graph-rest-1.0) · [Copy to section](#copy-a-page) | In OneNote for Windows, select **Move or Copy** on the page and then choose **Move**. Refresh the source and destination sections and verify the page ID, parent, and content after sync. [Move pages in OneNote](https://support.microsoft.com/en-us/onenote/organize-your-notes#move-a-page-or-subpage-to-another-section) |
64
- | Change an existing page's level | `level` is read-only and `pagelevel=true` returns indentation and order. Page creation accepts XHTML and creates a top-level page. [Page resource](https://learn.microsoft.com/en-us/graph/api/resources/page?view=graph-rest-1.0) · [Read page hierarchy](https://learn.microsoft.com/en-us/graph/onenote-get-content#page-entity) · [Create page](https://learn.microsoft.com/en-us/graph/api/section-post-pages?view=graph-rest-1.0) | Use `desktop-set-page-level` or `desktop_set_page_level` on Windows. You can also drag the page tab to change indentation. [Create or promote a subpage](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/create-a-subpage-in-onenote) |
65
- | Rename an existing notebook | The OneNote notebook service contract provides no rename method. `rename-notebook` and MCP `rename_notebook` use the Microsoft Graph Files API on a verified OneNote package. [OneNote notebook methods](https://learn.microsoft.com/en-us/graph/api/resources/notebook?view=graph-rest-1.0#methods) · [DriveItem update](https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0) | Rename through OneDrive or SharePoint with edit access. OneNote for Windows also supports a display name for your own view. A shared notebook's storage rename can disrupt existing access. [Rename a OneNote notebook](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/rename-a-onenote-notebook) |
66
- | Rename an existing section | CLI `rename-section SECTION_ID --name NAME` and MCP `rename_section` use the SDK's `PATCH /me/onenote/sections/{id}` with `displayName`. The app verifies the same ID and parents after the write. [Graph PowerShell section update](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.notes/update-mguseronenotesection?view=graph-powershell-1.0) · [Graph .NET request builder](https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/main/src/Microsoft.Graph/Generated/Me/Onenote/Sections/Item/OnenoteSectionItemRequestBuilder.cs) | Choose **Rename** on the section tab. Desktop automation can use `UpdateHierarchy` with the existing section ID. [Rename a section in OneNote](https://support.microsoft.com/en-us/onenote/organize-your-notes#rename-a-section) · [Windows OneNote COM interface](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote#updatehierarchy-method) |
67
-
68
- Use delegated sign-in for supported Graph OneNote operations. `Notes.Create` is the least privileged delegated scope for page creation and `copyToSection` for personal Microsoft accounts and work or school accounts. Existing page title and HTML writes require `Notes.ReadWrite` and edit access. `copyToSection` documents user and group source paths. Follow the endpoint's documented scope and path for the account and resource. [OneNote authorization and scopes](https://learn.microsoft.com/en-us/graph/api/resources/onenote-api-overview?view=graph-rest-1.0) · [Create page permissions](https://learn.microsoft.com/en-us/graph/api/section-post-pages?view=graph-rest-1.0#permissions) · [Update page permissions](https://learn.microsoft.com/en-us/graph/api/page-update?view=graph-rest-1.0#permissions) · [Copy permissions](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0#permissions)
69
-
70
- Section rename uses the signed-in `/me` route, the app's delegated `Notes.ReadWrite` scope, and edit access on the section. The OneNote REST section reference omits a rename permissions table, so account-specific availability is unverified. Graph errors and mismatched read-backs surface as errors. Use the desktop Rename command for sections outside this route. [Graph permission reference](https://learn.microsoft.com/en-us/graph/permissions-reference#notesreadwrite) · [OneNote section methods](https://learn.microsoft.com/en-us/graph/api/resources/onenotesection?view=graph-rest-1.0#methods) · [Microsoft Q&A section rename example](https://learn.microsoft.com/en-us/answers/questions/1065090/the-onenote-graph-api-does-not-return-the-new-name)
71
-
72
- ### Copy a page
73
-
74
- ```sh
75
- onenote copy-page 'me|PAGE_ID' --section 'me|SECTION_ID' --json
76
- onenote copy-page 'me|PAGE_ID' --section 'me|SECTION_ID' --operation 'OPERATION_URL' --json
77
- ```
78
-
79
- Use IDs or scoped keys from the page and section lists. A raw ID uses the signed-in user's `/me` route. A key such as `group:GROUP_ID|SECTION_ID` uses a Microsoft 365 group destination and sends its `groupId`. Group pages also accept a `group:GROUP_ID|PAGE_ID` source key. The client supports `/me` and `/groups/{id}` copy paths. [Microsoft Graph copyToSection paths and parameters](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0)
80
-
81
- Sign in with a delegated personal Microsoft account or work or school account. The copy and operation status endpoints list `Notes.Create` as the least privileged delegated scope. Page verification also needs read permission. A delegated `Notes.ReadWrite` token with access to both resources covers the workflow. Group notebooks require access to the relevant Microsoft 365 group resources. [Copy permissions](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0#permissions) · [Operation permissions](https://learn.microsoft.com/en-us/graph/api/onenoteoperation-get?view=graph-rest-1.0#permissions) · [Page read permissions](https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0#permissions) · [Delegated OneNote authentication](https://learn.microsoft.com/en-us/graph/integrate-with-onenote)
82
-
83
- The client sends one copy request, takes the operation URL from the `202 Accepted` response, and polls it on the configured Graph origin. On completion, the client reads the new page and verifies its ID differs from the source ID and its parent matches the requested destination. The original page and its links stay in place. [Graph operation status](https://learn.microsoft.com/en-us/graph/api/onenoteoperation-get?view=graph-rest-1.0) · [Graph page metadata](https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0)
84
-
85
- The JSON result includes `source_page_id`, `destination_section_id`, `operation_id` and `operation_url`. A verified copy returns `status: "completed"`, `new_page_id` and `new_page_key`. If polling reaches its deadline, the status is `pending`. A terminal Graph error returns `failed`. Polling errors and destination read-back errors return `status_unavailable` and `verification_failed` respectively. The CLI exits nonzero for these four outcomes and still prints the result with `--json`.
86
-
87
- Polling defaults to 20 seconds. Use `--wait-seconds 0` to return the accepted operation handle immediately. To check the same operation, use `--operation` with the returned `operation_url` and the original page and section arguments. If submission fails before you receive a usable operation URL, check the destination before submitting a new copy. See also [MCP copy_page](MCP.md#copy_page).
88
-
89
- ### Notebook storage rename
90
-
91
- Supply both the drive ID and item ID for an existing `driveItem` with `package.type = oneNote`. Set `ONENOTE_TOKEN_FILE` to a file containing a delegated Graph token with `Files.ReadWrite` and edit access. The Files API lists this permission for personal Microsoft accounts and work or school accounts. The command checks the package and parent, PATCHes only `name` with `If-Match` when an eTag is available, then verifies the same drive item ID and parent.
92
-
93
- ```sh
94
- onenote rename-notebook --drive-id DRIVE_ID --item-id ITEM_ID --name 'Engineering Notes' --json
95
- ```
96
-
97
- The result's `drive_item.item_id` identifies the notebook package in storage. Microsoft documents stable DriveItem IDs across rename. Its OneNote URL lookup can compare notebook IDs after syncing. Microsoft Support documents shared notebook access disruption and advises leaving Class and Staff Notebooks under their existing names. [OneNote notebook packages](https://learn.microsoft.com/en-us/graph/api/resources/package?view=graph-rest-1.0) · [DriveItem update and permissions](https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0) · [OneDrive item IDs](https://learn.microsoft.com/en-us/graph/onedrive-addressing-driveitems#id-based-addressing) · [OneNote URL lookup](https://learn.microsoft.com/en-us/graph/api/notebook-getnotebookfromweburl?view=graph-rest-1.0) · [Notebook rename in OneDrive and SharePoint](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/rename-a-onenote-notebook)
98
-
99
- ### Windows desktop hierarchy changes
100
-
101
- Open the notebook in desktop OneNote with edit access. The desktop commands use Windows PowerShell and the OneNote COM session. Get the full `Page` or `Section` `ID` from the desktop hierarchy. In Windows PowerShell, pass a specific notebook ID to `GetHierarchy` or pass an empty string to read open notebooks.
102
-
103
- ```powershell
104
- $note = New-Object -ComObject OneNote.Application
105
- $hierarchy = ''
106
- $note.GetHierarchy('', 4, [ref]$hierarchy, 2)
107
- $hierarchy
108
- onenote desktop-set-page-level 'FULL_DESKTOP_PAGE_ID' --level 1 --json
109
- onenote desktop-rename-section 'FULL_DESKTOP_SECTION_ID' --name 'Engineering Notes' --json
110
- ```
111
-
112
- Use levels 0, 1 and 2 for top-level pages and the two levels of subpages. A level update sends the page's ID and level and verifies the resulting level and original parent section. A section rename verifies the section ID, parent and name. The desktop Move workflow provides no documented Graph page-ID guarantee. [OneNote COM application interface](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote) · [Hierarchy and XML schema enumerations](https://learn.microsoft.com/en-us/office/client-developer/onenote/enumerations-onenote-developer-reference)
113
-
114
- After a native hierarchy edit, wait for OneNote to sync. Use `onenote read PAGE --json --full` or MCP `get_page` with `compact: false` to compare `summary.id`, `section_id`, `notebook_id`, `level`, and `raw_xhtml` with a previous read. Refresh hierarchy lists with `--refresh` and re-download referenced resources when binary preservation matters.
1
+ # Local HTTP JSON API (`onenote serve`)
2
+
3
+ `onenote serve` runs a local Axum HTTP server bound to `127.0.0.1:8793` by default.
4
+
5
+ ```sh
6
+ # Start with default port (127.0.0.1:8793); a random API key is printed once on stderr
7
+ onenote serve
8
+
9
+ # Keep a client configured for the previous port
10
+ onenote serve --port 8788
11
+
12
+ # Choose the API key yourself (flag or environment variable)
13
+ onenote serve --token my-secret-token
14
+ ONENOTE_API_KEY=my-secret-token onenote serve
15
+ ```
16
+
17
+ ### Authentication and access control
18
+
19
+ Every endpoint except `/health` requires the API key, sent as either header:
20
+
21
+ ```http
22
+ Authorization: Bearer my-secret-token
23
+ x-api-key: my-secret-token
24
+ ```
25
+
26
+ | Situation | Behaviour |
27
+ | --- | --- |
28
+ | `--api-key` / `--token` or `ONENOTE_API_KEY` set | That key is required. An empty value is an error. |
29
+ | Loopback bind, no key given | A random 32-byte key is generated for this run and printed once on stderr with a ready-to-copy `Authorization: Bearer …` line. |
30
+ | Loopback bind with `--allow-keyless` | No key is required (a warning is printed). Any local process can then read, edit and delete notebooks through the server. |
31
+ | Non-loopback bind (for example `--bind 0.0.0.0`) | A key is mandatory. `--allow-keyless` and the former `ONENOTE_ALLOW_INSECURE_SERVE` variable do not apply. |
32
+
33
+ The server also checks where a request comes from, on every route including `/health`:
34
+
35
+ - **`Host` allow-list.** The `Host` header must name `127.0.0.1`, `localhost`, `[::1]`, the `--bind` value, or a host added with `--allowed-host <HOST>` (repeatable; the port is ignored). Other hosts get `421 Misdirected Request`. When binding a LAN address, add the name clients use: `onenote serve --bind 0.0.0.0 --token … --allowed-host notes.corp.example`.
36
+ - **No cross-origin browser access by default.** A request with an `Origin` header gets `403 Forbidden`, and no `Access-Control-Allow-*` header is sent. To let a web app call the API, list its exact origin: `--cors-origin https://app.example.com` (repeatable). Wildcards are not supported. An allowed origin still needs the API key.
37
+
38
+ Command-line clients such as `curl` send no `Origin` header and are unaffected.
39
+
40
+ ## Endpoints
41
+
42
+ All OneNote endpoints are served under both `/v1/onenote/...` and the shorter `/onenote/...` alias.
43
+
44
+ | Method | Path | Description |
45
+ | --- | --- | --- |
46
+ | `GET` | `/health` | Health check (`{ ok, service, version }`) |
47
+ | `GET` | `/v1/whoami` | Signed-in Microsoft 365 user profile |
48
+ | `GET` | `/v1/onenote/notebooks` | List notebooks (`?include_teams=false&refresh=false&offline=false`) |
49
+ | `POST` | `/v1/onenote/notebooks` | Create notebook (`{ name, group_id?, site_id? }`) |
50
+ | `GET` | `/v1/onenote/sections` | List sections (`?notebook=...&refresh=false&offline=false`) |
51
+ | `POST` | `/v1/onenote/sections` | Create section (`{ notebook, name }`) |
52
+ | `GET` | `/v1/onenote/pages` | List pages in a section (`?section=...&limit=50&refresh=false&offline=false`) |
53
+ | `POST` | `/v1/onenote/pages` | Create a top-level page (`{ section, title, markdown?, level?, image_paths? }`). `level` defaults to 0. |
54
+ | `GET` | `/v1/onenote/pages/{page}` | Get structured page detail (`?section=...&offline=false`) |
55
+ | `PATCH` | `/v1/onenote/pages/{page}` | Update block or page (`{ block_id?, title?, markdown?, expected_content?, force?, section? }`) |
56
+ | `DELETE` | `/v1/onenote/pages/{page}` | Delete page (`?section=...`) |
57
+ | `POST` | `/v1/onenote/pages/{page}/append` | Append Markdown/images (`{ markdown, images? \| image_paths?, section? }`) |
58
+ | `POST` | `/v1/onenote/pages/{page}/todo` | Set or toggle checkbox (`{ block_id?, index?, completed?, expected_content?, force?, section? }`; alias: `/pages/{page}/toggle-todo`) |
59
+ | `GET` | `/v1/onenote/search` | Search local FTS5 cache (`?q=...&section=...&limit=30&refresh=false`) |
60
+ | `POST` | `/v1/onenote/resources/download` | Download embedded resource (`{ page, index?, url?, out? \| out_dir?, section? }`; alias: `/pages/{page}/resources/download`) |
61
+
62
+ ### Resource Download Response
63
+
64
+ ```json
65
+ {
66
+ "ok": true,
67
+ "path": "/Users/you/Downloads/onenote-cli/diagram.png",
68
+ "file_name": "diagram.png",
69
+ "mime_type": "image/png",
70
+ "size_bytes": 48192,
71
+ "is_image": true
72
+ }
73
+ ```
74
+
75
+ See [openapi.yaml](openapi.yaml) for the complete OpenAPI 3.1 schema.
76
+
77
+ ## Hierarchy operations
78
+
79
+ | Operation | Microsoft Graph OneNote v1.0 | Supported alternative |
80
+ | --- | --- | --- |
81
+ | Move an existing page to another section | Page parent relationships are read-only. Use CLI `copy-page` or MCP `copy_page` to create a separate page through Graph. [Page resource](https://learn.microsoft.com/en-us/graph/api/resources/page?view=graph-rest-1.0) · [Copy to section](#copy-a-page) | In OneNote for Windows, select **Move or Copy** on the page and then choose **Move**. Refresh the source and destination sections and verify the page ID, parent, and content after sync. [Move pages in OneNote](https://support.microsoft.com/en-us/onenote/organize-your-notes#move-a-page-or-subpage-to-another-section) |
82
+ | Change an existing page's level | `level` is read-only and `pagelevel=true` returns indentation and order. Page creation accepts XHTML and creates a top-level page. [Page resource](https://learn.microsoft.com/en-us/graph/api/resources/page?view=graph-rest-1.0) · [Read page hierarchy](https://learn.microsoft.com/en-us/graph/onenote-get-content#page-entity) · [Create page](https://learn.microsoft.com/en-us/graph/api/section-post-pages?view=graph-rest-1.0) | Use `desktop-set-page-level` or `desktop_set_page_level` on Windows. You can also drag the page tab to change indentation. [Create or promote a subpage](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/create-a-subpage-in-onenote) |
83
+ | Rename an existing notebook | The OneNote notebook service contract provides no rename method. `rename-notebook` and MCP `rename_notebook` use the Microsoft Graph Files API on a verified OneNote package. [OneNote notebook methods](https://learn.microsoft.com/en-us/graph/api/resources/notebook?view=graph-rest-1.0#methods) · [DriveItem update](https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0) | Rename through OneDrive or SharePoint with edit access. OneNote for Windows also supports a display name for your own view. A shared notebook's storage rename can disrupt existing access. [Rename a OneNote notebook](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/rename-a-onenote-notebook) |
84
+ | Rename an existing section | CLI `rename-section SECTION_ID --name NAME` and MCP `rename_section` use the SDK's `PATCH /me/onenote/sections/{id}` with `displayName`. The app verifies the same ID and parents after the write. [Graph PowerShell section update](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.notes/update-mguseronenotesection?view=graph-powershell-1.0) · [Graph .NET request builder](https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/main/src/Microsoft.Graph/Generated/Me/Onenote/Sections/Item/OnenoteSectionItemRequestBuilder.cs) | Choose **Rename** on the section tab. Desktop automation can use `UpdateHierarchy` with the existing section ID. [Rename a section in OneNote](https://support.microsoft.com/en-us/onenote/organize-your-notes#rename-a-section) · [Windows OneNote COM interface](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote#updatehierarchy-method) |
85
+
86
+ Use delegated sign-in for supported Graph OneNote operations. `Notes.Create` is the least privileged delegated scope for page creation and `copyToSection` for personal Microsoft accounts and work or school accounts. Existing page title and HTML writes require `Notes.ReadWrite` and edit access. `copyToSection` documents user and group source paths. Follow the endpoint's documented scope and path for the account and resource. [OneNote authorization and scopes](https://learn.microsoft.com/en-us/graph/api/resources/onenote-api-overview?view=graph-rest-1.0) · [Create page permissions](https://learn.microsoft.com/en-us/graph/api/section-post-pages?view=graph-rest-1.0#permissions) · [Update page permissions](https://learn.microsoft.com/en-us/graph/api/page-update?view=graph-rest-1.0#permissions) · [Copy permissions](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0#permissions)
87
+
88
+ Section rename uses the signed-in `/me` route, the app's delegated `Notes.ReadWrite` scope, and edit access on the section. The OneNote REST section reference omits a rename permissions table, so account-specific availability is unverified. Graph errors and mismatched read-backs surface as errors. Use the desktop Rename command for sections outside this route. [Graph permission reference](https://learn.microsoft.com/en-us/graph/permissions-reference#notesreadwrite) · [OneNote section methods](https://learn.microsoft.com/en-us/graph/api/resources/onenotesection?view=graph-rest-1.0#methods) · [Microsoft Q&A section rename example](https://learn.microsoft.com/en-us/answers/questions/1065090/the-onenote-graph-api-does-not-return-the-new-name)
89
+
90
+ ### Copy a page
91
+
92
+ ```sh
93
+ onenote copy-page 'me|PAGE_ID' --section 'me|SECTION_ID' --json
94
+ onenote copy-page 'me|PAGE_ID' --section 'me|SECTION_ID' --operation 'OPERATION_URL' --json
95
+ ```
96
+
97
+ Use IDs or scoped keys from the page and section lists. A raw ID uses the signed-in user's `/me` route. A key such as `group:GROUP_ID|SECTION_ID` uses a Microsoft 365 group destination and sends its `groupId`. Group pages also accept a `group:GROUP_ID|PAGE_ID` source key. The client supports `/me` and `/groups/{id}` copy paths. [Microsoft Graph copyToSection paths and parameters](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0)
98
+
99
+ Sign in with a delegated personal Microsoft account or work or school account. The copy and operation status endpoints list `Notes.Create` as the least privileged delegated scope. Page verification also needs read permission. A delegated `Notes.ReadWrite` token with access to both resources covers the workflow. Group notebooks require access to the relevant Microsoft 365 group resources. [Copy permissions](https://learn.microsoft.com/en-us/graph/api/page-copytosection?view=graph-rest-1.0#permissions) · [Operation permissions](https://learn.microsoft.com/en-us/graph/api/onenoteoperation-get?view=graph-rest-1.0#permissions) · [Page read permissions](https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0#permissions) · [Delegated OneNote authentication](https://learn.microsoft.com/en-us/graph/integrate-with-onenote)
100
+
101
+ The client sends one copy request, takes the operation URL from the `202 Accepted` response, and polls it on the configured Graph origin. On completion, the client reads the new page and verifies its ID differs from the source ID and its parent matches the requested destination. The original page and its links stay in place. [Graph operation status](https://learn.microsoft.com/en-us/graph/api/onenoteoperation-get?view=graph-rest-1.0) · [Graph page metadata](https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0)
102
+
103
+ The JSON result includes `source_page_id`, `destination_section_id`, `operation_id` and `operation_url`. A verified copy returns `status: "completed"`, `new_page_id` and `new_page_key`. If polling reaches its deadline, the status is `pending`. A terminal Graph error returns `failed`. Polling errors and destination read-back errors return `status_unavailable` and `verification_failed` respectively. The CLI exits nonzero for these four outcomes and prints a single JSON object with `ok: false`, the top-level operation fields, and `error: { code, message }` when `--json` is passed.
104
+
105
+ Polling defaults to 20 seconds. Use `--wait-seconds 0` to return the accepted operation handle immediately. To check the same operation, use `--operation` with the returned `operation_url` and the original page and section arguments. If submission fails before you receive a usable operation URL, check the destination before submitting a new copy. See also [MCP copy_page](MCP.md#copy_page).
106
+
107
+ ### Notebook storage rename
108
+
109
+ Supply both the drive ID and item ID for an existing `driveItem` with `package.type = oneNote`. Set `ONENOTE_TOKEN_FILE` to a file containing a delegated Graph token with `Files.ReadWrite` and edit access. The Files API lists this permission for personal Microsoft accounts and work or school accounts. The command checks the package and parent, PATCHes only `name` with `If-Match` when an eTag is available, then verifies the same drive item ID and parent.
110
+
111
+ ```sh
112
+ onenote rename-notebook --drive-id DRIVE_ID --item-id ITEM_ID --name 'Engineering Notes' --json
113
+ ```
114
+
115
+ The result's `drive_item.item_id` identifies the notebook package in storage. Microsoft documents stable DriveItem IDs across rename. Its OneNote URL lookup can compare notebook IDs after syncing. Microsoft Support documents shared notebook access disruption and advises leaving Class and Staff Notebooks under their existing names. [OneNote notebook packages](https://learn.microsoft.com/en-us/graph/api/resources/package?view=graph-rest-1.0) · [DriveItem update and permissions](https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0) · [OneDrive item IDs](https://learn.microsoft.com/en-us/graph/onedrive-addressing-driveitems#id-based-addressing) · [OneNote URL lookup](https://learn.microsoft.com/en-us/graph/api/notebook-getnotebookfromweburl?view=graph-rest-1.0) · [Notebook rename in OneDrive and SharePoint](https://support.microsoft.com/en-us/onenote/onenote-help-and-learning/rename-a-onenote-notebook)
116
+
117
+ ### Windows desktop hierarchy changes
118
+
119
+ Open the notebook in desktop OneNote with edit access. The desktop commands use Windows PowerShell and the OneNote COM session. Get the full `Page` or `Section` `ID` from the desktop hierarchy. In Windows PowerShell, pass a specific notebook ID to `GetHierarchy` or pass an empty string to read open notebooks.
120
+
121
+ ```powershell
122
+ $note = New-Object -ComObject OneNote.Application
123
+ $hierarchy = ''
124
+ $note.GetHierarchy('', 4, [ref]$hierarchy, 2)
125
+ $hierarchy
126
+ onenote desktop-set-page-level 'FULL_DESKTOP_PAGE_ID' --level 1 --json
127
+ onenote desktop-rename-section 'FULL_DESKTOP_SECTION_ID' --name 'Engineering Notes' --json
128
+ ```
129
+
130
+ Use levels 0, 1 and 2 for top-level pages and the two levels of subpages. A level update sends the page's ID and level and verifies the resulting level and original parent section. A section rename verifies the section ID, parent and name. The desktop Move workflow provides no documented Graph page-ID guarantee. [OneNote COM application interface](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote) · [Hierarchy and XML schema enumerations](https://learn.microsoft.com/en-us/office/client-developer/onenote/enumerations-onenote-developer-reference)
131
+
132
+ After a native hierarchy edit, wait for OneNote to sync. Use `onenote read PAGE --json --full` or MCP `get_page` with `compact: false` to compare `summary.id`, `section_id`, `notebook_id`, `level`, and `raw_xhtml` with a previous read. Refresh hierarchy lists with `--refresh` and re-download referenced resources when binary preservation matters.
package/docs/MCP.md CHANGED
@@ -1,130 +1,139 @@
1
- # Model Context Protocol (MCP) Server (`onenote mcp`)
2
-
3
- `onenote mcp` exposes Microsoft OneNote over **newline-delimited JSON-RPC 2.0 on stdio** (`protocolVersion: "2024-11-05"`), designed for Claude Desktop, Claude Code, Codex, and custom AI agents.
4
-
5
- ## Client Configuration
6
-
7
- ### Claude Desktop / Claude Code / Cursor
8
-
9
- ```json
10
- {
11
- "mcpServers": {
12
- "onenote": {
13
- "command": "onenote",
14
- "args": ["mcp"]
15
- }
16
- }
17
- }
18
- ```
19
-
20
- If installed via `npx`:
21
-
22
- ```json
23
- {
24
- "mcpServers": {
25
- "onenote": {
26
- "command": "npx",
27
- "args": ["-y", "@bitefoundry/onenote", "mcp"]
28
- }
29
- }
30
- }
31
- ```
32
-
33
- ## Available Tools
34
-
35
- | Tool | Description | Key Parameters |
36
- | --- | --- | --- |
37
- | `whoami` | Return signed-in Microsoft 365 profile & auth mode | _(none)_ |
38
- | `list_notebooks` | List accessible OneNote notebooks (personal, Teams/Group, SharePoint) | `include_teams?`, `limit?`, `cursor?`, `refresh?`, `offline?` |
39
- | `list_sections` | List sections in a notebook or across all notebooks | `notebook?`, `limit?`, `cursor?`, `refresh?`, `offline?` |
40
- | `list_pages` | List pages in a section (supports `Notebook/Section`, name, or ID) | `section` (required), `limit?`, `cursor?`, `refresh?`, `offline?` |
41
- | `get_page` | Read compact Markdown and identifiers; pass compact: false for XHTML, blocks and resources | `page` (required), `compact?`, `offline?` |
42
- | `create_notebook` | Create a new OneNote notebook | `name` (required), `group_id?`, `site_id?` |
43
- | `rename_notebook` | Rename a OneNote notebook package by explicit storage IDs | `drive_id`, `item_id`, `name` (all required) |
44
- | `create_section` | Create a new section inside a notebook | `notebook` (required), `name` (required) |
45
- | `rename_section` | Rename a section under `/me/onenote` and verify its ID and parents | `section` (required section ID or `me\|ID`), `name` (required) |
46
- | `desktop_rename_section` | Rename an existing section in OneNote for Windows | `section_id`, `name` (both required) |
47
- | `desktop_set_page_level` | Set the indentation of an existing page in OneNote for Windows | `page_id`, `level` (both required, level 0–2) |
48
- | `create_page` | Create a top-level OneNote page from Markdown and local images | `section` (required), `title` (required), `markdown?`, `level?` (0), `image_paths?` |
49
- | `copy_page` | Copy an existing page through Graph and verify its destination and new ID | `page`, `section` (IDs or scoped keys, both required), `operation_url?`, `wait_seconds?` |
50
- | `append_page` | Append Markdown and local images to the primary page region | `page` (required), `markdown` (required), `image_paths?` |
51
- | `update_block`, `update_page` | Replace a block, edit its text, or update the page title/body | `page` (required), `block_id?`, `title?`, `markdown?`, `replace_text?`, `with_text?`, `expected_content?`, `force?` |
52
- | `toggle_todo` | Set or toggle a checkbox by element ID or zero-based index | `page` (required), `block_id?`, `todo_index?`, `completed?`, `expected_content?`, `force?` |
53
- | `delete_page` | Permanently delete a OneNote page | `page` (required), `confirm: true` (required) |
54
- | `search_pages` | Full-text search across locally cached OneNote pages (SQLite FTS5) | `query` (required), `section?`, `limit?`, `cursor?`, `refresh?` |
55
- | `download_resource` | Download an embedded OneNote image or file attachment to disk | `page` (required), `index?`, `out_dir?` |
56
-
57
- The server resolves the signed-in account and local cache on the first `tools/call`; `initialize`, `ping`, and `tools/list` respond without contacting Graph or selecting a cache.
58
-
59
- ### Page reads and writes
60
-
61
- `get_page` returns the compact page by default, including `page.page_key`, `page.scope`, `page.omitted`, and `page.hint`. Pass `compact: false` to read `page.blocks[].element_id`, `page.raw_xhtml`, and `page.resources`. Write tools (`append_page`, `update_block`, `update_page`, `toggle_todo`) always return the full `page` object. Use current element IDs for block writes. Both `update_block` and its `update_page` alias appear in `tools/list`.
62
-
63
- ### List paging
64
-
65
- `list_notebooks` and `list_sections` return up to 50 items by default (`limit` range `1`–`1000`); `list_pages` defaults to 50 and `search_pages` defaults to 30. All four responses include `returned`, `has_more`, and `next_cursor` (pass `next_cursor` back as `cursor` to read the next page). When called with `offline: true`, `list_notebooks`, `list_sections`, and `list_pages` also include `cache_synced_at` (an RFC 3339 timestamp string, or `null` when the cache has never been synced). `search_pages` includes `cache: { pages, pages_with_body }` to show how many cached pages exist and how many have hydrated bodies.
66
-
67
- `rename_section` takes the section's current ID from `list_sections`. `rename_notebook` takes the current DriveItem ID and requires a delegated file-write token. The desktop tools use the Windows app's object IDs from `GetHierarchy`. [Hierarchy operations and permissions](API.md#hierarchy-operations)
68
-
69
- ```json
70
- {"name":"rename_section","arguments":{"section":"me|SECTION_ID","name":"Architecture Notes"}}
71
- ```
72
-
73
- ```json
74
- {"name":"rename_notebook","arguments":{"drive_id":"DRIVE_ID","item_id":"ITEM_ID","name":"Engineering Notes"}}
75
- ```
76
-
77
- ```json
78
- {"name":"desktop_set_page_level","arguments":{"page_id":"FULL_DESKTOP_PAGE_ID","level":1}}
79
- ```
80
-
81
- The following JSON objects are `tools/call` parameters.
82
-
83
- ```json
84
- {"name":"update_block","arguments":{"page":"me|PAGE_ID","block_id":"p:{ELEMENT_ID}","replace_text":"READY","with_text":"APPROVED"}}
85
- ```
86
-
87
- To replace the full block, pass `markdown` with `block_id`. Send `expected_content` from a previous read to check the live content before writing. A page-wide Markdown update on a page with several regions requires text changes that can be matched to current elements. Use `append_page` to add new content.
88
-
89
- ```json
90
- {"name":"toggle_todo","arguments":{"page":"me|PAGE_ID","block_id":"p:{TODO_ID}","completed":true}}
91
- ```
92
-
93
- Set `completed` to `false` to uncheck the item. Omit `completed` to toggle. Repeating a set operation with the same state skips the write after the conflict check.
94
-
95
- ```json
96
- {"name":"create_page","arguments":{"section":"SECTION_ID","title":"Evidence","markdown":"Release diagram","image_paths":["./diagram.png"]}}
97
- ```
98
-
99
- ### `copy_page`
100
-
101
- ```json
102
- {"name":"copy_page","arguments":{"page":"me|PAGE_ID","section":"me|SECTION_ID"}}
103
- ```
104
-
105
- Graph assigns a new page ID in the destination section. The original page and its links stay in place. A completed response includes `source_page_id`, `destination_section_id` and `new_page_id` in `structuredContent`. `wait_seconds` defaults to 20 and accepts 0 to return the accepted operation handle immediately.
106
-
107
- For a pending copy, an unavailable status, or a verification error, check the same operation by passing its `operation_url` and the same page and section.
108
-
109
- ```json
110
- {"name":"copy_page","arguments":{"page":"me|PAGE_ID","section":"me|SECTION_ID","operation_url":"OPERATION_URL"}}
111
- ```
112
-
113
- `isError` is true until the result confirms the copied page. Use `structuredContent.status` and `structuredContent.operation_url` to distinguish a pending, failed, or unverified operation and identify it. [Copy workflow and permissions](API.md#copy-a-page)
114
-
115
- ### `download_resource` Response Shape
116
-
117
- ```json
118
- {"name":"download_resource","arguments":{"page":"me|PAGE_ID","index":0,"out_dir":"./downloads"}}
119
- ```
120
-
121
- ```json
122
- {
123
- "ok": true,
124
- "path": "/path/to/downloaded-file.png",
125
- "file_name": "downloaded-file.png",
126
- "mime_type": "image/png",
127
- "size_bytes": 12480,
128
- "is_image": true
129
- }
130
- ```
1
+ # Model Context Protocol (MCP) Server (`onenote mcp`)
2
+
3
+ `onenote mcp` exposes Microsoft OneNote over **newline-delimited JSON-RPC 2.0 on stdio** (`protocolVersion: "2024-11-05"`), designed for Claude Desktop, Claude Code, Codex, and custom AI agents.
4
+
5
+ ## Client Configuration
6
+
7
+ ### Claude Desktop / Claude Code / Cursor
8
+
9
+ ```json
10
+ {
11
+ "mcpServers": {
12
+ "onenote": {
13
+ "command": "onenote",
14
+ "args": ["mcp"]
15
+ }
16
+ }
17
+ }
18
+ ```
19
+
20
+ If installed via `npx`:
21
+
22
+ ```json
23
+ {
24
+ "mcpServers": {
25
+ "onenote": {
26
+ "command": "npx",
27
+ "args": ["-y", "@bitefoundry/onenote", "mcp"]
28
+ }
29
+ }
30
+ }
31
+ ```
32
+
33
+ ## Available Tools
34
+
35
+ | Tool | Description | Key Parameters |
36
+ | --- | --- | --- |
37
+ | `whoami` | Return signed-in Microsoft 365 profile & auth mode | _(none)_ |
38
+ | `list_notebooks` | List accessible OneNote notebooks (personal, plus Teams/Group with `include_teams`; SharePoint site notebooks are not auto-discovered) | `include_teams?`, `limit?`, `cursor?`, `refresh?`, `offline?` |
39
+ | `list_sections` | List sections in a notebook or across all notebooks | `notebook?`, `limit?`, `cursor?`, `refresh?`, `offline?` |
40
+ | `list_pages` | List pages in a section (supports `Notebook/Section`, name, or ID) | `section` (required), `limit?`, `cursor?`, `refresh?`, `offline?` |
41
+ | `get_page` | Read compact Markdown and identifiers; pass compact: false for XHTML, blocks and resources | `page` (required), `section?`, `compact?`, `offline?` |
42
+ | `create_notebook` | Create a new OneNote notebook | `name` (required), `group_id?`, `site_id?` |
43
+ | `rename_notebook` | Rename a OneNote notebook package by explicit storage IDs | `drive_id`, `item_id`, `name` (all required) |
44
+ | `create_section` | Create a new section inside a notebook | `notebook` (required), `name` (required) |
45
+ | `rename_section` | Rename a section under `/me/onenote` and verify its ID and parents | `section` (required section ID or `me\|ID`), `name` (required) |
46
+ | `desktop_rename_section` | Rename an existing section in OneNote for Windows | `section_id`, `name` (both required) |
47
+ | `desktop_set_page_level` | Set the indentation of an existing page in OneNote for Windows | `page_id`, `level` (both required, level 0–2) |
48
+ | `create_page` | Create a top-level OneNote page from Markdown and local images | `section` (required), `title` (required), `markdown?`, `level?` (0), `image_paths?` |
49
+ | `copy_page` | Copy an existing page through Graph and verify its destination and new ID | `page`, `section` (IDs or scoped keys, both required), `operation_url?`, `wait_seconds?` |
50
+ | `append_page` | Append Markdown and local images to the primary page region | `page` (required), `section?`, `markdown` (required), `image_paths?`, `compact?` |
51
+ | `update_block`, `update_page` | Replace a block, edit its text, or update the page title/body | `page` (required), `section?`, `block_id?`, `title?`, `markdown?`, `replace_text?`, `with_text?`, `expected_content?`, `force?`, `compact?` |
52
+ | `toggle_todo` | Set or toggle a checkbox by element ID or zero-based index | `page` (required), `section?`, `block_id?`, `todo_index?`, `completed?`, `expected_content?`, `force?`, `compact?` |
53
+ | `delete_page` | Permanently delete a OneNote page | `page` (required), `section?`, `confirm: true` (required) |
54
+ | `search_pages` | Full-text search across locally cached OneNote pages (SQLite FTS5) | `query` (required), `section?`, `limit?`, `cursor?`, `refresh?` |
55
+ | `download_resource` | Download an embedded OneNote image or file attachment to disk | `page` (required), `index?`, `out_dir?` |
56
+
57
+ The server resolves the signed-in account and local cache on the first `tools/call`; `initialize`, `ping`, and `tools/list` respond without contacting Graph or selecting a cache.
58
+
59
+ ### Request cost
60
+
61
+ Each tool description in `tools/list` states what a call costs, so agents can avoid expensive patterns:
62
+
63
+ - `search_pages` is local (no network). `refresh: true` first runs a full account sync, which issues many Graph requests on large accounts; do not use it in loops.
64
+ - `list_notebooks`, `list_sections`, `list_pages` and `get_page` call Microsoft Graph unless `offline: true`. A recent cached list is reused only when `ONENOTE_CLI_CACHE_SECS` is set; `refresh: true` always refetches.
65
+ - `include_teams` adds one Graph request per joined Team (up to `ONENOTE_MAX_TEAMS`, default 100). `list_sections` without `notebook` lists every notebook, including Teams notebooks, and then each notebook's sections.
66
+ - `copy_page` blocks for up to `wait_seconds` while it polls the server-side copy. `download_resource` downloads the full file to disk.
67
+
68
+ ### Page reads and writes
69
+
70
+ `get_page` returns the compact page by default, including `page.page_key`, `page.scope`, `page.omitted`, and `page.hint`. Pass `compact: false` to read `page.blocks[].element_id`, `page.raw_xhtml`, and `page.resources`. Write tools (`append_page`, `update_block`, `update_page`, `toggle_todo`) return a compact summary (`ok`, `page_key`, `title`, `last_modified_at`, plus `block_id` / `completed` where applicable) by default; pass `compact: false` to include the full `page` object. Page tools (`get_page`, `append_page`, `update_block`, `update_page`, `toggle_todo`, `delete_page`) accept an optional `section` argument to narrow title lookup. Use current element IDs for block writes. Both `update_block` and its `update_page` alias appear in `tools/list`.
71
+
72
+ ### List paging
73
+
74
+ `list_notebooks`, `list_sections`, `list_pages`, and `search_pages` enforce `limit` in `1`–`1000` (`list_notebooks`, `list_sections`, and `list_pages` default to 50; `search_pages` defaults to 30). All four responses include `returned`, `has_more`, and `next_cursor` (pass `next_cursor` back as `cursor` to read the next page). When called with `offline: true`, `list_notebooks`, `list_sections`, and `list_pages` also include `cache_synced_at` (an RFC 3339 timestamp string, or `null` when the cache has never been synced). `search_pages` includes `cache: { pages, pages_with_body }` to show how many cached pages exist and how many have hydrated bodies; body search covers pages that have been read or synced.
75
+
76
+ `rename_section` takes the section's current ID from `list_sections`. `rename_notebook` takes the current DriveItem ID and requires a delegated file-write token. The desktop tools use the Windows app's object IDs from `GetHierarchy`. [Hierarchy operations and permissions](API.md#hierarchy-operations)
77
+
78
+ ```json
79
+ {"name":"rename_section","arguments":{"section":"me|SECTION_ID","name":"Architecture Notes"}}
80
+ ```
81
+
82
+ ```json
83
+ {"name":"rename_notebook","arguments":{"drive_id":"DRIVE_ID","item_id":"ITEM_ID","name":"Engineering Notes"}}
84
+ ```
85
+
86
+ ```json
87
+ {"name":"desktop_set_page_level","arguments":{"page_id":"FULL_DESKTOP_PAGE_ID","level":1}}
88
+ ```
89
+
90
+ The following JSON objects are `tools/call` parameters.
91
+
92
+ ```json
93
+ {"name":"update_block","arguments":{"page":"me|PAGE_ID","block_id":"p:{ELEMENT_ID}","replace_text":"READY","with_text":"APPROVED"}}
94
+ ```
95
+
96
+ To replace the full block, pass `markdown` with `block_id`. Send `expected_content` from a previous read to check the live content before writing. A page-wide Markdown update on a page with several regions requires text changes that can be matched to current elements. Use `append_page` to add new content.
97
+
98
+ ```json
99
+ {"name":"toggle_todo","arguments":{"page":"me|PAGE_ID","block_id":"p:{TODO_ID}","completed":true}}
100
+ ```
101
+
102
+ Set `completed` to `false` to uncheck the item. Omit `completed` to toggle. Repeating a set operation with the same state skips the write after the conflict check.
103
+
104
+ ```json
105
+ {"name":"create_page","arguments":{"section":"SECTION_ID","title":"Evidence","markdown":"Release diagram","image_paths":["./diagram.png"]}}
106
+ ```
107
+
108
+ ### `copy_page`
109
+
110
+ ```json
111
+ {"name":"copy_page","arguments":{"page":"me|PAGE_ID","section":"me|SECTION_ID"}}
112
+ ```
113
+
114
+ Graph assigns a new page ID in the destination section. The original page and its links stay in place. A completed response includes `source_page_id`, `destination_section_id` and `new_page_id` in `structuredContent`. `wait_seconds` defaults to 20 and accepts 0 to return the accepted operation handle immediately.
115
+
116
+ For a pending copy, an unavailable status, or a verification error, check the same operation by passing its `operation_url` and the same page and section.
117
+
118
+ ```json
119
+ {"name":"copy_page","arguments":{"page":"me|PAGE_ID","section":"me|SECTION_ID","operation_url":"OPERATION_URL"}}
120
+ ```
121
+
122
+ `isError` is true until the result confirms the copied page. Use `structuredContent.status` and `structuredContent.operation_url` to distinguish a pending, failed, or unverified operation and identify it. [Copy workflow and permissions](API.md#copy-a-page)
123
+
124
+ ### `download_resource` Response Shape
125
+
126
+ ```json
127
+ {"name":"download_resource","arguments":{"page":"me|PAGE_ID","index":0,"out_dir":"./downloads"}}
128
+ ```
129
+
130
+ ```json
131
+ {
132
+ "ok": true,
133
+ "path": "/path/to/downloaded-file.png",
134
+ "file_name": "downloaded-file.png",
135
+ "mime_type": "image/png",
136
+ "size_bytes": 12480,
137
+ "is_image": true
138
+ }
139
+ ```