API-patch-block-children
Append child content like paragraphs or bullet points to a specified block in Notion. Enables structured updates to container blocks using block or page IDs for precise content organization.
Instructions
Notion | Append block children
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| after | No | The ID of the existing block that the new block should be appended after. | |
| block_id | Yes | Identifier for a [block](ref:block). Also accepts a [page](ref:page) ID. | |
| children | Yes | Child content to append to a container block as an array of [block objects](ref:block) |
Implementation Reference
- The handler function for calling any MCP tool, including "API-patch-block-children". It looks up the corresponding OpenAPI operation by tool name, executes it via HTTP client, and formats the response as MCP content.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: params } = request.params // Find the operation in OpenAPI spec const operation = this.findOperation(name) if (!operation) { throw new Error(`Method ${name} not found`) } try { // Execute the operation const response = await this.httpClient.executeOperation(operation, params) // Convert response to MCP format return { content: [ { type: 'text', // currently this is the only type that seems to be used by mcp server text: JSON.stringify(response.data), // TODO: pass through the http status code text? }, ], } } catch (error) { console.error('Error in tool call', error) if (error instanceof HttpClientError) { console.error('HttpClientError encountered, returning structured error', error) const data = error.data?.response?.data ?? error.data ?? {} return { content: [ { type: 'text', text: JSON.stringify({ status: 'error', // TODO: get this from http status code? ...(typeof data === 'object' ? data : { data: data }), }), }, ], } } throw error } })
- src/openapi-mcp-server/mcp/proxy.ts:58-75 (registration)The registration/listing handler for MCP tools. Constructs tool names as 'API-{operationId}' (truncated if necessary), including "API-patch-block-children", and provides their schemas and descriptions from the OpenAPI spec.this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools: Tool[] = [] // Add methods as separate tools to match the MCP format 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'], }) }) }) return { tools } })
- Generates MCP tools and schemas from OpenAPI spec, creating tool names like 'API-{operationId}' and input schemas for parameters and request bodies.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 mcpMethod.description = this.getDescription(operation.summary || operation.description || '') tools[apiName]!.methods.push(mcpMethod) openApiLookup[apiName + '-' + uniqueName] = { ...operation, method, path } zip[apiName + '-' + uniqueName] = { openApi: { ...operation, method, path }, mcp: mcpMethod } } } } return { tools, openApiLookup, zip } }
- In the MCPProxy constructor, converts the Notion OpenAPI spec to MCP tools (including "API-patch-block-children") and sets up the openApiLookup for operation resolution and handlers.const converter = new OpenAPIToMCPConverter(openApiSpec) const { tools, openApiLookup } = converter.convertToMCPTools() this.tools = tools this.openApiLookup = openApiLookup
- src/init-server.ts:45-50 (registration)Initializes the MCPProxy with the Notion OpenAPI spec, creating the server instance that registers all tools including the target one.export async function initProxy(specPath: string, baseUrl: string |undefined) { const openApiSpec = await loadOpenApiSpec(specPath, baseUrl) const proxy = new MCPProxy('Notion API', openApiSpec) return proxy }