initialize_notion_database
Creates a Notion database for Kindle book summaries by setting up the required structure under a specified parent page.
Instructions
Creates the Kindle Book Summaries database in Notion under a given parent page. Call this automatically when process_kindle_export returns status='setup_required', using the page ID created by the Notion MCP tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parentPageId | Yes | The Notion page ID to create the database under |
Implementation Reference
- Main handler function that executes the initialize_notion_database tool logic. Creates a Notion database under a parent page with properties for Name, Author, and Title. Saves the database ID locally and returns the database_id and success message.
export async function initializeNotionDatabase( input: InitializeNotionDatabaseInput ): Promise<{ database_id: string; message: string }> { const { parentPageId } = InitializeNotionDatabaseInputSchema.parse(input); const apiKey = process.env.NOTION_API_KEY; if (!apiKey) { throw new Error("NOTION_API_KEY is not set."); } const notion = new Client({ auth: apiKey }); const database = await notion.databases.create({ parent: { type: "page_id", page_id: parentPageId }, title: [{ type: "text", text: { content: DB_TITLE } }], properties: { Name: { title: {} }, Author: { rich_text: {} }, Title: { rich_text: {} }, }, }); saveLocalDatabaseId(database.id); return { database_id: database.id, message: `Database "${DB_TITLE}" created successfully. Now call process_kindle_export again with the original file to continue.`, }; } - Zod input validation schema and TypeScript type definition for the initialize_notion_database tool input. Validates that parentPageId is a non-empty string.
export const InitializeNotionDatabaseInputSchema = z.object({ parentPageId: z.string().min(1, "parentPageId must not be empty"), }); export type InitializeNotionDatabaseInput = z.infer< typeof InitializeNotionDatabaseInputSchema >; - src/index.ts:38-52 (registration)MCP tool registration for initialize_notion_database. Defines the tool name, description, and JSON input schema with parentPageId property that gets exposed to MCP clients.
{ name: "initialize_notion_database", description: "Creates the Kindle Book Summaries database in Notion under a given parent page. Call this automatically when process_kindle_export returns status='setup_required', using the page ID created by the Notion MCP tool.", inputSchema: { type: "object", properties: { parentPageId: { type: "string", description: "The Notion page ID to create the database under", }, }, required: ["parentPageId"], }, }, - src/index.ts:134-141 (registration)Tool dispatch handler switch case that routes initialize_notion_database calls to the actual implementation function and returns the result as JSON content.
case "initialize_notion_database": { const result = await initializeNotionDatabase( args as { parentPageId: string } ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }