Skip to main content
Glama
brendon92

Specialized AI Search Tools

by brendon92

typeconversion

Convert data between JSON, XML, YAML, CSV, and TOML formats with options for pretty printing, minification, and format-specific settings like CSV delimiters.

Instructions

Convert data between different formats: JSON, XML, YAML, CSV, and TOML. Supports pretty printing, minification, and format-specific options like CSV delimiters and headers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesInput data as string
fromFormatYesSource data format
toFormatYesTarget data format
optionsNo

Implementation Reference

  • Registration function that instantiates the TypeConversionTool and registers it along with other tools to the MCP server using server.registerTools
    export function registerAllTools(server: MCPServer): void { const tools: BaseTool[] = [ new WebSearchTool(), new WebFetchTool(), new TypeConversionTool(), ]; // Register all tools if (tools.length > 0) { server.registerTools(tools); logger.info(`Registered ${tools.length} tool(s): ${tools.map(t => t.name).join(', ')}`); } else { logger.warn('No tools registered - add tool implementations to src/tools/index.ts'); } }
  • Zod schemas defining supported formats, conversion options, input parameters (TypeConversionParams) for the typeconversion tool
    const formatEnum = z.enum(['json', 'xml', 'yaml', 'csv', 'toml']); type DataFormat = z.infer<typeof formatEnum>; /** * Conversion options schema */ const conversionOptionsSchema = z .object({ pretty: z.boolean().optional().default(true).describe('Pretty print output (with indentation)'), indent: z.number().int().min(0).max(8).optional().default(2).describe('Indentation spaces for pretty printing'), csvDelimiter: z.string().optional().default(',').describe('CSV delimiter character'), csvHeaders: z.boolean().optional().default(true).describe('CSV has headers in first row'), }) .optional(); /** * Type conversion tool schema */ const typeConversionSchema = z.object({ input: z.string().min(1).describe('Input data as string'), fromFormat: formatEnum.describe('Source data format'), toFormat: formatEnum.describe('Target data format'), options: conversionOptionsSchema, }); type TypeConversionParams = z.infer<typeof typeConversionSchema>;
  • TypeConversionTool class with name, description, schema reference, and execute handler method that orchestrates parsing input to JS object and formatting to target output using private helpers
    export class TypeConversionTool extends BaseTool<typeof typeConversionSchema> { readonly name = 'typeconversion'; readonly description = 'Convert data between different formats: JSON, XML, YAML, CSV, and TOML. Supports pretty printing, minification, and format-specific options like CSV delimiters and headers.'; readonly schema = typeConversionSchema; protected async execute(params: TypeConversionParams): Promise<string> { logger.info(`Converting from ${params.fromFormat} to ${params.toFormat}`); try { // Parse input to intermediate format (JavaScript object) const data = await this.parseInput(params.input, params.fromFormat, params.options); // Convert to target format const output = await this.formatOutput(data, params.toFormat, params.options); logger.info(`Conversion completed successfully`); return output; } catch (error) { throw new Error( `Conversion failed: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
  • parseInput helper: dispatches input parsing based on fromFormat to specific parser methods
    private async parseInput( input: string, format: DataFormat, options?: z.infer<typeof conversionOptionsSchema> ): Promise<any> { switch (format) { case 'json': return this.parseJson(input); case 'xml': return await this.parseXmlToObject(input); case 'yaml': return this.parseYaml(input); case 'csv': return this.parseCsvToObject(input, options); case 'toml': return this.parseToml(input); default: throw new Error(`Unsupported input format: ${format}`); } }
  • formatOutput helper: dispatches object formatting based on toFormat to specific formatter methods
    private async formatOutput( data: any, format: DataFormat, options?: z.infer<typeof conversionOptionsSchema> ): Promise<string> { switch (format) { case 'json': return this.formatJson(data, options); case 'xml': return await this.formatXml(data, options); case 'yaml': return this.formatYaml(data, options); case 'csv': return this.formatCsv(data, options); case 'toml': return this.formatToml(data); default: throw new Error(`Unsupported output format: ${format}`); } }

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

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