API-retrieve-a-comment
Fetch comments from a specific Notion block or page by providing a block ID, enabling pagination with optional start cursor and page size parameters.
Instructions
Retrieve comments
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| block_id | Yes | Identifier for a Notion block or page | |
| page_size | No | The number of items from the full list desired in the response. Maximum: 100 | |
| start_cursor | No | If supplied, this endpoint will return a page of results starting after the cursor provided. If not supplied, this endpoint will return the first page of results. |
Implementation Reference
- src/openapi-mcp-server/mcp/proxy.ts:115-126 (registration)Registers OpenAPI-derived tools, including 'API-retrieve-a-comment', in the MCP ListToolsRequestSchema handler by constructing names like 'API-{operationId}' and using schemas from the converter.Object.entries(this.tools).forEach(([toolName, def]) => { def.methods.forEach(method => { const toolNameWithMethod = `${toolName}-${method.name}`; const truncatedToolName = this.truncateToolName(toolNameWithMethod); tools.push({ name: truncatedToolName, description: method.description, inputSchema: method.inputSchema as Tool['inputSchema'], }) console.log(`- ${truncatedToolName}: ${method.description}`) }) })
- Handler logic for regular OpenAPI tools like 'API-retrieve-a-comment' in the MCP CallToolRequestSchema: finds the operation, executes via HttpClient, caches response, returns as MCP content.// Find the operation in OpenAPI spec const operation = this.findOperation(name) if (!operation) { const error = `Method ${name} not found.` console.error(error) return { content: [ { type: 'text', text: JSON.stringify({ status: 'error', message: error, code: 404 }), }, ], } } // Optimized parallel processing for API-get-block-children if (name === 'API-get-block-children') { // Create basic options for logging control const blockOptions: RecursiveExplorationOptions = { runInBackground: false, // Default to not showing logs for regular API calls }; return await this.handleBlockChildrenParallel(operation, params, blockOptions); } // Other regular API calls console.log(`Notion API call: ${operation.method.toUpperCase()} ${operation.path}`) const response = await this.httpClient.executeOperation(operation, params) // Log response summary console.log('Notion API response code:', response.status) if (response.status !== 200) { console.error('Response error:', response.data) } else { console.log('Response success') } // Update cache with response data this.updateCacheFromResponse(name, response.data); // Convert response to MCP format return {
- Helper method that uses the 'API-retrieve-a-comment' tool to fetch comments for a block/page during recursive exploration.// Retrieve comments private async retrieveComments(blockId: string, options: RecursiveExplorationOptions): Promise<any> { if (options.runInBackground) { console.log(`Retrieving comments: ${blockId}`); } // Get comments via API call const operation = this.findOperation('API-retrieve-a-comment'); if (!operation) { if (options.runInBackground) { console.warn('API-retrieve-a-comment method not found.'); } return Promise.resolve({ results: [] }); } try { if (options.runInBackground) { console.log(`Notion API call: ${operation.method.toUpperCase()} ${operation.path} (blockId: ${blockId})`); } return this.httpClient.executeOperation(operation, { block_id: blockId }) .then(response => { if (response.status !== 200) { if (options.runInBackground) { console.error('Error retrieving comments:', response.data); } return { results: [] }; } const commentsData = response.data; // Cache comments if (commentsData.results) { commentsData.results.forEach((comment: any) => { if (comment.id) { this.commentCache.set(comment.id, comment); } }); } return commentsData; }) .catch(error => { if (options.runInBackground) { console.error('Error retrieving comments:', error); } return { results: [] }; }); } catch (error) { if (options.runInBackground) { console.error('Error retrieving comments:', error); } return Promise.resolve({ results: [] }); } }
- Caches comments retrieved via 'API-retrieve-a-comment' tool in the commentCache Map for performance.private updateCacheFromResponse(apiName: string, data: any): void { if (!data || typeof data !== 'object') return; try { // Update appropriate cache based on API response type if (apiName === 'API-retrieve-a-page' && data.object === 'page' && data.id) { this.pageCache.set(data.id, data); } else if (apiName === 'API-retrieve-a-block' && data.object === 'block' && data.id) { this.blockCache.set(data.id, data); } else if (apiName === 'API-retrieve-a-database' && data.object === 'database' && data.id) { this.databaseCache.set(data.id, data); } else if (apiName === 'API-retrieve-a-comment' && data.results) { // Cache comments from result list data.results.forEach((comment: any) => { if (comment.object === 'comment' && comment.id) { this.commentCache.set(comment.id, comment); } }); } else if (apiName === 'API-retrieve-a-page-property' && data.results) { // Page property caching - would need params from call context // Skip this in current context console.log('Page property information has been cached'); } // API-get-block-children handled in handleBlockChildrenParallel } catch (error) { console.warn('Error updating cache:', error); } }
- Generates input schemas for tools including 'API-retrieve-a-comment' by converting the OpenAPI spec using OpenAPIToMCPConverter.const converter = new OpenAPIToMCPConverter(openApiSpec) const { tools, openApiLookup } = converter.convertToMCPTools() this.tools = tools this.openApiLookup = openApiLookup