Skip to main content
Glama
gendosu

Notion MCP Server

by gendosu

API-update-a-block

Modify or archive Notion blocks using their block ID. Update text content for supported block types or toggle 'checked' status for to-do tasks. Restore archived blocks if needed.

Instructions

Notion | Update a block

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
archivedNoSet to true to archive (delete) a block. Set to false to un-archive (restore) a block.
block_idYesIdentifier for a Notion block
typeNoThe [block object `type`](ref:block#block-object-keys) value with the properties to be updated. Currently only `text` (for supported block types) and `checked` (for `to_do` blocks) fields can be updated.

Implementation Reference

  • The generic MCP tool call handler that executes all OpenAPI-derived tools, including 'API-update-a-block'. It resolves the tool name to the corresponding OpenAPI operation (matching 'API-' + operationId), calls the HTTP client to perform the API request to Notion's update block endpoint, and formats the response.
    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
      }
    })
  • Generates the inputSchema and output schema for each OpenAPI operation, including the 'update-a-block' operation used by tool 'API-update-a-block'. Converts parameters, requestBody, and responses from OpenAPI to JSON Schema for MCP tools.
    private convertOperationToMCPMethod(operation: OpenAPIV3.OperationObject, method: string, path: string): NewToolMethod | null {
      if (!operation.operationId) {
        console.warn(`Operation without operationId at ${method} ${path}`)
        return null
      }
    
      const methodName = operation.operationId
    
      const inputSchema: IJsonSchema & { type: 'object' } = {
        $defs: this.convertComponentsToJsonSchema(),
        type: 'object',
        properties: {},
        required: [],
      }
    
      // Handle parameters (path, query, header, cookie)
      if (operation.parameters) {
        for (const param of operation.parameters) {
          const paramObj = this.resolveParameter(param)
          if (paramObj && paramObj.schema) {
            const schema = this.convertOpenApiSchemaToJsonSchema(paramObj.schema, new Set(), false)
            // Merge parameter-level description if available
            if (paramObj.description) {
              schema.description = paramObj.description
            }
            inputSchema.properties![paramObj.name] = schema
            if (paramObj.required) {
              inputSchema.required!.push(paramObj.name)
            }
          }
        }
      }
    
      // Handle requestBody
      if (operation.requestBody) {
        const bodyObj = this.resolveRequestBody(operation.requestBody)
        if (bodyObj?.content) {
          // Handle multipart/form-data for file uploads
          // We convert the multipart/form-data schema to a JSON schema and we require
          // that the user passes in a string for each file that points to the local file
          if (bodyObj.content['multipart/form-data']?.schema) {
            const formSchema = this.convertOpenApiSchemaToJsonSchema(bodyObj.content['multipart/form-data'].schema, new Set(), false)
            if (formSchema.type === 'object' && formSchema.properties) {
              for (const [name, propSchema] of Object.entries(formSchema.properties)) {
                inputSchema.properties![name] = propSchema
              }
              if (formSchema.required) {
                inputSchema.required!.push(...formSchema.required!)
              }
            }
          }
          // Handle application/json
          else if (bodyObj.content['application/json']?.schema) {
            const bodySchema = this.convertOpenApiSchemaToJsonSchema(bodyObj.content['application/json'].schema, new Set(), false)
            // Merge body schema into the inputSchema's properties
            if (bodySchema.type === 'object' && bodySchema.properties) {
              for (const [name, propSchema] of Object.entries(bodySchema.properties)) {
                inputSchema.properties![name] = propSchema
              }
              if (bodySchema.required) {
                inputSchema.required!.push(...bodySchema.required!)
              }
            } else {
              // If the request body is not an object, just put it under "body"
              inputSchema.properties!['body'] = bodySchema
              inputSchema.required!.push('body')
            }
          }
        }
      }
    
      // Build description including error responses
      let description = operation.summary || operation.description || ''
      if (operation.responses) {
        const errorResponses = Object.entries(operation.responses)
          .filter(([code]) => code.startsWith('4') || code.startsWith('5'))
          .map(([code, response]) => {
            const responseObj = this.resolveResponse(response)
            let errorDesc = responseObj?.description || ''
            return `${code}: ${errorDesc}`
          })
    
        if (errorResponses.length > 0) {
          description += '\nError Responses:\n' + errorResponses.join('\n')
        }
      }
    
      // Extract return type (response schema)
      const returnSchema = this.extractResponseType(operation.responses)
    
      // Generate Zod schema from input schema
      try {
        // const zodSchemaStr = jsonSchemaToZod(inputSchema, { module: "cjs" })
        // console.log(zodSchemaStr)
        // // Execute the function with the zod instance
        // const zodSchema = eval(zodSchemaStr) as z.ZodType
    
        return {
          name: methodName,
          description,
          inputSchema,
          ...(returnSchema ? { returnSchema } : {}),
        }
      } catch (error) {
        console.warn(`Failed to generate Zod schema for ${methodName}:`, error)
        // Fallback to a basic object schema
        return {
          name: methodName,
          description,
          inputSchema,
          ...(returnSchema ? { returnSchema } : {}),
        }
      }
    }
  • Registers all generated tools by responding to listTools requests. Constructs tool names as 'API-' + operationId (e.g., 'API-update-a-block'), using schemas and descriptions from OpenAPI converter.
    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 }
    })
  • Processes each OpenAPI operation to create MCP tool methods under 'API' group, mapping 'API-' + operationId (e.g., 'API-update-a-block') to the operation details for lookup during execution.
    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 }
    }
  • In the MCPProxy constructor, converts the loaded Notion OpenAPI spec to MCP tools and lookup map, enabling dynamic tool handling for operations like 'update-a-block'.
      const converter = new OpenAPIToMCPConverter(openApiSpec)
      const { tools, openApiLookup } = converter.convertToMCPTools()
      this.tools = tools
      this.openApiLookup = openApiLookup
    
      this.setupHandlers()
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Update a block' implies a mutation operation, but the description fails to mention that it can archive/unarchive blocks, handle specific block types (e.g., text, to_do), or discuss potential side effects like permissions or rate limits, which are critical for safe use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description 'Notion | Update a block' is extremely concise and front-loaded, with no wasted words. It efficiently communicates the core purpose in a minimal format, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of updating blocks (with nested objects and archiving functionality), no annotations, and no output schema, the description is incomplete. It should provide more context on behavioral aspects, return values, or error handling to adequately guide the agent, especially for a mutation tool with potential side effects.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so the schema fully documents parameters like block_id, archived, and type. The description adds no additional meaning beyond the schema, such as explaining parameter interactions or use cases, but this is acceptable given the high schema coverage, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Notion | Update a block' clearly states the action (update) and resource (a block in Notion), distinguishing it from siblings like API-create-a-database or API-delete-a-block. However, it lacks specificity about what aspects of a block can be updated, which could differentiate it more precisely from similar tools like API-patch-block-children.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, such as needing a block_id, or compare it to siblings like API-patch-block-children or API-retrieve-a-block, leaving the agent without context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/gendosu/notion-mcp-server'

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