js.beautify
Format and beautify JavaScript code for improved readability during security analysis and vulnerability testing.
Instructions
Beautify and format JavaScript source code
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | JavaScript source code | |
| indentSize | No | Indentation size |
Implementation Reference
- src/tools/js.ts:59-75 (handler)The handler function for the 'js.beautify' tool. It takes JS source code, optionally an indent size, beautifies it using the 'js-beautify' library, and returns the formatted code along with length metrics.async ({ source, indentSize = 2 }: any): Promise<ToolResult> => { try { const beautified = beautify.js(source, { indent_size: indentSize, space_in_empty_paren: true, preserve_newlines: true, }); return formatToolResult(true, { beautified, originalLength: source.length, beautifiedLength: beautified.length, }); } catch (error: any) { return formatToolResult(false, null, error.message); } }
- src/tools/js.ts:50-57 (schema)Input schema for the 'js.beautify' tool, defining required 'source' string and optional 'indentSize' number.inputSchema: { type: 'object', properties: { source: { type: 'string', description: 'JavaScript source code' }, indentSize: { type: 'number', description: 'Indentation size', default: 2 }, }, required: ['source'], },
- src/tools/js.ts:47-76 (registration)Registers the 'js.beautify' tool on the MCP server within the registerJsTools function, including schema and handler.'js.beautify', { description: 'Beautify and format JavaScript source code', inputSchema: { type: 'object', properties: { source: { type: 'string', description: 'JavaScript source code' }, indentSize: { type: 'number', description: 'Indentation size', default: 2 }, }, required: ['source'], }, }, async ({ source, indentSize = 2 }: any): Promise<ToolResult> => { try { const beautified = beautify.js(source, { indent_size: indentSize, space_in_empty_paren: true, preserve_newlines: true, }); return formatToolResult(true, { beautified, originalLength: source.length, beautifiedLength: beautified.length, }); } catch (error: any) { return formatToolResult(false, null, error.message); } } );
- src/tools/js.ts:3-3 (helper)Imports the 'js-beautify' library used by the js.beautify tool handler.import beautify from 'js-beautify';
- src/index.ts:36-36 (registration)Top-level call to registerJsTools, which includes registration of the 'js.beautify' tool.registerJsTools(server);