Java Boilerplate Generator MCP
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Java Boilerplate Generator MCPGenerate getter, setter, equals, hashCode, toString, and all-args constructor for src/main/java/com/example/User.java"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Java Boilerplate Generator MCP
一个 MCP(Model Context Protocol) 服务器,用于为 Java 实体类自动生成显式的样板方法(getter/setter/equals/hashCode/toString/构造函数),并写回原文件。
为什么需要它
AI 编码助手在为 Java 实体类生成样板代码时,倾向于直接加 Lombok 注解(@Data、@Getter 等)。这会引入对 Lombok 的隐式依赖,且生成的代码不可见、不可审查。本工具由 MCP 替代 AI 直接生成显式的、IDE 标准风格的 Java 方法,让实体类自带完整方法,无需 Lombok。
Related MCP server: MCP Java Testing Agent
工具:generate_boilerplate
解析指定 .java 文件中的实体类,生成缺失的样板方法并写回原文件。
参数
参数 | 类型 | 默认 | 说明 |
|
| 必填 | Java 实体类的绝对路径 |
|
| 全部 | 要生成的方法类型子集,可选值: |
|
|
| setter 返回风格: |
|
|
| 为 |
行为规则
getter/setter/构造器:按字段/方法级去重,只为缺失的生成,保留手写逻辑(如带校验的 setter)。
equals/hashCode/toString:
@Override方法,请求即生成;若已存在则删除旧方法重新生成。static/transient 字段:不参与生成(与 IDE 行为一致)。
风格:IDE 标准风格。equals 用
instanceof模式;对象字段用Objects.equals,基本类型用==;hashCode 用Objects.hash。Lombok:工具不解析 Lombok 语义,不处理与 Lombok 注解的冲突。
关于 include_super_fields 与继承
当 include_super_fields=true 时,子类的 equals/hashCode 会调用 super.equals(o) / super.hashCode()。由于 equals 使用 instanceof 模式(而非 getClass()),父类的 o instanceof Parent 对子类实例为 true,因此 super.equals(o) 能在父子类间正确传递——前提是父类也由本工具生成 equals/hashCode。
// 父类 Parent(由本工具生成)
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Parent)) return false; // Child 也是 Parent,通过
Parent other = (Parent) o;
return Objects.equals(this.id, other.id);
}
// 子类 Child(include_super_fields=true)
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Child)) return false;
Child other = (Child) o;
return super.equals(o) // 委托父类比较父类字段
&& Objects.equals(this.name, other.name); // 子类自己的字段
}注意:
instanceof模式 + 继承有一个固有的对称性副作用(parent.equals(child)可能为 true 而child.equals(parent)为 false),这是 IDE 生成代码的相同行为,实体类场景通常可接受。
安装与接入
前置要求
Python 3.14+
uv(用于管理依赖与运行)
接入 Claude Code
在 Claude Code 的 MCP 配置(~/.claude.json 或项目的 .mcp.json)中添加:
{
"mcpServers": {
"java-boilerplate": {
"command": "uvx",
"args": ["--from", "git+https://github.com/FlyDut/java-boilerplate-mcp", "python", "-m", "java_mcp.server"]
}
}
}接入 Claude Desktop
在 Claude Desktop 的配置文件(claude_desktop_config.json)中添加同样的 mcpServers 条目。
验证
# 运行测试
uv run pytest
# 启动服务器(stdio 模式,应显示 FastMCP 横幅后等待输入)
uv run python -m java_mcp.server使用示例
对 AI 说:
帮我为
src/main/java/com/example/User.java生成 getter、setter、equals、hashCode、toString 和构造函数,不要用 Lombok。
AI 会调用 generate_boilerplate 工具,工具读取文件、生成方法、写回原文件,并返回生成统计。
项目结构
src/java_mcp/
├── server.py # FastMCP 实例 + generate_boilerplate 工具 + 编排逻辑
├── parser.py # tree-sitter-java 解析 → ParsedFile/EntityClass/Field
├── model.py # 数据模型: Field, EntityClass, ParsedFile
├── detector.py # 检测已存在的 getter/setter/equals/hashCode/toString/构造
├── generator.py # 生成各方法的 Java 源码(IDE 标准风格)
└── writer.py # 插入方法 + import,替换旧 @Override 方法,写回文件测试
uv run pytest # 全部测试(含用 javac/java 的端到端验证)
uv run pytest tests/test_e2e.py -v # 端到端:编译运行生成的 Java 验证 equals 链端到端测试会用 javac 编译工具生成的 Java 文件并运行,验证父子类 equals/hashCode 链在运行时自洽正确。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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/FlyDut/java-boilerplate-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server