Skip to content

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.

Capabilitycode.generate_code
AreaCode insight and refactoring
Accesschanges files
Reaches—
Rightswrite
Dry rundry_run, on unless the call turns it off

Arguments

ArgumentTypeDescription
pathrequiredstringWorkspace-relative .java file.
linerequiredinteger1-based line inside the class to generate in.minimum 0
kindrequiredstring | string | string | string | string | stringWhat to generate.
fieldsarray of stringJava only: the field names to use (default: every field; empty is allowed for a constructor).
templatestringJava only: the template, as generate_choices lists it (default default).
override_annotationbooleanJava to_string only: add @Override (default true).
dry_runbooleanOnly 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.

Terminal window
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"
}