Skip to main content
Glama

content_convert

Read-onlyIdempotent

Convert markdown to Notion block JSON and vice versa. Validate and preview conversions between markdown content and Notion's block structure.

Instructions

Convert between markdown and Notion block JSON. Directions: markdown-to-blocks (input: markdown string), blocks-to-markdown (input: JSON array of Notion blocks or JSON string). Most tools (pages, blocks) handle markdown automatically -- use this only for preview/validation. Supported markdown: headings, lists, to-do, code blocks, blockquotes, dividers, callouts (> [!NOTE]), toggles (), tables, images, bookmarks, embeds, equations ($$), columns (:::columns), [toc], [breadcrumb]. Inline: bold, italic, code, strike, link.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directionYesConversion direction
contentYesContent to convert (string or array/JSON string)

Implementation Reference

  • Main handler function for the content_convert tool. Converts between Markdown and Notion block JSON. Supports two directions: markdown-to-blocks (accepts a markdown string) and blocks-to-markdown (accepts a JSON array of Notion blocks or a JSON string). Delegates to markdownToBlocks() and blocksToMarkdown() from helpers/markdown.ts.
    export async function contentConvert(input: ContentConvertInput): Promise<any> {
      return withErrorHandling(async () => {
        switch (input.direction) {
          case 'markdown-to-blocks': {
            if (typeof input.content !== 'string') {
              throw new NotionMCPError(
                'Content must be a string for markdown-to-blocks',
                'VALIDATION_ERROR',
                'Provide a string content'
              )
            }
            const blocks = markdownToBlocks(input.content)
            return {
              direction: input.direction,
              block_count: blocks.length,
              blocks
            }
          }
    
          case 'blocks-to-markdown': {
            let content = input.content
            // Parse JSON string if needed
            if (typeof content === 'string') {
              try {
                content = JSON.parse(content)
              } catch {
                throw new NotionMCPError(
                  'Content must be a valid JSON array or array object for blocks-to-markdown',
                  'VALIDATION_ERROR',
                  'Provide a valid JSON array or object'
                )
              }
            }
            if (!Array.isArray(content)) {
              throw new NotionMCPError(
                'Content must be an array for blocks-to-markdown',
                'VALIDATION_ERROR',
                'Provide an array content'
              )
            }
            if (!content.every((b) => typeof b === 'object' && b !== null)) {
              throw new NotionMCPError(
                'Content must be an array of objects for blocks-to-markdown',
                'VALIDATION_ERROR',
                'Provide an array of block objects'
              )
            }
            const markdown = blocksToMarkdown(content as any)
            return {
              direction: input.direction,
              char_count: markdown.length,
              markdown
            }
          }
    
          default:
            throw new NotionMCPError(
              `Unsupported direction: ${input.direction}`,
              'VALIDATION_ERROR',
              'Provide a valid direction'
            )
        }
      })()
    }
  • Input type definition for the content_convert tool. Defines ContentConvertInput interface with direction enum ('markdown-to-blocks' | 'blocks-to-markdown') and content (string | any[]).
    export interface ContentConvertInput {
      direction: 'markdown-to-blocks' | 'blocks-to-markdown'
      content: string | any[]
    }
  • Tool schema registration in the TOOLS array. Defines name 'content_convert', description, annotations, and inputSchema (direction enum + content string).
    {
      name: 'content_convert',
      description:
        'Convert between markdown and Notion block JSON. Directions: markdown-to-blocks (input: markdown string), blocks-to-markdown (input: JSON array of Notion blocks or JSON string). Most tools (pages, blocks) handle markdown automatically -- use this only for preview/validation. Supported markdown: headings, lists, to-do, code blocks, blockquotes, dividers, callouts (> [!NOTE]), toggles (<details>), tables, images, bookmarks, embeds, equations ($$), columns (:::columns), [toc], [breadcrumb]. Inline: **bold**, *italic*, `code`, ~~strike~~, [link](url).',
      annotations: {
        title: 'Content Convert',
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      },
      inputSchema: {
        type: 'object',
        properties: {
          direction: {
            type: 'string',
            enum: ['markdown-to-blocks', 'blocks-to-markdown'],
            description: 'Conversion direction'
          },
          content: { type: 'string', description: 'Content to convert (string or array/JSON string)' }
        },
        required: ['direction', 'content']
      }
    },
  • Handler dispatch in the CallToolRequestSchema switch statement. Routes 'content_convert' to the contentConvert() function (no notion client needed, unlike most tools).
    case 'content_convert':
      result = await contentConvert(args as any)
  • blocksToMarkdown() - converts Notion block array to markdown string. Used by the blocks-to-markdown direction. Also markdownToBlocks() at line 246-249 converts markdown string to Notion block array for the reverse direction.
    export function blocksToMarkdown(blocks: NotionBlock[]): string {
      const lines: string[] = []
    
      for (const block of blocks) {
        const handler = BLOCK_HANDLERS[block.type]
        if (handler) {
          handler(block, lines)
        }
      }
    
      return lines.join('\n')
    }
Behavior5/5

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

Beyond annotations (readOnly, idempotent), the description provides a comprehensive list of supported markdown features, specifics on input formats per direction, and confirms no side effects. It fully discloses behavioral traits relevant to selection and invocation.

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

Conciseness4/5

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

The description is well-structured, front-loading the core purpose and directions, then usage guidance, then supported features. It is somewhat lengthy due to the markdown list, but every section serves a purpose. Minor redundancy exists (e.g., repeating 'Directions:'), but overall it's appropriate.

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

Completeness4/5

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

Given no output schema, the description implicitly covers return values by stating the conversion nature. It sufficiently covers prerequisites, directions, supported markdown, and usage context. Missing details like error handling are acceptable for a read-only conversion tool.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description adds value by specifying input formats: 'markdown string' for markdown-to-blocks and 'JSON array of Notion blocks or JSON string' for blocks-to-markdown, clarifying what the content parameter expects beyond the schema's generic description.

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

Purpose5/5

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

The description clearly states the tool converts between markdown and Notion block JSON, a specific verb-resource pair. It further specifies two directions (markdown-to-blocks and blocks-to-markdown) and explicitly distinguishes it from sibling tools that handle markdown automatically.

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

Usage Guidelines5/5

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

The description includes explicit guidance: 'Most tools (pages, blocks) handle markdown automatically -- use this only for preview/validation.' This tells the agent when to use this tool versus alternatives, making the usage context crystal clear.

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

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/n24q02m/better-notion-mcp'

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