Skip to main content
Glama

API-retrieve-a-block

Fetch specific content from Notion by retrieving a block using its unique identifier. Ideal for AI assistants to efficiently access and process information stored in Notion databases.

Instructions

Retrieve a block

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
block_idYesIdentifier for a Notion block

Implementation Reference

  • Dynamically registers 'API-retrieve-a-block' (from OpenAPI operationId 'retrieve-a-block') to the list of available MCP tools, including its schema and description from the converted spec.
    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}`) }) })
  • Generic handler for API tools including 'API-retrieve-a-block': looks up OpenAPI operation, executes via HTTP client, updates cache, and returns JSON response as text content.
    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 { content: [ { type: 'text', text: JSON.stringify(response.data), }, ], }
  • Helper function to cache responses from API calls, with specific handling to cache block data from 'API-retrieve-a-block' in blockCache.
    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); } }
  • Converts OpenAPI spec to MCP tools, creating 'API-retrieve-a-block' tool name, inputSchema from operation parameters/body, and populates openApiLookup for handler lookup.
    convertToMCPTools(): { tools: Record<string, { methods: NewToolMethod[] }> openApiLookup: Record<string, OpenAPIV3.OperationObject & { method: string; path: string }> zip: Record<string, { openApi: OpenAPIV3.OperationObject & { method: string; path: string }; mcp: NewToolMethod }> } { const apiName = 'API' const openApiLookup: Record<string, OpenAPIV3.OperationObject & { method: string; path: string }> = {} const tools: Record<string, { methods: NewToolMethod[] }> = { [apiName]: { methods: [] }, } const zip: Record<string, { openApi: OpenAPIV3.OperationObject & { method: string; path: string }; mcp: NewToolMethod }> = {} for (const [path, pathItem] of Object.entries(this.openApiSpec.paths || {})) { if (!pathItem) continue for (const [method, operation] of Object.entries(pathItem)) { if (!this.isOperation(method, operation)) continue const mcpMethod = this.convertOperationToMCPMethod(operation, method, path) if (mcpMethod) { const uniqueName = this.ensureUniqueName(mcpMethod.name) mcpMethod.name = uniqueName tools[apiName]!.methods.push(mcpMethod) openApiLookup[apiName + '-' + uniqueName] = { ...operation, method, path } zip[apiName + '-' + uniqueName] = { openApi: { ...operation, method, path }, mcp: mcpMethod } } } } return { tools, openApiLookup, zip } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Taewoong1378/notion-readonly-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server