fix(notion): align integration with live API docs, add block retrieval coverage (#5491)

* fix(notion): align integration with live API docs, add block retrieval coverage

- wire up notion_update_page in the block (was registered but unreachable — no dropdown option or subBlocks)
- fix legacy NotionBlock outputs to cover all 17 operations, not just content/metadata
- trim ID params (pageId, databaseId, parentId) before use in request URLs across 8 tool files
- remove content required:true on create_page (Notion allows title-only pages)
- remove dead unused NotionReadDatabaseParams interface
- add notion_retrieve_block/_v2 tool for GET /v1/blocks/{id}, filling a gap in block CRUD coverage

* fix(notion): second validation pass — pagination gaps, phantom outputs, dead types, regen docs

- add missing startCursor/start_cursor pagination param to notion_query_database and notion_search
- fix notion_search missing from the shared pageSize/startCursor field's operation condition in NotionBlock
- fix NotionV2Block title/url/created_time/last_edited_time outputs rendering unconditionally for every operation instead of only the ones that return them
- remove 153 lines of dead unused output-shape constants from types.ts
- regenerate integration docs

* fix(notion): expose retrieve-block outputs in legacy block picker

type/block/archived only conditioned on notion_update_block/notion_delete_block,
and has_children was missing entirely — Retrieve Block's payload was invisible
in the legacy NotionBlock output picker (Greptile P1 on PR #5491).

* fix(notion): document type-specific content gap on retrieve_block output

block.properties (BLOCK_OUTPUT_PROPERTIES) only covers common block fields,
not the type-specific sub-object (paragraph.rich_text, image.file, etc.) —
that varies per block type and isn't enumerable. Documented in the
description per Greptile P2 on PR #5491; no functional change, block: data
already carries the full object at runtime.
This commit is contained in:
Waleed
2026-07-07 13:57:33 -07:00
committed by GitHub
parent ed1492bcbd
commit 61ceedc5b9
15 changed files with 458 additions and 197 deletions
@@ -145,6 +145,7 @@ Query and filter Notion database entries with advanced filtering
| `filter` | string | No | Filter conditions as JSON \(optional\) |
| `sorts` | string | No | Sort criteria as JSON array \(optional\) |
| `pageSize` | number | No | Number of results to return \(default: 100, max: 100\) |
| `startCursor` | string | No | Pagination cursor returned by a previous request |
#### Output
@@ -200,6 +201,7 @@ Search across all pages and databases in Notion workspace
| `query` | string | No | Search terms to find pages and databases \(leave empty to get all pages\) |
| `filterType` | string | No | Filter by object type: "page", "database", or leave empty for all |
| `pageSize` | number | No | Number of results to return \(default: 100, max: 100\) |
| `startCursor` | string | No | Pagination cursor returned by a previous request |
#### Output
@@ -302,8 +304,44 @@ Append new block children (content) to a Notion page or block
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
| `email` | string | User email address \(person users only\) |
### `notion_retrieve_block`
Retrieve a single Notion block by its UUID, including its type-specific content
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `blockId` | string | Yes | The UUID of the block to retrieve |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `content` | string | Page content in markdown format, or comment text for create comment |
| `title` | string | Page or database title |
| `url` | string | Notion URL |
| `id` | string | Page, database, block, comment, or user ID |
| `created_time` | string | Creation timestamp |
| `last_edited_time` | string | Last edit timestamp |
| `results` | array | Array of results \(pages, blocks, comments, or users\) |
| `has_more` | boolean | Whether more results are available |
| `next_cursor` | string | Cursor for pagination |
| `total_results` | number | Number of results returned |
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -338,8 +376,9 @@ Retrieve the block children (content) of a Notion page or block
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -374,8 +413,9 @@ Update the content or archived state of a single Notion block
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -408,8 +448,9 @@ Delete (move to trash) a single Notion block
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -444,8 +485,9 @@ Create a comment on a Notion page or within an existing discussion thread
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -480,8 +522,9 @@ List unresolved comments on a Notion page or block
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -515,8 +558,9 @@ List all users (members and bots) in the Notion workspace
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
@@ -549,8 +593,9 @@ Retrieve a single Notion user by their UUID
| `properties` | json | Database properties schema |
| `appended` | boolean | Whether content was successfully appended |
| `type` | string | Block type |
| `block` | json | The full updated Notion block object |
| `archived` | boolean | Whether the block was archived |
| `block` | json | The full Notion block object |
| `has_children` | boolean | Whether the block has nested blocks |
| `archived` | boolean | Whether the block is archived |
| `discussion_id` | string | Discussion thread ID |
| `name` | string | User display name |
| `avatar_url` | string | User avatar image URL |
+249 -15
View File
@@ -30,10 +30,12 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
{ label: 'Read Page', id: 'notion_read' },
{ label: 'Read Database', id: 'notion_read_database' },
{ label: 'Create Page', id: 'notion_create_page' },
{ label: 'Update Page Properties', id: 'notion_update_page' },
{ label: 'Create Database', id: 'notion_create_database' },
{ label: 'Add Database Row', id: 'notion_add_database_row' },
{ label: 'Append Content', id: 'notion_write' },
{ label: 'Append Block Children', id: 'notion_append_blocks' },
{ label: 'Retrieve Block', id: 'notion_retrieve_block' },
{ label: 'Retrieve Block Children', id: 'notion_retrieve_block_children' },
{ label: 'Update Block', id: 'notion_update_block' },
{ label: 'Delete Block', id: 'notion_delete_block' },
@@ -77,7 +79,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
mode: 'basic',
condition: {
field: 'operation',
value: ['notion_read', 'notion_write'],
value: ['notion_read', 'notion_write', 'notion_update_page'],
},
required: true,
},
@@ -91,7 +93,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
mode: 'advanced',
condition: {
field: 'operation',
value: ['notion_read', 'notion_write'],
value: ['notion_read', 'notion_write', 'notion_update_page'],
},
required: true,
},
@@ -192,7 +194,6 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
field: 'operation',
value: 'notion_create_page',
},
required: true,
wandConfig: {
enabled: true,
prompt:
@@ -243,6 +244,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
'notion_retrieve_block_children',
'notion_list_comments',
'notion_list_users',
'notion_search',
],
},
},
@@ -318,6 +320,22 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
generationType: 'json-object',
},
},
{
id: 'properties',
title: 'Properties to Update',
type: 'code',
placeholder: 'Enter page properties as JSON object',
condition: { field: 'operation', value: 'notion_update_page' },
required: true,
wandConfig: {
enabled: true,
prompt:
'Generate Notion page properties to update in JSON format based on the user\'s description. Properties must match the parent database schema. Common formats: Title: {"Name": {"title": [{"text": {"content": "Value"}}]}}, Text: {"Description": {"rich_text": [{"text": {"content": "Value"}}]}}, Number: {"Price": {"number": 10}}, Select: {"Status": {"select": {"name": "Done"}}}, Multi-select: {"Tags": {"multi_select": [{"name": "Tag1"}]}}, Date: {"Due": {"date": {"start": "2024-01-01"}}}, Checkbox: {"Done": {"checkbox": true}}. Return ONLY valid JSON - no explanations.',
placeholder:
'Describe the properties to update (e.g., "set status to Done, priority to High")...',
generationType: 'json-object',
},
},
{
id: 'blockId',
title: 'Page or Block ID',
@@ -328,6 +346,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
field: 'operation',
value: [
'notion_append_blocks',
'notion_retrieve_block',
'notion_retrieve_block_children',
'notion_update_block',
'notion_delete_block',
@@ -433,7 +452,13 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
mode: 'advanced',
condition: {
field: 'operation',
value: ['notion_retrieve_block_children', 'notion_list_comments', 'notion_list_users'],
value: [
'notion_retrieve_block_children',
'notion_list_comments',
'notion_list_users',
'notion_query_database',
'notion_search',
],
},
},
],
@@ -449,6 +474,7 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
'notion_add_database_row',
'notion_update_page',
'notion_append_blocks',
'notion_retrieve_block',
'notion_retrieve_block_children',
'notion_update_block',
'notion_delete_block',
@@ -480,6 +506,8 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
return 'notion_add_database_row'
case 'notion_append_blocks':
return 'notion_append_blocks'
case 'notion_retrieve_block':
return 'notion_retrieve_block'
case 'notion_retrieve_block_children':
return 'notion_retrieve_block_children'
case 'notion_update_block':
@@ -519,7 +547,8 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
if (
(operation === 'notion_create_page' ||
operation === 'notion_create_database' ||
operation === 'notion_add_database_row') &&
operation === 'notion_add_database_row' ||
operation === 'notion_update_page') &&
properties
) {
if (typeof properties === 'string') {
@@ -651,17 +680,169 @@ export const NotionBlock: BlockConfig<NotionResponse> = {
userId: { type: 'string', description: 'User identifier' },
},
outputs: {
// Common outputs across all Notion operations
// Outputs for the original content/metadata-shaped operations
content: {
type: 'string',
description: 'Page content, search results, or confirmation messages',
description: 'Page content, comment text, search results, or confirmation messages',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_write',
'notion_create_page',
'notion_update_page',
'notion_query_database',
'notion_search',
'notion_create_database',
'notion_read_database',
'notion_create_comment',
],
},
},
// Metadata object containing operation-specific information
metadata: {
type: 'json',
description:
'Metadata containing operation-specific details including page/database info, results, and pagination data',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_write',
'notion_create_page',
'notion_update_page',
'notion_query_database',
'notion_search',
'notion_create_database',
'notion_read_database',
],
},
},
// Outputs for the API-aligned flat-shaped operations added after the legacy block was hidden
id: {
type: 'string',
description: 'Row, block, comment, or user ID',
condition: {
field: 'operation',
value: [
'notion_add_database_row',
'notion_retrieve_block',
'notion_update_block',
'notion_delete_block',
'notion_create_comment',
'notion_retrieve_user',
],
},
},
url: {
type: 'string',
description: 'Notion page URL',
condition: { field: 'operation', value: 'notion_add_database_row' },
},
title: {
type: 'string',
description: 'Row title',
condition: { field: 'operation', value: 'notion_add_database_row' },
},
created_time: {
type: 'string',
description: 'Creation timestamp',
condition: {
field: 'operation',
value: ['notion_add_database_row', 'notion_create_comment'],
},
},
last_edited_time: {
type: 'string',
description: 'Last edit timestamp',
condition: { field: 'operation', value: 'notion_add_database_row' },
},
results: {
type: 'array',
description: 'Array of results (blocks, comments, or users)',
condition: {
field: 'operation',
value: [
'notion_append_blocks',
'notion_retrieve_block_children',
'notion_list_comments',
'notion_list_users',
],
},
},
has_more: {
type: 'boolean',
description: 'Whether more results are available',
condition: {
field: 'operation',
value: [
'notion_append_blocks',
'notion_retrieve_block_children',
'notion_list_comments',
'notion_list_users',
],
},
},
next_cursor: {
type: 'string',
description: 'Cursor for pagination',
condition: {
field: 'operation',
value: [
'notion_append_blocks',
'notion_retrieve_block_children',
'notion_list_comments',
'notion_list_users',
],
},
},
type: {
type: 'string',
description: 'Block type',
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
},
block: {
type: 'json',
description: 'The full Notion block object',
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
},
has_children: {
type: 'boolean',
description: 'Whether the block has nested blocks',
condition: { field: 'operation', value: 'notion_retrieve_block' },
},
archived: {
type: 'boolean',
description: 'Whether the block is archived',
condition: {
field: 'operation',
value: ['notion_retrieve_block', 'notion_update_block', 'notion_delete_block'],
},
},
discussion_id: {
type: 'string',
description: 'Discussion thread ID',
condition: { field: 'operation', value: 'notion_create_comment' },
},
rich_text: {
type: 'json',
description: 'Rich text array of the comment',
condition: { field: 'operation', value: 'notion_create_comment' },
},
name: {
type: 'string',
description: 'User display name',
condition: { field: 'operation', value: 'notion_retrieve_user' },
},
avatar_url: {
type: 'string',
description: 'User avatar image URL',
condition: { field: 'operation', value: 'notion_retrieve_user' },
},
email: {
type: 'string',
description: 'User email address (person users only)',
condition: { field: 'operation', value: 'notion_retrieve_user' },
},
},
}
@@ -721,6 +902,7 @@ export const NotionV2Block: BlockConfig<any> = {
'notion_create_database_v2',
'notion_add_database_row_v2',
'notion_append_blocks_v2',
'notion_retrieve_block_v2',
'notion_retrieve_block_children_v2',
'notion_update_block_v2',
'notion_delete_block_v2',
@@ -749,10 +931,32 @@ export const NotionV2Block: BlockConfig<any> = {
title: {
type: 'string',
description: 'Page or database title',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_create_page',
'notion_update_page',
'notion_create_database',
'notion_read_database',
'notion_add_database_row',
],
},
},
url: {
type: 'string',
description: 'Notion URL',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_create_page',
'notion_update_page',
'notion_create_database',
'notion_read_database',
'notion_add_database_row',
],
},
},
id: {
type: 'string',
@@ -765,6 +969,7 @@ export const NotionV2Block: BlockConfig<any> = {
'notion_add_database_row',
'notion_read_database',
'notion_update_page',
'notion_retrieve_block',
'notion_update_block',
'notion_delete_block',
'notion_create_comment',
@@ -775,10 +980,31 @@ export const NotionV2Block: BlockConfig<any> = {
created_time: {
type: 'string',
description: 'Creation timestamp',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_create_page',
'notion_create_database',
'notion_read_database',
'notion_add_database_row',
'notion_create_comment',
],
},
},
last_edited_time: {
type: 'string',
description: 'Last edit timestamp',
condition: {
field: 'operation',
value: [
'notion_read',
'notion_create_page',
'notion_update_page',
'notion_read_database',
'notion_add_database_row',
],
},
},
// List/query/search outputs
results: {
@@ -843,21 +1069,29 @@ export const NotionV2Block: BlockConfig<any> = {
description: 'Whether content was successfully appended',
condition: { field: 'operation', value: 'notion_write' },
},
// Block update/delete outputs
// Block retrieve/update/delete outputs
type: {
type: 'string',
description: 'Block type',
condition: { field: 'operation', value: 'notion_update_block' },
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
},
block: {
type: 'json',
description: 'The full updated Notion block object',
condition: { field: 'operation', value: 'notion_update_block' },
description: 'The full Notion block object',
condition: { field: 'operation', value: ['notion_retrieve_block', 'notion_update_block'] },
},
has_children: {
type: 'boolean',
description: 'Whether the block has nested blocks',
condition: { field: 'operation', value: 'notion_retrieve_block' },
},
archived: {
type: 'boolean',
description: 'Whether the block was archived',
condition: { field: 'operation', value: ['notion_update_block', 'notion_delete_block'] },
description: 'Whether the block is archived',
condition: {
field: 'operation',
value: ['notion_retrieve_block', 'notion_update_block', 'notion_delete_block'],
},
},
// Comment outputs
discussion_id: {
+1 -1
View File
@@ -67,7 +67,7 @@ export const notionAddDatabaseRowTool: ToolConfig<
return {
parent: {
type: 'database_id',
database_id: params.databaseId,
database_id: params.databaseId.trim(),
},
properties: params.properties,
}
+1 -1
View File
@@ -65,7 +65,7 @@ export const notionCreateDatabaseTool: ToolConfig<NotionCreateDatabaseParams, No
const body = {
parent: {
type: 'page_id',
page_id: params.parentId,
page_id: params.parentId.trim(),
},
title: [
{
+1 -1
View File
@@ -58,7 +58,7 @@ export const notionCreatePageTool: ToolConfig<NotionCreatePageParams, NotionResp
const body: any = {
parent: {
type: 'page_id',
page_id: params.parentId,
page_id: params.parentId.trim(),
},
}
+3
View File
@@ -15,6 +15,7 @@ import { notionListUsersTool, notionListUsersV2Tool } from '@/tools/notion/list_
import { notionQueryDatabaseTool, notionQueryDatabaseV2Tool } from '@/tools/notion/query_database'
import { notionReadTool, notionReadV2Tool } from '@/tools/notion/read'
import { notionReadDatabaseTool, notionReadDatabaseV2Tool } from '@/tools/notion/read_database'
import { notionRetrieveBlockTool, notionRetrieveBlockV2Tool } from '@/tools/notion/retrieve_block'
import {
notionRetrieveBlockChildrenTool,
notionRetrieveBlockChildrenV2Tool,
@@ -37,6 +38,7 @@ export {
notionCreateDatabaseTool,
notionAddDatabaseRowTool,
notionAppendBlocksTool,
notionRetrieveBlockTool,
notionRetrieveBlockChildrenTool,
notionUpdateBlockTool,
notionDeleteBlockTool,
@@ -55,6 +57,7 @@ export {
notionCreateDatabaseV2Tool,
notionAddDatabaseRowV2Tool,
notionAppendBlocksV2Tool,
notionRetrieveBlockV2Tool,
notionRetrieveBlockChildrenV2Tool,
notionUpdateBlockV2Tool,
notionDeleteBlockV2Tool,
+12 -1
View File
@@ -46,11 +46,17 @@ export const notionQueryDatabaseTool: ToolConfig<NotionQueryDatabaseParams, Noti
visibility: 'user-or-llm',
description: 'Number of results to return (default: 100, max: 100)',
},
startCursor: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Pagination cursor returned by a previous request',
},
},
request: {
url: (params: NotionQueryDatabaseParams) => {
return `https://api.notion.com/v1/databases/${params.databaseId}/query`
return `https://api.notion.com/v1/databases/${params.databaseId.trim()}/query`
},
method: 'POST',
headers: (params: NotionQueryDatabaseParams) => {
@@ -90,6 +96,11 @@ export const notionQueryDatabaseTool: ToolConfig<NotionQueryDatabaseParams, Noti
body.page_size = Math.min(Number(params.pageSize), 100)
}
// Add pagination cursor if provided
if (params.startCursor) {
body.start_cursor = params.startCursor.trim()
}
return body
},
},
+3 -3
View File
@@ -30,7 +30,7 @@ export const notionReadTool: ToolConfig<NotionReadParams, NotionResponse> = {
request: {
url: (params: NotionReadParams) => {
return `https://api.notion.com/v1/pages/${params.pageId}`
return `https://api.notion.com/v1/pages/${params.pageId.trim()}`
},
method: 'GET',
headers: (params: NotionReadParams) => {
@@ -64,7 +64,7 @@ export const notionReadTool: ToolConfig<NotionReadParams, NotionResponse> = {
}
// Now fetch the page content using blocks endpoint
const pageId = params?.pageId
const pageId = params?.pageId?.trim()
const accessToken = params?.accessToken
if (!pageId || !accessToken) {
@@ -212,7 +212,7 @@ export const notionReadV2Tool: ToolConfig<NotionReadParams, NotionReadV2Response
}
}
const pageId = params?.pageId
const pageId = params?.pageId?.trim()
const accessToken = params?.accessToken
if (!pageId || !accessToken) {
+1 -1
View File
@@ -35,7 +35,7 @@ export const notionReadDatabaseTool: ToolConfig<NotionReadDatabaseParams, Notion
request: {
url: (params: NotionReadDatabaseParams) => {
return `https://api.notion.com/v1/databases/${params.databaseId}`
return `https://api.notion.com/v1/databases/${params.databaseId.trim()}`
},
method: 'GET',
headers: (params: NotionReadDatabaseParams) => {
+107
View File
@@ -0,0 +1,107 @@
import { BLOCK_OUTPUT_PROPERTIES } from '@/tools/notion/types'
import type { ToolConfig } from '@/tools/types'
export interface NotionRetrieveBlockParams {
blockId: string
accessToken: string
}
interface NotionRetrieveBlockResponse {
success: boolean
output: {
id: string
type: string
has_children: boolean
archived: boolean
block: Record<string, any>
}
}
export const notionRetrieveBlockTool: ToolConfig<
NotionRetrieveBlockParams,
NotionRetrieveBlockResponse
> = {
id: 'notion_retrieve_block',
name: 'Notion Retrieve Block',
description: 'Retrieve a single Notion block by its UUID, including its type-specific content',
version: '1.0.0',
oauth: {
required: true,
provider: 'notion',
},
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'hidden',
description: 'Notion OAuth access token',
},
blockId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The UUID of the block to retrieve',
},
},
request: {
url: (params: NotionRetrieveBlockParams) =>
`https://api.notion.com/v1/blocks/${params.blockId.trim()}`,
method: 'GET',
headers: (params: NotionRetrieveBlockParams) => {
if (!params.accessToken) {
throw new Error('Access token is required')
}
return {
Authorization: `Bearer ${params.accessToken}`,
'Notion-Version': '2022-06-28',
'Content-Type': 'application/json',
}
},
},
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: response.ok,
output: {
id: data.id,
type: data.type ?? '',
has_children: data.has_children ?? false,
archived: data.archived ?? false,
block: data,
},
}
},
outputs: {
id: BLOCK_OUTPUT_PROPERTIES.id,
type: BLOCK_OUTPUT_PROPERTIES.type,
has_children: BLOCK_OUTPUT_PROPERTIES.has_children,
archived: BLOCK_OUTPUT_PROPERTIES.archived,
block: {
type: 'object',
description:
'The full Notion block object. Includes a type-specific field (e.g. paragraph, heading_1, image) whose shape varies by block type and is not enumerated below — read it directly off this object.',
properties: BLOCK_OUTPUT_PROPERTIES,
},
},
}
export const notionRetrieveBlockV2Tool: ToolConfig<
NotionRetrieveBlockParams,
NotionRetrieveBlockResponse
> = {
id: 'notion_retrieve_block_v2',
name: 'Notion Retrieve Block',
description: 'Retrieve a single Notion block by its UUID, including its type-specific content',
version: '2.0.0',
oauth: notionRetrieveBlockTool.oauth,
params: notionRetrieveBlockTool.params,
request: notionRetrieveBlockTool.request,
transformResponse: notionRetrieveBlockTool.transformResponse,
outputs: notionRetrieveBlockTool.outputs,
}
+11
View File
@@ -39,6 +39,12 @@ export const notionSearchTool: ToolConfig<NotionSearchParams, NotionResponse> =
visibility: 'user-or-llm',
description: 'Number of results to return (default: 100, max: 100)',
},
startCursor: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Pagination cursor returned by a previous request',
},
},
request: {
@@ -80,6 +86,11 @@ export const notionSearchTool: ToolConfig<NotionSearchParams, NotionResponse> =
body.page_size = Math.min(Number(params.pageSize), 100)
}
// Add pagination cursor if provided
if (params.startCursor) {
body.start_cursor = params.startCursor.trim()
}
return body
},
},
+2 -156
View File
@@ -190,15 +190,6 @@ export const FILE_OUTPUT_PROPERTIES = {
},
} as const satisfies Record<string, OutputProperty>
/**
* Complete file output definition
*/
export const FILE_OUTPUT: OutputProperty = {
type: 'object',
description: 'File object',
properties: FILE_OUTPUT_PROPERTIES,
}
/**
* Emoji object properties.
* @see https://developers.notion.com/reference/emoji-object
@@ -308,61 +299,6 @@ export const PAGE_OUTPUT: OutputProperty = {
properties: PAGE_OUTPUT_PROPERTIES,
}
/**
* Simplified page output properties for read operations (flattened structure).
* Used by notion_read and notion_read_v2 tools.
*/
export const PAGE_READ_OUTPUT_PROPERTIES = {
content: {
type: 'string',
description: 'Page content in markdown format with headers, paragraphs, lists, and todos',
},
title: { type: 'string', description: 'Page title' },
url: { type: 'string', description: 'Notion page URL' },
created_time: { type: 'string', description: 'ISO 8601 creation timestamp' },
last_edited_time: { type: 'string', description: 'ISO 8601 last edit timestamp' },
} as const satisfies Record<string, OutputProperty>
/**
* Page metadata output properties for legacy tools.
* Used by notion_read, notion_create_page, notion_update_page.
*/
export const PAGE_METADATA_OUTPUT_PROPERTIES = {
title: { type: 'string', description: 'Page title' },
lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' },
createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' },
url: { type: 'string', description: 'Notion page URL' },
} as const satisfies Record<string, OutputProperty>
/**
* Page metadata output for create/update operations.
*/
export const PAGE_MUTATION_METADATA_OUTPUT_PROPERTIES = {
title: { type: 'string', description: 'Page title' },
pageId: { type: 'string', description: 'Page UUID' },
url: { type: 'string', description: 'Notion page URL' },
lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' },
createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' },
} as const satisfies Record<string, OutputProperty>
/**
* Complete page metadata output definition
*/
export const PAGE_METADATA_OUTPUT: OutputProperty = {
type: 'object',
description: 'Page metadata including title, URL, and timestamps',
properties: PAGE_METADATA_OUTPUT_PROPERTIES,
}
/**
* Page mutation metadata output definition (for create/update)
*/
export const PAGE_MUTATION_METADATA_OUTPUT: OutputProperty = {
type: 'object',
description: 'Page metadata including title, page ID, URL, and timestamps',
properties: PAGE_MUTATION_METADATA_OUTPUT_PROPERTIES,
}
/**
* Common database object properties from Notion API.
* @see https://developers.notion.com/reference/database
@@ -400,28 +336,6 @@ export const DATABASE_OUTPUT: OutputProperty = {
properties: DATABASE_OUTPUT_PROPERTIES,
}
/**
* Database metadata output properties for legacy tools.
* Used by notion_read_database, notion_create_database.
*/
export const DATABASE_METADATA_OUTPUT_PROPERTIES = {
id: { type: 'string', description: 'Database UUID' },
title: { type: 'string', description: 'Database title' },
url: { type: 'string', description: 'Notion database URL' },
createdTime: { type: 'string', description: 'ISO 8601 creation timestamp' },
lastEditedTime: { type: 'string', description: 'ISO 8601 last edit timestamp' },
properties: { type: 'object', description: 'Database properties schema' },
} as const satisfies Record<string, OutputProperty>
/**
* Complete database metadata output definition
*/
export const DATABASE_METADATA_OUTPUT: OutputProperty = {
type: 'object',
description: 'Database metadata including title, ID, URL, timestamps, and properties schema',
properties: DATABASE_METADATA_OUTPUT_PROPERTIES,
}
/**
* Block object properties from Notion API.
* @see https://developers.notion.com/reference/block
@@ -491,25 +405,6 @@ export const SEARCH_RESULTS_OUTPUT: OutputProperty = {
},
}
/**
* Search metadata output properties for legacy tools.
*/
export const SEARCH_METADATA_OUTPUT_PROPERTIES = {
totalResults: { type: 'number', description: 'Number of results returned' },
hasMore: { type: 'boolean', description: 'Whether more results are available' },
nextCursor: { type: 'string', description: 'Cursor for next page of results', optional: true },
results: SEARCH_RESULTS_OUTPUT,
} as const satisfies Record<string, OutputProperty>
/**
* Complete search metadata output definition
*/
export const SEARCH_METADATA_OUTPUT: OutputProperty = {
type: 'object',
description: 'Search metadata including total results count, pagination info, and raw results',
properties: SEARCH_METADATA_OUTPUT_PROPERTIES,
}
/**
* Database query results array output with page items
*/
@@ -522,43 +417,6 @@ export const DATABASE_QUERY_RESULTS_OUTPUT: OutputProperty = {
},
}
/**
* Query metadata output properties for legacy tools.
*/
export const QUERY_METADATA_OUTPUT_PROPERTIES = {
totalResults: { type: 'number', description: 'Number of results returned' },
hasMore: { type: 'boolean', description: 'Whether more results are available' },
nextCursor: { type: 'string', description: 'Cursor for next page of results', optional: true },
results: DATABASE_QUERY_RESULTS_OUTPUT,
} as const satisfies Record<string, OutputProperty>
/**
* Complete query metadata output definition
*/
export const QUERY_METADATA_OUTPUT: OutputProperty = {
type: 'object',
description: 'Query metadata including total results, pagination info, and raw results array',
properties: QUERY_METADATA_OUTPUT_PROPERTIES,
}
/**
* Row output properties for add_database_row operations.
*/
export const ROW_OUTPUT_PROPERTIES = {
id: { type: 'string', description: 'Row (page) UUID' },
url: { type: 'string', description: 'Notion page URL' },
title: { type: 'string', description: 'Row title' },
created_time: { type: 'string', description: 'ISO 8601 creation timestamp' },
last_edited_time: { type: 'string', description: 'ISO 8601 last edit timestamp' },
} as const satisfies Record<string, OutputProperty>
/**
* Write operation output properties.
*/
export const WRITE_OUTPUT_PROPERTIES = {
appended: { type: 'boolean', description: 'Whether content was successfully appended' },
} as const satisfies Record<string, OutputProperty>
/**
* Comment object properties from Notion API.
* @see https://developers.notion.com/reference/comment-object
@@ -574,15 +432,6 @@ export const COMMENT_OUTPUT_PROPERTIES = {
rich_text: RICH_TEXT_ARRAY_OUTPUT,
} as const satisfies Record<string, OutputProperty>
/**
* Complete comment output definition for array items
*/
export const COMMENT_OUTPUT: OutputProperty = {
type: 'object',
description: 'Notion comment object',
properties: COMMENT_OUTPUT_PROPERTIES,
}
/**
* Array of block objects (used by append/retrieve block children).
*/
@@ -668,6 +517,7 @@ export interface NotionQueryDatabaseParams {
filter?: string
sorts?: string
pageSize?: number
startCursor?: string
accessToken: string
}
@@ -675,6 +525,7 @@ export interface NotionSearchParams {
query?: string
filterType?: string
pageSize?: number
startCursor?: string
accessToken: string
}
@@ -685,11 +536,6 @@ export interface NotionCreateDatabaseParams {
accessToken: string
}
interface NotionReadDatabaseParams {
databaseId: string
accessToken: string
}
export interface NotionAddDatabaseRowParams {
databaseId: string
properties: Record<string, any>
+1 -1
View File
@@ -36,7 +36,7 @@ export const notionUpdatePageTool: ToolConfig<NotionUpdatePageParams, NotionResp
request: {
url: (params: NotionUpdatePageParams) => {
return `https://api.notion.com/v1/pages/${params.pageId}`
return `https://api.notion.com/v1/pages/${params.pageId.trim()}`
},
method: 'PATCH',
headers: (params: NotionUpdatePageParams) => {
+1 -1
View File
@@ -35,7 +35,7 @@ export const notionWriteTool: ToolConfig<NotionWriteParams, NotionResponse> = {
request: {
url: (params: NotionWriteParams) => {
return `https://api.notion.com/v1/blocks/${params.pageId}/children`
return `https://api.notion.com/v1/blocks/${params.pageId.trim()}/children`
},
method: 'PATCH',
headers: (params: NotionWriteParams) => {
+4
View File
@@ -2489,6 +2489,8 @@ import {
notionReadV2Tool,
notionRetrieveBlockChildrenTool,
notionRetrieveBlockChildrenV2Tool,
notionRetrieveBlockTool,
notionRetrieveBlockV2Tool,
notionRetrieveUserTool,
notionRetrieveUserV2Tool,
notionSearchTool,
@@ -5528,6 +5530,7 @@ export const tools: Record<string, ToolConfig> = {
notion_add_database_row: notionAddDatabaseRowTool,
notion_update_page: notionUpdatePageTool,
notion_append_blocks: notionAppendBlocksTool,
notion_retrieve_block: notionRetrieveBlockTool,
notion_retrieve_block_children: notionRetrieveBlockChildrenTool,
notion_update_block: notionUpdateBlockTool,
notion_delete_block: notionDeleteBlockTool,
@@ -5545,6 +5548,7 @@ export const tools: Record<string, ToolConfig> = {
notion_update_page_v2: notionUpdatePageV2Tool,
notion_add_database_row_v2: notionAddDatabaseRowV2Tool,
notion_append_blocks_v2: notionAppendBlocksV2Tool,
notion_retrieve_block_v2: notionRetrieveBlockV2Tool,
notion_retrieve_block_children_v2: notionRetrieveBlockChildrenV2Tool,
notion_update_block_v2: notionUpdateBlockV2Tool,
notion_delete_block_v2: notionDeleteBlockV2Tool,