Skip to main content
Glama
paladini

devutils-mcp-server

json_format

Format JSON strings with customizable indentation or minify them for cleaner, more readable code.

Instructions

Format (pretty-print) a JSON string with configurable indentation. Can also minify JSON.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesThe JSON string to format
indentNoNumber of spaces for indentation (0 = minify, default: 2)

Implementation Reference

  • The handler function for 'json_format' which takes the input JSON string and an optional indentation level, parses the input, and returns the formatted (or minified) JSON string.
    async ({ input, indent }) => {
      try {
        const parsed = JSON.parse(input);
        const formatted =
          indent === 0
            ? JSON.stringify(parsed)
            : JSON.stringify(parsed, null, indent);
        return { content: [{ type: "text" as const, text: formatted }] };
      } catch (e) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: Invalid JSON — ${e instanceof Error ? e.message : String(e)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition using Zod for 'json_format', defining the required input string and optional integer indent level.
    {
      input: z.string().describe("The JSON string to format"),
      indent: z
        .number()
        .int()
        .min(0)
        .max(8)
        .default(2)
        .describe("Number of spaces for indentation (0 = minify, default: 2)"),
    },
  • Registration of the 'json_format' tool in the MCP server using server.tool.
    server.tool(
      "json_format",
      "Format (pretty-print) a JSON string with configurable indentation. Can also minify JSON.",
      {
        input: z.string().describe("The JSON string to format"),
        indent: z
          .number()
          .int()
          .min(0)
          .max(8)
          .default(2)
          .describe("Number of spaces for indentation (0 = minify, default: 2)"),
      },
      async ({ input, indent }) => {
        try {
          const parsed = JSON.parse(input);
          const formatted =
            indent === 0
              ? JSON.stringify(parsed)
              : JSON.stringify(parsed, null, indent);
          return { content: [{ type: "text" as const, text: formatted }] };
        } catch (e) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: Invalid JSON — ${e instanceof Error ? e.message : String(e)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );

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

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