Skip to main content
Glama
cablate

Simple Document Processing MCP Server

format_convert

Convert document content between Markdown, HTML, XML, and JSON formats to enable cross-format compatibility and processing.

Instructions

Convert between different document formats (Markdown, HTML, XML, JSON)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesInput content to convert
fromFormatYesSource format
toFormatYesTarget format

Implementation Reference

  • The main handler function that performs the actual format conversion logic, validating inputs and dispatching to specific helper converters based on from/to format pair.
    export async function convertFormat(input: string, fromFormat: FormatType, toFormat: FormatType) {
      try {
        console.log(`Converting from ${fromFormat} to ${toFormat}`);
    
        // Validate formats
        if (!Object.values(FormatType).includes(fromFormat)) {
          return {
            success: false,
            error: `Unsupported source format: ${fromFormat}`,
          };
        }
        if (!Object.values(FormatType).includes(toFormat)) {
          return {
            success: false,
            error: `Unsupported target format: ${toFormat}`,
          };
        }
    
        // Handle different conversion paths
        let result: string;
        switch (`${fromFormat}-${toFormat}`) {
          case `${FormatType.MARKDOWN}-${FormatType.HTML}`:
            result = await markdownToHtml(input);
            break;
          case `${FormatType.HTML}-${FormatType.MARKDOWN}`:
            return {
              success: false,
              error: "HTML to Markdown conversion is not supported yet",
            };
          case `${FormatType.XML}-${FormatType.JSON}`:
            result = await xmlToJson(input);
            break;
          case `${FormatType.JSON}-${FormatType.XML}`:
            result = jsonToXml(input);
            break;
          default:
            return {
              success: false,
              error: `Unsupported conversion path: ${fromFormat} to ${toFormat}`,
            };
        }
    
        return {
          success: true,
          data: result,
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
        console.error(`Error converting format: ${errorMessage}`);
        return {
          success: false,
          error: errorMessage,
        };
      }
    }
  • Input JSON schema defining the parameters for the format_convert tool: input content, source format, and target format.
    inputSchema: {
      type: "object",
      properties: {
        input: {
          type: "string",
          description: "Input content to convert",
        },
        fromFormat: {
          type: "string",
          enum: Object.values(FormatType),
          description: "Source format",
        },
        toFormat: {
          type: "string",
          enum: Object.values(FormatType),
          description: "Target format",
        },
      },
      required: ["input", "fromFormat", "toFormat"],
    },
  • Registration of the format_convert tool (as FORMAT_CONVERTER_TOOL) in the central tools array exported for use in the MCP server.
    export const tools = [DOCUMENT_READER_TOOL, PDF_MERGE_TOOL, PDF_SPLIT_TOOL, DOCX_TO_PDF_TOOL, DOCX_TO_HTML_TOOL, HTML_CLEAN_TOOL, HTML_TO_TEXT_TOOL, HTML_TO_MARKDOWN_TOOL, HTML_EXTRACT_RESOURCES_TOOL, HTML_FORMAT_TOOL, TEXT_DIFF_TOOL, TEXT_SPLIT_TOOL, TEXT_FORMAT_TOOL, TEXT_ENCODING_CONVERT_TOOL, EXCEL_READ_TOOL, FORMAT_CONVERTER_TOOL];
  • Type guard function for validating input arguments match FormatConverterArgs.
    export function isFormatConverterArgs(args: unknown): args is FormatConverterArgs {
      return typeof args === "object" && args !== null && "input" in args && "fromFormat" in args && "toFormat" in args && typeof (args as FormatConverterArgs).input === "string" && Object.values(FormatType).includes((args as FormatConverterArgs).fromFormat) && Object.values(FormatType).includes((args as FormatConverterArgs).toFormat);
    }
  • Enumeration of supported format types used in schema and logic.
    export enum FormatType {
      MARKDOWN = "markdown",
      HTML = "html",
      XML = "xml",
      JSON = "json",
    }

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/cablate/mcp-doc-forge'

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