Add Notion integration for read-only workspace access#182
Add Notion integration for read-only workspace access#182benvinegar merged 3 commits intomodem-dev:mainfrom
Conversation
Greptile SummaryThis PR adds a well-structured read-only Notion integration that enables Baudbot agents to access workspace documentation. The implementation follows established patterns from Key Changes:
Notable Implementation Details:
Documentation Quality:
The implementation is production-tested and ready to merge. One minor suggestion for ID validation has been noted as a best practice improvement. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent as Baudbot Agent
participant Ext as notion.ts Extension
participant API as Notion REST API
participant Page as Notion Workspace
Note over Agent,Page: Search Action
Agent->>Ext: notion({action: "search", query: "..."})
Ext->>API: POST /search
API->>Page: Query pages/databases
Page-->>API: Results
API-->>Ext: JSON response
Ext-->>Agent: Formatted list with titles, URLs
Note over Agent,Page: Get Page Content Action
Agent->>Ext: notion({action: "get", page_id: "..."})
Ext->>API: GET /pages/{id}
API-->>Ext: Page metadata
Ext->>API: GET /blocks/{id}/children
API->>Page: Fetch blocks
Page-->>API: Block content
API-->>Ext: Blocks JSON
loop For blocks with children
Ext->>API: GET /blocks/{child_id}/children
API-->>Ext: Nested blocks
end
Ext-->>Agent: Markdown formatted content
Note over Agent,Page: Database Query Action
Agent->>Ext: notion({action: "list", database_id: "...", filter: "..."})
Ext->>API: POST /databases/{id}/query
API->>Page: Query with filters
Page-->>API: Database rows
API-->>Ext: JSON entries
Ext-->>Agent: Formatted entries with properties
Note over Agent,Page: Database Schema Action
Agent->>Ext: notion({action: "database", database_id: "..."})
Ext->>API: GET /databases/{id}
API->>Page: Get schema
Page-->>API: Database structure
API-->>Ext: Properties metadata
Ext-->>Agent: Property list with types
Last reviewed commit: d45915b |
pi/extensions/notion.ts
Outdated
| // Remove hyphens from page_id if present (Notion accepts both formats) | ||
| const pageId = params.page_id.replace(/-/g, ""); |
There was a problem hiding this comment.
ID sanitization without validation - consider validating that the result is a 32-character hex string after removing hyphens to prevent potential API errors from malformed inputs
| // Remove hyphens from page_id if present (Notion accepts both formats) | |
| const pageId = params.page_id.replace(/-/g, ""); | |
| const pageId = params.page_id.replace(/-/g, ""); | |
| if (!/^[a-f0-9]{32}$/i.test(pageId)) { | |
| return "❌ page_id must be a valid Notion page ID (32 hex characters)"; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: pi/extensions/notion.ts
Line: 180-181
Comment:
ID sanitization without validation - consider validating that the result is a 32-character hex string after removing hyphens to prevent potential API errors from malformed inputs
```suggestion
const pageId = params.page_id.replace(/-/g, "");
if (!/^[a-f0-9]{32}$/i.test(pageId)) {
return "❌ page_id must be a valid Notion page ID (32 hex characters)";
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Added validation after ID normalization and reused it across get, list, and database. Inputs now return a clear error unless they normalize to a 32-character hex Notion ID.
Responded by pi-coding-agent using openai/gpt-5.
Add notion.ts extension providing read-only access to Notion workspaces via the Notion REST API. Enables agents to search for pages/databases, retrieve full page content with nested blocks, query database entries with filters, and inspect database schemas. Features: - Search: Find pages and databases by text query or type filter - Get: Retrieve complete page content formatted as markdown, including paragraphs, headings, lists, code blocks, callouts, and nested content (up to 1 level deep) - List: Query database entries with JSON filters and sorting - Database: Inspect schema and property types Configuration: - NOTION_API_KEY (internal integration token) in ~/.config/.env - Pages/databases must be explicitly shared with the integration - Read-only access (no write, update, or delete capabilities) Documentation: - Updated .env.schema with NOTION_API_KEY configuration - Updated CONFIGURATION.md with setup instructions and capabilities - Added comprehensive docs/notion-integration.md covering setup, usage examples, use cases, limitations, security, and troubleshooting Use cases: - Documentation lookup during task execution - Specification and ADR retrieval for dev-agents - Project database queries for task context The integration follows the same pattern as existing extensions (linear.ts, sentry-monitor.ts) and includes proper error handling, type safety, and security considerations (token stored in 600-perms env file, read-only access enforced by API capabilities). Tested with TypeScript compilation (no errors) and biome linting (clean).
d45915b to
a477d4b
Compare
7b7001c to
2c4f46a
Compare
Overview
This PR contributes a new Notion extension that provides read-only access to Notion workspaces via the Notion REST API. We built and tested this integration in our production Baudbot deployment and are contributing it back upstream.
Features
The
notiontool provides four key actions:🔍 Search
Find pages and databases by text query or filter by object type:
📄 Get
Retrieve complete page content formatted as markdown:
🗂️ List
Query database entries with advanced filtering:
🔬 Database
Inspect database schemas:
Use Cases
Documentation Lookup
Control agents can retrieve setup guides, API references, and runbooks during task execution:
Specification Retrieval
Dev-agents can read PRDs and architecture decision records:
Project Database Queries
Query task databases for context on current work:
Configuration
Required Environment Variable
Setup Steps
~/.config/.envSecurity
✅ Read-only access — Cannot create, update, or delete content
✅ Explicit sharing required — Only sees pages/databases shared with the integration
✅ Token stored securely —
~/.config/.envwith 600 permissions✅ No credentials leaked — Verified clean of all workspace-specific IDs and tokens
✅ Follows existing patterns — Matches security model of
linear.tsandsentry-monitor.tsTesting
✅ TypeScript compilation: Clean (
npm run typecheck)✅ Biome linting: No warnings (
npx biome lint pi/extensions/notion.ts)✅ Existing test suite: No regressions (same failures as upstream main)
✅ Production tested: Used in our live Baudbot deployment since Feb 26, 2026
Files Changed
pi/extensions/notion.ts— Main extension implementation (~400 LOC).env.schema— AddedNOTION_API_KEYconfigurationCONFIGURATION.md— Added Notion Integration section with setup instructionsdocs/notion-integration.md— Comprehensive documentation (setup, usage, troubleshooting)Implementation Details
Architecture
2022-06-28)Block Content Formatting
Supports all major Notion block types with markdown conversion:
API Efficiency
has_childrenis trueLimitations
📋 Read-only — By design, no write operations
📋 Pagination — Limited to 100 results per query (no auto-pagination)
📋 Nesting depth — Child blocks fetched 1 level deep only
📋 Access control — Integration must be explicitly added to each page
All limitations are documented in
docs/notion-integration.md.Documentation
Added comprehensive documentation covering:
Why This Matters
Many engineering teams keep critical documentation in Notion:
This extension lets Baudbot agents access that context during autonomous work, improving code quality and reducing the need for human intervention.
Contribution Notes
fetchAPI)linear.ts,sentry-monitor.ts)We're using this in production and would love to see it land upstream so other Baudbot users can benefit! 🚀