Skip to main content
Glama

Simple Document Processing MCP Server

format_convert

Convert documents between Markdown, HTML, XML, and JSON formats using clearly defined source and target formats for efficient document processing.

Instructions

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

Input Schema

NameRequiredDescriptionDefault
fromFormatYesSource format
inputYesInput content to convert
toFormatYesTarget format

Input Schema (JSON Schema)

{ "properties": { "fromFormat": { "description": "Source format", "enum": [ "markdown", "html", "xml", "json" ], "type": "string" }, "input": { "description": "Input content to convert", "type": "string" }, "toFormat": { "description": "Target format", "enum": [ "markdown", "html", "xml", "json" ], "type": "string" } }, "required": [ "input", "fromFormat", "toFormat" ], "type": "object" }

Implementation Reference

  • The main handler function that performs the actual format conversion logic between supported formats (Markdown, HTML, XML, JSON).
    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, }; } }
  • Tool definition including the input schema for format_convert tool.
    export const FORMAT_CONVERTER_TOOL: Tool = { name: "format_convert", description: "Convert between different document formats (Markdown, HTML, XML, JSON)", 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 (FORMAT_CONVERTER_TOOL) in the main tools export array.
    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];
  • TypeScript interface defining the input arguments for the format converter.
    export interface FormatConverterArgs { input: string; fromFormat: FormatType; toFormat: FormatType; }
  • Enum defining supported format types used in the tool.
    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