search_pages
Find pages and databases in Notion by title using customizable search queries, results sorting, and pagination for efficient content navigation.
Instructions
Search for pages and databases in Notion by title
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of results to return (1-100) | |
| query | No | Search query for filtering by title | |
| sort | No | Sort order for results | |
| start_cursor | No | Cursor for pagination |
Implementation Reference
- src/tools/searchPage.ts:6-32 (handler)The core handler function implementing the search_pages tool logic, performing a Notion search API call and formatting results.export async function searchPages( params: SearchPagesParams ): Promise<CallToolResult> { try { const response = await notion.search({ query: params.query || "", sort: params.sort, start_cursor: params.start_cursor, page_size: params.page_size || 10, }); const resultsText = JSON.stringify(response, null, 2); return { content: [ { type: "text", text: `Found ${response.results.length} results. ${ response.has_more ? "More results available." : "" }\n\n${resultsText}`, }, ], }; } catch (error) { return handleNotionError(error); } }
- src/schema/page.ts:123-139 (schema)Zod schema defining the input parameters specifically for the search_pages action.export const SEARCH_PAGES_SCHEMA = { query: z.string().optional().describe("Search query for filtering by title"), sort: z .object({ direction: z.enum(["ascending", "descending"]), timestamp: z.literal("last_edited_time"), }) .optional() .describe("Sort order for results"), start_cursor: z.string().optional().describe("Cursor for pagination"), page_size: z .number() .min(1) .max(100) .optional() .describe("Number of results to return (1-100)"), };
- src/tools/index.ts:14-20 (registration)Registration of the 'notion_pages' MCP tool, which includes the search_pages action via its dispatcher.// Register combined pages operation tool server.tool( "notion_pages", "Perform various page operations (create, archive, restore, search, update)", PAGES_OPERATION_SCHEMA, registerPagesOperationTool );
- src/tools/pages.ts:10-30 (helper)Dispatcher function that routes 'search_pages' action to the searchPages handler.export const registerPagesOperationTool = async ( params: PagesOperationParams ): Promise<CallToolResult> => { switch (params.payload.action) { case "create_page": return registerCreatePageTool(params.payload.params); case "archive_page": return archivePage(params.payload.params); case "restore_page": return restorePage(params.payload.params); case "search_pages": return searchPages(params.payload.params); case "update_page_properties": return updatePageProperties(params.payload.params); default: return handleNotionError( new Error( `Unsupported action, use one of the following: "create_page", "archive_page", "restore_page", "search_pages", "update_page_properties"` ) ); }
- src/schema/page.ts:168-172 (schema)Part of the discriminated union schema defining the search_pages action variant.action: z .literal("search_pages") .describe("Use this action to search for pages based on a query."), params: z.object(SEARCH_PAGES_SCHEMA), }),