fix(notion): correctly register tool (#4337)

This commit is contained in:
Vikhyath Mondreti
2026-04-28 20:41:40 -07:00
committed by GitHub
parent ed7786d7fd
commit 61342e2567
6 changed files with 79 additions and 6 deletions
+51
View File
@@ -267,6 +267,38 @@ vi.mock('@/tools/registry', () => {
params: {},
request: { url: '/api/tools/serper/search', method: 'GET' },
},
notion_add_database_row: {
id: 'notion_add_database_row',
name: 'Add Notion Database Row',
description: 'Add a new row to a Notion database with specified properties',
version: '1.0.0',
params: {},
request: { url: 'https://api.notion.com/v1/pages', method: 'POST' },
},
notion_add_database_row_v2: {
id: 'notion_add_database_row_v2',
name: 'Add Notion Database Row',
description: 'Add a new row to a Notion database with specified properties',
version: '2.0.0',
params: {},
request: { url: 'https://api.notion.com/v1/pages', method: 'POST' },
},
notion_update_page: {
id: 'notion_update_page',
name: 'Notion Page Updater',
description: 'Update properties of a Notion page',
version: '1.0.0',
params: {},
request: { url: 'https://api.notion.com/v1/pages/x', method: 'PATCH' },
},
notion_update_page_v2: {
id: 'notion_update_page_v2',
name: 'Notion Page Updater',
description: 'Update properties of a Notion page',
version: '2.0.0',
params: {},
request: { url: 'https://api.notion.com/v1/pages/x', method: 'PATCH' },
},
}
return { tools: mockTools }
})
@@ -388,6 +420,19 @@ describe('Tools Registry', () => {
expect(gmailTool?.name).toBe('Gmail Read')
})
it.each([
['notion_add_database_row', 'notion_add_database_row_v2'],
['notion_update_page', 'notion_update_page_v2'],
])('getTool resolves both the legacy and v2 ids for %s', (legacyId, v2Id) => {
const legacy = getTool(legacyId)
expect(legacy).toBeDefined()
expect(legacy?.id).toBe(legacyId)
const v2 = getTool(v2Id)
expect(v2).toBeDefined()
expect(v2?.id).toBe(v2Id)
})
it('getTool should return undefined for non-existent tool', () => {
const nonExistentTool = getTool('non_existent_tool')
expect(nonExistentTool).toBeUndefined()
@@ -399,6 +444,12 @@ describe('Custom Tools', () => {
expect(getTool('custom_remote-tool-123', 'workspace-1')).toBeUndefined()
})
it('returns the legacy notion_add_database_row tool through the async helper', async () => {
const legacy = await getToolAsync('notion_add_database_row')
expect(legacy).toBeDefined()
expect(legacy?.id).toBe('notion_add_database_row')
})
it('resolves custom tools through the async helper', async () => {
mockGetCustomToolByIdOrTitle.mockResolvedValue({
id: 'remote-tool-123',
+10 -1
View File
@@ -17,7 +17,7 @@ export const notionAddDatabaseRowTool: ToolConfig<
NotionAddDatabaseRowParams,
NotionAddDatabaseRowResponse
> = {
id: 'notion_add_database_row_v2',
id: 'notion_add_database_row',
name: 'Add Notion Database Row',
description: 'Add a new row to a Notion database with specified properties',
version: '1.0.0',
@@ -107,3 +107,12 @@ export const notionAddDatabaseRowTool: ToolConfig<
last_edited_time: PAGE_OUTPUT_PROPERTIES.last_edited_time,
},
}
export const notionAddDatabaseRowV2Tool: ToolConfig<
NotionAddDatabaseRowParams,
NotionAddDatabaseRowResponse
> = {
...notionAddDatabaseRowTool,
id: 'notion_add_database_row_v2',
version: '2.0.0',
}
+5 -1
View File
@@ -1,4 +1,7 @@
import { notionAddDatabaseRowTool } from '@/tools/notion/add_database_row'
import {
notionAddDatabaseRowTool,
notionAddDatabaseRowV2Tool,
} from '@/tools/notion/add_database_row'
import {
notionCreateDatabaseTool,
notionCreateDatabaseV2Tool,
@@ -52,4 +55,5 @@ export {
notionSearchV2Tool,
notionCreateDatabaseV2Tool,
notionAddDatabaseRowTool,
notionAddDatabaseRowV2Tool,
}
+5 -1
View File
@@ -1788,6 +1788,7 @@ import {
} from '@/tools/neo4j'
import {
notionAddDatabaseRowTool,
notionAddDatabaseRowV2Tool,
notionCreateDatabaseTool,
notionCreateDatabaseV2Tool,
notionCreatePageTool,
@@ -1800,6 +1801,7 @@ import {
notionReadV2Tool,
notionSearchTool,
notionSearchV2Tool,
notionUpdatePageTool,
notionUpdatePageV2Tool,
notionWriteTool,
notionWriteV2Tool,
@@ -3527,6 +3529,8 @@ export const tools: Record<string, ToolConfig> = {
notion_query_database: notionQueryDatabaseTool,
notion_search: notionSearchTool,
notion_create_database: notionCreateDatabaseTool,
notion_add_database_row: notionAddDatabaseRowTool,
notion_update_page: notionUpdatePageTool,
// Notion V2 tools
notion_read_v2: notionReadV2Tool,
notion_read_database_v2: notionReadDatabaseV2Tool,
@@ -3536,7 +3540,7 @@ export const tools: Record<string, ToolConfig> = {
notion_search_v2: notionSearchV2Tool,
notion_create_database_v2: notionCreateDatabaseV2Tool,
notion_update_page_v2: notionUpdatePageV2Tool,
notion_add_database_row_v2: notionAddDatabaseRowTool,
notion_add_database_row_v2: notionAddDatabaseRowV2Tool,
obsidian_append_active: obsidianAppendActiveTool,
obsidian_append_note: obsidianAppendNoteTool,
obsidian_append_periodic_note: obsidianAppendPeriodicNoteTool,
+7 -2
View File
@@ -10,7 +10,12 @@ import { extractErrorMessage } from '@/tools/error-extractors'
import { tools } from '@/tools/registry'
import type { ToolConfig, ToolResponse } from '@/tools/types'
import type { RequestParams } from '@/tools/utils'
import { createCustomToolRequestBody, createParamSchema, createToolConfig } from '@/tools/utils'
import {
createCustomToolRequestBody,
createParamSchema,
createToolConfig,
resolveToolId,
} from '@/tools/utils'
const logger = createLogger('ToolsUtils')
@@ -92,7 +97,7 @@ export async function getToolAsync(
toolId: string,
context: GetToolAsyncContext = {}
): Promise<ToolConfig | undefined> {
const builtInTool = tools[toolId]
const builtInTool = tools[resolveToolId(toolId)]
if (builtInTool) return builtInTool
if (isCustomTool(toolId)) {
+1 -1
View File
@@ -282,7 +282,7 @@ export function createCustomToolRequestBody(customTool: any, isClient = true, wo
// Get a tool by its ID
export function getTool(toolId: string, _workspaceId?: string): ToolConfig | undefined {
// Check for built-in tools
const builtInTool = tools[toolId]
const builtInTool = tools[resolveToolId(toolId)]
if (builtInTool) return builtInTool
// If not found or running on the server, return undefined