Skip to main content
Glama

yaml-format

Format and prettify YAML strings for improved readability and consistency. Simplify YAML structure for better management and deployment in development workflows.

Instructions

Format and prettify YAML

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yamlYesYAML string to format

Implementation Reference

  • The handler function that parses the input YAML using js-yaml, reformats it with 2-space indentation and other options, computes line stats, and returns formatted content or error diagnostics.
    }, async ({ yaml }) => { try { const YAML = await import("js-yaml"); // Parse YAML to validate and then dump with proper formatting const parsed = YAML.load(yaml); // Format with proper indentation and options const formatted = YAML.dump(parsed, { indent: 2, lineWidth: 80, noRefs: false, noCompatMode: false, condenseFlow: false, quotingType: '"', forceQuotes: false, sortKeys: false, skipInvalid: false, }); // Count lines and detect any issues const inputLines = yaml.split('\n').length; const outputLines = formatted.split('\n').length; return { content: [ { type: "text", text: `Formatted YAML: ${formatted.trim()} ✅ YAML is valid and properly formatted 📊 Input: ${inputLines} lines → Output: ${outputLines} lines 🎯 Features: 2-space indentation, proper line width, preserved structure`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error formatting YAML: ${error instanceof Error ? error.message : 'Unknown error'} 💡 Common YAML issues: • Check indentation (use spaces, not tabs) • Ensure proper key-value syntax (key: value) • Validate string quoting • Check list formatting (- item) • Verify nested structure alignment`, }, ], }; } }
  • Zod schema defining the tool's input: a 'yaml' string parameter.
    inputSchema: { yaml: z.string().describe("YAML string to format"), },
  • Registers the 'format_yaml' tool (YAML formatter) with the MCP server, including description, schema, annotations, and handler reference. Note: tool name is 'format_yaml', matching the YAML formatting functionality.
    export function registerFormatYaml(server: McpServer) { server.registerTool("format_yaml", { description: "Format and prettify YAML", inputSchema: { yaml: z.string().describe("YAML string to format"), }, // VS Code compliance annotations annotations: { title: "Format Yaml", description: "Format and prettify YAML", readOnlyHint: false } }, async ({ yaml }) => { try { const YAML = await import("js-yaml"); // Parse YAML to validate and then dump with proper formatting const parsed = YAML.load(yaml); // Format with proper indentation and options const formatted = YAML.dump(parsed, { indent: 2, lineWidth: 80, noRefs: false, noCompatMode: false, condenseFlow: false, quotingType: '"', forceQuotes: false, sortKeys: false, skipInvalid: false, }); // Count lines and detect any issues const inputLines = yaml.split('\n').length; const outputLines = formatted.split('\n').length; return { content: [ { type: "text", text: `Formatted YAML: ${formatted.trim()} ✅ YAML is valid and properly formatted 📊 Input: ${inputLines} lines → Output: ${outputLines} lines 🎯 Features: 2-space indentation, proper line width, preserved structure`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error formatting YAML: ${error instanceof Error ? error.message : 'Unknown error'} 💡 Common YAML issues: • Check indentation (use spaces, not tabs) • Ensure proper key-value syntax (key: value) • Validate string quoting • Check list formatting (- item) • Verify nested structure alignment`, }, ], }; } } ); }

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/wrenchpilot/it-tools-mcp'

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