JavaScript / TypeScript beautify or minify
js_beautifyFormat JavaScript, TypeScript or JSX with js-beautify, or minify JavaScript/TypeScript by removing comments and whitespace (no renaming, no rewriting; line breaks are kept where automatic semicolon insertion needs them). The output is re-lexed and compared token by token with the input.
Returns: Text: the formatted or minified code. structuredContent { code, mode, inputBytes, outputBytes, savedPercent, warnings[] }.
Example input: {"code":"function add(a,b){return a+b}","mode":"beautify","language":"javascript","indent":2,"brace_style":"collapse","keep_license":true}
On error, includes hint: Pass the whole file as code. An unterminated string, comment or regex is reported with its line and column.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "js_beautify"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Source code to format or minify. | |
| mode | No | beautify = pretty-print, minify = strip comments and whitespace. | beautify |
| indent | No | Spaces per indent level when beautifying (0 = tabs). | |
| language | No | Language of the code. TypeScript gets generic and optional-marker fix-ups; JSX cannot be minified. | javascript |
| brace_style | No | Brace placement when beautifying: collapse = K&R (same line), expand = Allman (own line). | collapse |
| keep_license | No | When minifying, keep /*! ... */ and @license comments. |