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
| Name | Required | Description | Default |
|---|---|---|---|
| yaml | Yes | YAML 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"), },
- src/tools/data_format/format_yaml/index.ts:4-72 (registration)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`, }, ], }; } } ); }