generate_code
MCP tools › Code insight and refactoring
Generate code in the Java class around a line from its non-static fields, like the Generate menu: constructor, getters, setters, getters_and_setters, equals_hash_code or to_string; Java template picks one of generate_choices. Existing methods are not duplicated; imports are added. In Kotlin classes: secondary constructor, equals_hash_code and to_string over properties; data classes are refused. Dry run unless dry_run false, which writes the file and refuses if it changed meanwhile.
Its results carry text from files, language_server: the client is told to treat that as data, never as instructions.
| Capability | code.generate_code |
|---|---|
| Area | Code insight and refactoring |
| Access | changes files |
| Reaches | — |
| Rights | write |
| Dry run | dry_run, on unless the call turns it off |
Arguments
| Argument | Type | Description |
|---|---|---|
pathrequired | string | Workspace-relative .java file. |
linerequired | integer | 1-based line inside the class to generate in.minimum 0 |
kindrequired | string | string | string | string | string | string | What to generate. |
fields | array of string | Java only: the field names to use (default: every field; empty is allowed for a constructor). |
template | string | Java only: the template, as generate_choices lists it (default default). |
override_annotation | boolean | Java to_string only: add @Override (default true). |
dry_run | boolean | Only return the edits and the new text (default true). |
Call it from a shell
ferris-idea call runs one tool with the rights and safe mode of ferris-idea mcp. Replace the folder and the placeholder values.
ferris-idea call ~/my-project generate_code '{"path":"<string>","line":1,"kind":"<value>"}'Input schema as JSON
{ "properties": { "path": { "description": "Workspace-relative `.java` file.", "type": "string" }, "line": { "description": "1-based line inside the class to generate in.", "type": "integer", "minimum": 0 }, "kind": { "description": "What to generate.", "$ref": "#/$defs/GenerateKindArg" }, "fields": { "description": "Java only: the field names to use (default: every field; empty is allowed for a constructor).", "type": [ "array", "null" ], "items": { "type": "string" } }, "template": { "description": "Java only: the template, as `generate_choices` lists it (default `default`).", "type": [ "string", "null" ] }, "override_annotation": { "description": "Java `to_string` only: add `@Override` (default true).", "type": [ "boolean", "null" ] }, "dry_run": { "description": "Only return the edits and the new text (default true).", "type": [ "boolean", "null" ] } }, "$defs": { "GenerateKindArg": { "description": "What `generate_code` makes.", "oneOf": [ { "description": "A constructor taking the fields.", "type": "string", "const": "constructor" }, { "description": "Getters.", "type": "string", "const": "getters" }, { "description": "Setters for non-final fields.", "type": "string", "const": "setters" }, { "description": "Getters and setters.", "type": "string", "const": "getters_and_setters" }, { "description": "`equals` and `hashCode`.", "type": "string", "const": "equals_hash_code" }, { "description": "`toString`.", "type": "string", "const": "to_string" } ] } }, "required": [ "path", "line", "kind" ], "type": "object"}