notion-mcp-sidecar
by Camel031
README.md
# notion-mcp-sidecar
A small MCP server that gives a chat assistant narrow, validated access to two Notion databases: an Inbox and a TODO list. I run it next to a [Hermes](https://github.com/NousResearch/hermes-agent) agent that I talk to over LINE, so I can say "remind me to hand in the report by Friday" and get a Notion todo with the right project and due date. The assistant gets three tools and nothing else; it can't read the rest of the workspace, delete pages, or create new select options.

The screenshot is the output of `scripts/demo_fake_notion.py`, which starts the real server on a loopback port with the test suite's Notion fake behind it and calls each tool over Streamable HTTP.
## Tools
| Tool | What it does | Notion access |
|---|---|---|
| `notion_inbox_add` | Records one chat message in the Inbox. When `kind` is `todo`, also creates a linked TODO item with project, urgency, priority and due date. Calling it again with the same message on the same day returns the existing entry. | Query and create in the two data sources; update the new Inbox row to link the todo |
| `notion_todo_query` | Lists open TODO items, soonest hard deadline first, filtered by project or by "due within N days". Returns `has_more` when the list is cut off. | Query the TODO data source |
| `notion_todo_set_status` | Changes the status of one TODO item. | Read the page, check it belongs to the TODO data source, update one property |
## Validation model
The design goal is that a confused or manipulated model can't do much damage through these tools.
- Closed vocabularies: Kind, project, urgency, priority and status are `Literal` types, so they appear as enums in the tool's JSON schema and the MCP layer rejects anything else before any Notion call is made. Free text is limited to the title (200 characters), the raw message (5000) and a `YYYY-MM-DD` date.
- Startup schema check: Before serving, the sidecar fetches both data sources, checks that every property exists with the expected type, and resolves every vocabulary label to its Notion option id. A missing property or option stops startup with an error that names it. Labels match after leading symbols such as emoji are stripped and case is folded, so an option named with an emoji prefix still matches its plain label.
- Writes by option id: Select and status values are always sent as ids, never names. Notion creates a new option when it receives an unknown name; sending ids means a bad value can't add options to the database.
- Scoped updates: `notion_todo_set_status` reads the page first and refuses it unless its parent is the configured TODO data source.
- De-duplication: Hermes doesn't pass the LINE message id to MCP tools, so the dedup key is a hash of the normalized message and the Asia/Taipei calendar day. A capture that failed halfway (Inbox row created, todo not linked) is completed on retry instead of duplicated; for that purpose the todo's Note ends with a dedup marker in the format `[butler:<key>]` (the prefix is kept for compatibility with existing pages).
- Loopback and a bearer token: The server only binds to `127.0.0.1` or `localhost`, and an ASGI middleware requires `Authorization: Bearer <SIDECAR_TOKEN>` on every HTTP request; WebSocket and unknown ASGI scopes are refused. Tokens must be printable ASCII (so they can't leak into an httpx header error) and are hidden from `repr`.
- No escape hatches in the code: Two tests (`tests/test_forbidden_calls.py` and `tests/test_forbidden_ast.py`) scan the package for process execution, `eval`/`exec`, dynamic imports and Notion's trash and archive fields, and check imports against an allowlist, so adding a new capability has to be done on purpose.
## Configuration
Settings live in a private env file outside the repository, `~/.config/notion-mcp-sidecar/sidecar.env` by default (override with `NOTION_SIDECAR_ENV`):
```ini
SIDECAR_TOKEN=<long random string shared with the MCP client>
NOTION_TOKEN=<Notion internal integration token>
NOTION_INBOX_DS_ID=<Inbox data source id>
NOTION_TODO_DS_ID=<TODO List data source id>
# optional
SIDECAR_HOST=127.0.0.1
SIDECAR_PORT=8721
```
Share both databases with the integration. In Notion, a database's data source id is under the database menu, Manage data sources, Copy data source ID; `scripts/show_data_source.py database <database_id>` lists them too.
The property names and option labels the sidecar expects are in `src/notion_mcp_sidecar/options.py`. The project and priority lists there are examples; edit them to match your own database, and run `uv run python scripts/show_data_source.py schema <data_source_id>` to see what your data source has. The client is pinned to Notion API version 2026-03-11.
## Running
Requires Python 3.11 to 3.13 and [uv](https://docs.astral.sh/uv/).
```bash
uv sync
uv run python -m notion_mcp_sidecar
```
The server logs `schemas verified; serving MCP on http://127.0.0.1:8721/mcp` and then accepts Streamable HTTP MCP connections. To check a running instance end to end, `uv run python scripts/mcp_smoke.py` connects with the token the way Hermes does, adds one Inbox note three times (expecting the second and third to be deduplicated) and checks that an invented project is rejected.
### Hermes setup
`deploy/hermes/apply_config.py` merges the settings I use into Hermes's `config.yaml` while keeping its comments, and writes a timestamped backup first. `--mode base` restricts the agent to a few built-in toolsets (clarify, memory, todo, session_search, web) and disables the rest (terminal, file, code execution, browser and so on); `--mode sidecar` also registers this sidecar as an MCP server and adds capture instructions to the system prompt. `scripts/check_tool_surface.py --platform line` reads `hermes prompt-size --json` and fails if any toolset outside that allowlist is exposed.
## Tests
```bash
uv run pytest
```
166 tests, no network. `tests/fake_notion.py` is an in-memory Notion that mirrors the API's behavior closely enough to matter here (including creating an option when it receives an unknown select name, which is what the id-only writes guard against) and supports failure injection for the retry paths.
## Status
This runs for one user on one machine. The vocabularies are fixed in code rather than read from config, there is no per-user separation, and the dedup key treats the same message sent twice on one day as a single capture.
## License
MIT, see [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues