Skip to main content
Glama

content_convert

Convert content between markdown and Notion blocks to enable content migration and formatting within the Notion workspace.

Instructions

Convert: markdown-to-blocks, blocks-to-markdown. Most tools handle markdown automatically.

Input Schema

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

Implementation Reference

  • The main handler function that implements the content_convert tool, converting between Markdown strings and Notion block arrays based on the direction parameter.
    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 Error('Content must be a string for markdown-to-blocks')
            }
            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 Error('Content must be a valid JSON array or array object for blocks-to-markdown')
              }
            }
            if (!Array.isArray(content)) {
              throw new Error('Content must be an array for blocks-to-markdown')
            }
            const markdown = blocksToMarkdown(content as any)
            return {
              direction: input.direction,
              char_count: markdown.length,
              markdown
            }
          }
    
          default:
            throw new Error(`Unsupported direction: ${input.direction}`)
        }
      })()
    }
  • TypeScript interface defining the expected input shape for the contentConvert handler.
    export interface ContentConvertInput {
      direction: 'markdown-to-blocks' | 'blocks-to-markdown'
      content: string | any[]
    }
  • MCP tool registration in the TOOLS array, defining name, description, and input schema for content_convert.
    {
      name: 'content_convert',
      description: 'Convert: markdown-to-blocks, blocks-to-markdown. Most tools handle markdown automatically.',
      inputSchema: {
        type: 'object',
        properties: {
          direction: {
            type: 'string',
            enum: ['markdown-to-blocks', 'blocks-to-markdown'],
            description: 'Conversion direction'
          },
          content: { description: 'Content to convert (string or array/JSON string)' }
        },
        required: ['direction', 'content']
      }
    },
  • Dispatch logic in the tool call handler that invokes the contentConvert function.
    case 'content_convert':
      result = await contentConvert(args as any)
      break
  • Import statement bringing the contentConvert handler into the registry module.
    import { contentConvert } from './composite/content.js'

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