get-block
Retrieve specific blocks from Notion workspaces using their unique block IDs to access and manipulate content within pages.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| block_id | Yes | The ID of the block to retrieve |
Implementation Reference
- src/lib/mcp-server.ts:409-440 (handler)The complete registration of the 'get-block' tool, including input schema, handler logic that fetches the block via NotionService and returns its JSON, with error handling.this.server.tool( "get-block", { block_id: z.string().describe("The ID of the block to retrieve"), }, async ({ block_id }) => { try { const block = await this.notionService.retrieveBlock(block_id); return { content: [ { type: "text", text: JSON.stringify(block, null, 2), }, ], }; } catch (error) { console.error("Error in get-block tool:", error); return { content: [ { type: "text", text: `Error: Failed to retrieve block - ${ (error as Error).message }`, }, ], isError: true, }; } } );
- src/lib/mcp-server.ts:411-413 (schema)Zod input schema for the 'get-block' tool: requires a block_id string.{ block_id: z.string().describe("The ID of the block to retrieve"), },
- src/lib/notion.ts:223-234 (helper)Supporting method in NotionService.retrieveBlock, which wraps the Notion Client's blocks.retrieve API call and handles errors./** * Retrieve a block */ async retrieveBlock(blockId: string) { try { return await this.client.blocks.retrieve({ block_id: blockId, }); } catch (error) { this.handleError(error); } }
- src/lib/mcp-server.ts:409-440 (registration)Registration of the 'get-block' tool on the MCP server using server.tool()this.server.tool( "get-block", { block_id: z.string().describe("The ID of the block to retrieve"), }, async ({ block_id }) => { try { const block = await this.notionService.retrieveBlock(block_id); return { content: [ { type: "text", text: JSON.stringify(block, null, 2), }, ], }; } catch (error) { console.error("Error in get-block tool:", error); return { content: [ { type: "text", text: `Error: Failed to retrieve block - ${ (error as Error).message }`, }, ], isError: true, }; } } );