nbjm-mcp
by newknew
README.md
# nbjm-mcp
> **Deprecated** — no longer maintained. Use Notion's hosted MCP
> server at `https://mcp.notion.com/mcp` instead. The code stays
> for reference; the server still prints a warning on startup.
This MCP server gives Claude full read/write access to your Notion workspace.
- **Token-efficient** — a typical Notion page is 50-100KB of JSON from the API. This server compresses that to 2-5KB of readable text (87-92% reduction), so Claude can work with large workspaces without blowing through context.
- **Parallel read/write** — mutations execute concurrently with async rate limiting. Batch edits to a page happen in parallel, not one block at a time.
- **Broad block type coverage** — 16 block types, inline formatting, database CRUD, table read/write, column layouts, and database schema management. Not universal yet (synced blocks and media are read-only).
## How it works
Doesn't Notion basically feel like fancy markdown? Well, that's the entire idea here. When you read a Notion page through this server, you get back something that looks like this:
```
R4kQ # Potential names for my cat
t9Xm > Serious contenders
pL3n - **Gerald**
vB8s - Very distinguished
J2wE - **Margaret** :red[(vetoed @date:2026-02-14)]
hA3z > Backups
dR5v - **Dr. Philip Hoffmann III**
wU6j # Potential names for my newborn
bT1y - :blue[Mr. Beans] (current frontrunner)
xF4p - Pros: already responds to it
gN9s - Cons: none
kD2r - Mittens
eP5m - *Does this sound too much like a cat?*
gI7N - See @p:R4kQ
```
There are many small differences from markdown — `>` is a toggle (foldable section), `@p:R4kQ` is a page mention, and [following Streamlit](https://docs.streamlit.io/develop/api-reference/text/st.markdown), `:red[...]` is colored text — but the format is designed to be immediately readable without learning anything new. For the full specification covering all block types, inline formatting, mutation commands, and error codes, see [docs/nbjm-spec.md](docs/nbjm-spec.md).
One big departure from markdown is those four-character codes on the left (`R4kQ`, `t9Xm`, ...). Each one is a token-efficient reference to a Notion block. The MCP server manages these IDs across reads and writes so that edits target the correct blocks.
## Prerequisites
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) or [Codex](https://developers.openai.com/codex/) (untested) or another MCP client
- A [Notion](https://www.notion.so/) account with an API integration
- [uv](https://docs.astral.sh/uv/getting-started/installation/) (Python package manager)
> **Note:** Only tested on Ubuntu so far.
## Setup
### 1. Get a Notion API token
Create an internal integration at [notion.so/profile/integrations](https://www.notion.so/profile/integrations). It needs **Read**, **Update**, and **Insert content** capabilities. You'll get a token starting with `ntn_`.
Then share the pages/databases you want accessible: open each top-level page in Notion, go to **...** → **Connections**, and add your integration. Child pages inherit access.
### 2. Save the token to a file
```bash
mkdir -p ~/.config/nbjm-mcp
echo "ntn_YOUR_TOKEN_HERE" > ~/.config/nbjm-mcp/token
```
### 3. Add to Claude Code
Add this to `~/.claude/settings.json` (or a project `.mcp.json`):
```json
{
"mcpServers": {
"nbjm-mcp": {
"type": "stdio",
"command": "uvx",
"args": [
"--refresh",
"--from",
"git+https://github.com/newknew/nbjm-mcp",
"nbjm-mcp",
"--token-file",
"~/.config/nbjm-mcp/token"
]
}
}
}
```
Restart Claude Code. You should see five new tools: `notion_read`, `notion_apply`, `notion_search`, `notion_check_auth`, and `notion_get_url`. Ask Claude to run `notion_check_auth` to verify the connection.
### 3b. Add to Codex (untested)
> **Note:** These instructions have not been tested. If you run into issues, please [open an issue](https://github.com/newknew/nbjm-mcp/issues).
Add this to `~/.codex/config.toml` (or a project-scoped `.codex/config.toml`):
```toml
[mcp_servers.nbjm-mcp]
command = "uvx"
args = [
"--refresh",
"--from", "git+https://github.com/newknew/nbjm-mcp",
"nbjm-mcp",
"--token-file", "~/.config/nbjm-mcp/token",
]
```
Or use the CLI:
```bash
codex mcp add nbjm-mcp -- uvx --refresh --from git+https://github.com/newknew/nbjm-mcp nbjm-mcp --token-file ~/.config/nbjm-mcp/token
```
## Not yet supported
- **Synced blocks** — displayed as placeholder, can't create
- **Video/file blocks** — displayed as `!file~` etc.; can't
be created via the API (use `!img` for images)
- **Block equations** — read-only (inline `:eq[expr]` works)
## Changelog
### v0.7.2 — 2026-10-25
- **Deprecated** — superseded by Notion's hosted MCP server.
Startup prints a deprecation warning to stderr.
### v0.7.0 — 2026-04-29
- **Image block creation via `!img`** — `notion_apply` scripts can
now create image blocks inline. Two forms:
`!img url=https://example.com/x.png` (external URL, externally
hosted) and `!img path=/abs/local/file.png` (local file uploaded
via Notion's `/file_uploads` API, ≤20 MB single-part). Add
`caption="…"` for inline captions with full rich-text support.
Previously agents had to upload PNGs to Drive and link to them,
which broke inline rendering. Existing image blocks still render
as `!image~` on read for backwards compatibility.
### v0.5.0 — 2026-04-15
- **Refuse misplaced row-update payloads as titles** — every path that sets a page, row, or database title (`+page`, `+db`, `+row` Name column, `upage`, `cpage`, `u` on page/database, `urow`, `u <rowID>` Name column) now refuses values that look like a row-update payload landing in the wrong place. Two bright-line checks: the value contains a literal tab character (tabs are the DSL's column separator for row updates — a title with a tab is almost certainly a misplaced update), or the value starts with a `CapitalizedKey=Value` pattern (e.g. `Last contact=2026-04-10`). Rejections come back as `SUSPICIOUS_TITLE` with a specific reason and a suggested `urow` rewrite. Regression for the contact-db corruption that produced dozens of rows with titles like `Last contact=2026-04-10\tLast platform=WhatsApp` across prior sessions — the earlier u-on-row fix closed one path, this closes the perimeter.
### v0.4.0 — 2026-04-14
- **Relation property writes** — `+row`, `urow`, and `u <rowID>` now write to `relation` columns. Values are comma-separated page references (short ID, dashed UUID, or dashless UUID); a single relation is `Who=N2jf`, multi-target is `Tags=N2jf, R4kQ`. Previously `_build_property_value` had no case for `"relation"` and returned `None`, so the row builder silently skipped relation columns — `+row ... Who=N2jf` reported `ok` but the relation was empty, and `urow` / `u` returned `No valid properties to update` even when a valid relation was in the payload.
- **No more silent drops in row-property builds** — `_build_row_properties` now returns `(props, unresolved)`, where `unresolved` lists every input key that didn't apply (unknown column, or value that couldn't be converted for the column's type). `+row`, `urow`, and `u <rowID>` all surface `ROW_UPDATE_NO_MATCH` with a per-key explanation (e.g. `unknown column 'Who' (available: Date, Name)` or `column 'Count' (number): value 'x' couldn't be converted`). This makes failures like the relation-write bug impossible to miss — previously the relation-missing bug went unnoticed across many sessions because the error was hidden behind a generic "No valid properties to update" message.
### v0.3.0 — 2026-04-11
- **`@b:shortID` block mentions** — inline references to specific blocks now parse and render as links to the block's Notion URL. Works in paragraphs, bullets, and table cells (the original scenario where the bug was reported — table cells use the same parse pipeline as everything else, so fixing `@b:` at the parser level fixes tables for free). Also supports `[custom text](b:shortID)` explicit link syntax.
- **`u <rowID>` as a synonym for `urow`** — calling `u` on a database row now auto-routes to row-property update semantics (parse the tab-separated `key=value` payload, match columns, PATCH the row). Previously `u` on a row silently overwrote the Name/title with the raw payload string, quietly corrupting contact records and similar databases across many sessions.
- **Quoted keys in row updates** — `"Last contact"=2026-04-10\t"Last platform"=WhatsApp` (the natural form when column names have spaces) now parses correctly. Surrounding double quotes are stripped from both keys and values. Previously keys kept their literal quotes and never matched any column, making the update a silent no-op.
- **Database rename via `upage` / `u`** — `upage <dbID> = "New Name" icon=📚` and `u <dbShortID> = "New Name"` now correctly `PATCH /databases/{id}` with the Notion databases API's top-level `title` rich_text shape. Previously both routed to `/pages/{id}` and returned 404 for database UUIDs.
- **Clean refusal for database moves** — `m` or `mpage` on a database now returns `DB_MOVE_UNSUPPORTED` with a pointer to the Notion UI. The Notion API has no way to move databases programmatically; previously callers hit the move endpoint and got a raw validation error.
- **`notion_read` dispatch for block-level refs** — reading a block short ID (toggle, bullet, heading) now correctly falls through `/pages/` → `/databases/` → `/blocks/` on 400 responses, not just 404. Previously Notion's "Provided database_id..." validation error short-circuited with `HTTP_ERROR`, forcing agents to re-read entire parent pages to verify a single child.
- **`cpage` surfaces the new page short ID** — copy operations now return the new page's short ID in the apply result (`+SHORT_ID`), so follow-up ops like `mpage <copyID> -> parent=<originalID>` have a target. Previously `cpage` returned just `ok`, making the copy unreachable in the same batch.
- **Pipe rows missing outer pipes warn** — content like `Camp | For | Ages` (intended as a table row but missing the leading/trailing pipes) now emits a warning explaining why it became a paragraph instead of a table. Joins the existing `@table` and bare-`!table` guardrail warnings.
- **All apply-script parse errors surface** — submitting multiple invalid commands in one script now reports one error per bad line. Previously `execute_apply_script` grabbed `parse_result.errors[0]` and silently dropped the rest, hiding anything past the first mistake.
### v0.2.0 — 2026-03-31
- **Flexible update syntax** — `u`/`e` now accepts three forms: quoted (`u ID = "text"`), unquoted (`u ID = text`), and indented (`u ID` with content on the next indented line). Previously only quoted was supported.
- **Syntax error hints** — when a known command is used with wrong syntax, the error now shows the expected format and an example, instead of reporting it as an unknown command.
- **Code fence language with spaces** — code blocks now accept multi-word language hints (e.g., `` ```plain text ``), which were previously rejected.
- **Server version in auth check** — `notion_check_auth` now includes the server version (from pyproject.toml) in its response for easier debugging.
### v0.1.3 — 2026-03-30
- **Null-field stripping on write** — block data returned by the Notion API sometimes contains `null`-valued fields (e.g., `icon: null`). These are now stripped before writing, since the API rejects explicit nulls but accepts absent fields. Fixes errors when cloning or moving certain block types.
### v0.1.2 — 2026-03-29
- **`e` alias for block updates** — `e ID = "text"` is now accepted as an alias for `u`, matching natural "edit" intent.
- **`help` command** — `script="help"` returns a compact command reference without executing anything.
- **Smarter unknown-command errors** — unrecognized commands now get fuzzy-matched against valid commands and common natural-language aliases (e.g., `edit` → `u`, `delete` → `x`), with "did you mean?" suggestions.
- **Explicit `!table N` child rows** — when using `!table N` with indented pipe rows, the rows are now correctly attached as children of the explicit table block instead of being wrapped in a second synthetic table.
- **Table creation guardrails** — warnings for common mistakes: `@table` (read-only format, not a write command), `!table` without a column count, and pipe rows missing outer pipes.
- **Typed creation responses** — `+` results now include block types (e.g., `+A1b2(paragraph) +C3d4(to_do)`), with a type summary in the footer.
- **Parse error suggestions** — error messages now include suggestion text inline, so the fix is visible without inspecting the structured error.
### v0.1.1 — 2026-03-14
- **Equation syntax** — inline equations now use `:eq[expr]` directive instead of `$expr$`. Dollar signs are treated as literal text, so `$50` no longer triggers equation parsing.
- **Stable move IDs** — moving a block preserves its short ID instead of assigning a new one, so references to moved blocks remain valid.
- **`+db` response metadata** — `+db` results now include the database short ID and property names (e.g., `+db=7QI8 props: Name, Status, Due`).
- **`+row` response format** — `+row` results now return created IDs as a list, consistent with other creation commands.
- **ID registry reassign** — new `reassign()` method on the ID registry supports re-pointing a short ID to a different UUID, used internally by move operations.
### v0.1.0 — 2026-02-20
- **Missing payload diagnostics** — `+row`, `urow`, and `+db` now detect missing or non-indented payloads and produce actionable error messages with autofix suggestions, instead of silently accepting incomplete commands.
- **Sequential schema execution** — consecutive schema operations (`+prop`, `xprop`, `uprop`) on the same database now execute sequentially to avoid race conditions, using the same chaining mechanism as consecutive moves.
- **Expanded tool docstrings** — `notion.read` and `notion.apply` docstrings updated with table operations, relative date filter examples, typed refs, and clearer parameter descriptions.
### v0.0.3 — 2026-02-17
- **Database creation and management** — `+db` creates databases with typed property definitions, `+prop` adds properties, `xprop` deletes properties, and `uprop` renames properties. Property definitions use a compact `Name(type: config)` syntax supporting select options, number formats, relation targets, and dual relations.
- **Full table support** — tables are no longer opaque placeholders. They render as pipe-delimited rows (`| cell | cell |`) with full read/write roundtrip. Consecutive table rows auto-group into a table parent, and Markdown separator rows are silently dropped.
- **Structural block notation** — column layouts and tables use a new `!type N` notation (`!cols 3`, `!col 1`, `!table 4`) that exposes their structure for editing, replacing the old opaque rendering of columns.
- **Page positioning** — `+page` now accepts `after=<block_id>` and `pos=start` to control where new pages appear within their parent.
- **Variable-length code fences** — code blocks now support 3+ backticks, with the closing fence required to match the opening length.
- **Improved `!`-prefix disambiguation** — callout, opaque, and structural blocks all start with `!` and are now disambiguated in a clear priority order: colored callouts → opaque (`!type~`) → structural (`!type N`) → default callout.
- **Auto-refresh install** — the recommended `uvx` config now includes `--refresh` so Claude Code always uses the latest version.
### v0.0.2 — 2026-02-14
- **Better searching and filtering over databases** — `notion_read` now accepts `filter`, `sort`, and `columns` parameters. The filter DSL supports comparison operators (`=`, `!=`, `~`, `!~`, `<`, `>`, `<=`, `>=`), unary checks (`?` empty, `!?` not empty), boolean logic (`&`, `|`), parenthesized grouping, quoted property names, and relative dates (`-14d`). Sort takes compact specs like `Due desc, Status asc`. Columns selects which properties to return (`Name, Status, Due`). Schema-aware compilation validates property names and coerces types.
- **Parallel reads** — each entry in the `pages` list can now override `depth`, `limit`, `filter`, `sort`, and `columns` independently, enabling batch reads that mix pages and filtered databases in a single call.
- **More block type coverage** — database mentions, `link_mention` (rich URL embeds), `link_preview` (integration embeds), and `template_mention` types are now rendered instead of silently dropped. Annotations (bold, italic, color, etc.) are applied to mention output. Page and row icons (emoji or external URL) are included in NBJM output.
- **Better move semantics** — moving blocks that contain Notion-hosted files (images, videos, PDFs) now re-uploads the file via the File Upload API to get a permanent reference. Move commands pre-flight check whether a block can be moved, returning clear errors for synced blocks, tables, breadcrumbs, and other non-portable types. Consecutive moves to the same parent execute sequentially with auto-chaining to preserve script order. `m X -> after=Y` without `parent=` now returns a helpful error instead of silently failing.
- **Renamed MCP config key** — the recommended key in `.mcp.json` / `settings.json` is now `nbjm-mcp` (was `notion-mcp`), to avoid conflicts with other Notion MCP servers.
## License
Apache 2.0