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: Maven Project Generator MCP
工具:generate_boilerplate
解析指定 .java 文件中的实体类,生成缺失的样板方法并写回原文件。
参数
参数 | 类型 | 默认 | 说明 |
|
| 必填 | Java 实体类的绝对路径 |
|
|
| 要只补缺失的方法类型子集,仅接受 |
|
|
| setter 返回风格: |
|
|
| 为 |
|
| 后 5 类 | 要删旧重建的方法类型子集,可选值为全部 7 种: |
冲突:同一访问器类型(getter 或 setter)不能同时出现在
generate与regenerate中——"只补缺失"与"删旧重建"对同一访问器互斥。冲突时工具返回error="conflict"并给出说明,不写回文件,需重新调用二选一。同理,把 5 类放入generate也会触发该错误(它们只能经regenerate请求)。
行为规则
generate(仅 getter/setter):只补缺失——只为缺少访问器的字段生成,保留手写逻辑。regenerate(全部 7 种皆可):删旧重建——删除旧方法后重新生成。equals/hashCode/toString/构造器只能经此参数请求;getter/setter 列入则改为删旧重建。默认(不传参):生成全部 7 种——
generate默认[getter,setter]补缺失,regenerate默认后 5 类删旧重建。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 链在运行时自洽正确。
Available Tools
1 toolgenerate_boilerplateA
为 Java 实体类生成显式的样板方法并写回原文件(替代 Lombok)。
解析指定 .java 文件中的实体类,生成 IDE 标准风格的 getter/setter/ equals/hashCode/toString/无参构造/全参构造。
两个参数表达如何生成方法,互为补充:
generate(仅 getter/setter):只补缺失——只为缺少访问器的字段生成, 保留手写逻辑(如带校验的 setter)。regenerate(全部 7 种皆可):删旧重建——删除旧方法后重新生成。这是 请求 equals/hashCode/toString/构造器的唯一途径(它们没有"只补缺失"模式), 也是把 getter/setter 从"补缺失"切换为"重建"的方式(适合改 setter 风格等)。
冲突:同一访问器类型(getter 或 setter)不能同时出现在 generate 与
regenerate 中——"只补缺失"与"删旧重建"对同一访问器是矛盾的。冲突时工具
返回 error="conflict" 并给出说明,不写回文件,需重新调用二选一。
不传任何方法参数 = 生成全部 7 种(generate 默认 getter/setter 补缺失,
regenerate 默认后 5 类删旧重建)。
| Name | Required | Description | Default |
|---|---|---|---|
| generate | No | 要**只补缺失**的方法类型子集,**仅接受** `"getter"`、`"setter"`。 默认 `["getter","setter"]`。其余 5 类不能放这里,请用 `regenerate`。 | |
| file_path | Yes | Java 实体类的绝对路径。 | |
| regenerate | No | 要**删旧重建**的方法类型子集,可选值全部 7 种: `"getter"`、`"setter"`、`"equals"`、`"hashCode"`、`"toString"`、 `"no_args_ctor"`、`"all_args_ctor"`。默认后 5 类(equals/hashCode/ toString/构造器)——它们只能经此参数请求。把 getter/setter 列入 此参数则改为删旧重建(用于切换风格等重构)。注意:同一访问器不得 同时在 `generate` 与 `regenerate` 中,否则触发冲突错误。 | |
| setter_style | No | setter 返回风格,"void"(默认,传统)或 "fluent"(返回 this,支持链式调用)。 | void |
| include_super_fields | No | 为 true 时,equals 前置 super.equals(o)、 hashCode 加 super.hashCode()。要求父类也由本工具生成 equals/ hashCode(instanceof 模式),以保证父子类比较自洽。 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden and does disclose key behaviors: it writes back to the file, preserves handwritten logic in generate mode, deletes old methods in regenerate mode, and returns error="conflict" without writing on conflicts. It does not cover permissions or error cases like invalid file paths, but the core behavioral traits are clearly stated.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is dense but well-organized: purpose is front-loaded, the two modes are clearly separated, and the conflict rule is highlighted. The length is justified by the conceptual complexity of the parameter interplay, and every sentence adds useful information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a five-parameter tool with no siblings, the description covers defaults, mode-specific usage, conflict outcomes, and the full set of method types. Combined with 100% schema description coverage and the presence of an output schema, nothing critical is missing for correct tool invocation.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so the baseline is 3, but the description adds substantial meaning beyond the schema. It explains the complementary semantics of generate vs regenerate, the defaults when parameters are omitted, and the conflict constraint that prevents certain combinations. This turns raw parameter lists into actionable decision guidance.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific action: generate explicit boilerplate methods for Java entity classes and write them back to the original file. It names the seven method types covered, so the resource and scope are unambiguous even without sibling tools.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description explicitly contrasts the two generation modes: generate is for filling only missing getters/setters, while regenerate is the only path for equals/hashCode/toString/constructors. It also warns about the conflict condition and tells the agent to choose one mode when a conflict occurs.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
v0.1.0- First observed
generate_boilerplate
TDQS
Only one tool exists, so agents cannot confuse it with another. The internal generate/regenerate modes are clearly separated and described, avoiding ambiguity within the tool itself.
The single tool name follows a clear lowercase snake_case verb_noun pattern. With no other tools, there are no naming inconsistencies to evaluate.
One tool feels slightly thin for a boilerplate generator, but the tool is non-trivial and packs multiple operations into well-organized parameters. It sits at the borderline end of the appropriate range.
The tool covers generated getters/setters, equals/hashCode, toString, and both constructors, which covers the main entities boilerplate. It lacks Lombok-style extras like builder or with methods, leaving minor gaps for agents to work around.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Ship better Java with your coding agent.
Governance copilot for AI-assisted coding. 72 packs, 532 rules, proof bundles.
Turn PRDs and product ideas into structured specs so coding agents build your intent, not theirs.
AI Agent with Architectural Memory. Impact analysis (free), tests and code from the graph (pro).
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceEnables generation of enterprise-grade software templates with built-in GDPR/Swedish compliance validation, workflow automation for platform migrations, and comprehensive template management through domain-driven design principles.-
- FlicenseAqualityDmaintenanceEnables automatic generation of complete Maven projects (applications, plugins, libraries) with intelligent package detection, customizable file structure, and integrated ZIP export functionality.81-
- AlicenseBqualityCmaintenanceEnables reverse engineering of database tables into Spring Boot projects with AI-enhanced naming and code generation, providing interactive visualizations and workflow orchestration.291535MIT
- FlicenseAqualityDmaintenanceGenerates complete, production-ready REST, GraphQL, and microservice APIs with built-in security, validation, and deployment configurations.5-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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