AI-enhanced Java code generator based on MCP service architecture for Spring Boot projects from database schemas
DBJavaGenix provides 17 tools with mostly complete JSON Schema definitions and descriptions in English and Chinese. Naming follows verb_noun patterns consistently (ai_infer_*, codegen_render_*, schema_*). However, several tools lack output schema documentation, parameter descriptions are sometimes generic or incomplete, and error handling guidance is minimal. Parameter defaults are generally reasonable. Tool composition is solid, tools are atomic and chainable (e.g., codegen_build_context → codegen_render_entity). The server demonstrates good understanding of MCP patterns but falls short of production grade due to incomplete output documentation and missing error recovery guidance.
从数据库表/列推断 Spring Boot 项目中**业务上合理的 Java 命名**。默认基于 15 条命名规则; 设 prefer_llm=true 且 ANTHROPIC_API_KEY 可用时,优先调用 Claude (启用 prompt caching 节省 token)。返回每张表的 class_name + reason + table_kind (entity/association/log/dict/config)。
返回进程内累积的 AI 调用指标 (Prompt Caching 命中率、token 消耗、错误次数)。对应 P4.4: ai.cache_hit_rate / ai.tokens_saved_via_cache 等。可在每次 ai_infer_business_names 等工具调用后查询。
根据整库表名 + FK 关系推荐 template_category (Default/MybatisPlus/MybatisPlus-Mixed/sb35-java21) + 生成选项 (useSwagger/useLombok/include_mapstruct/generate_dto/generate_vo)。检测 RBAC / 电商 / CMS / 工单 等典型业务模式。传 hint_modern_stack=true 强制推 sb35-java21 (Java 21 + jakarta)。
对整库 schema 做自然语言概述: 总览、模块划分 (按前缀)、核心实体 (列数 + 命中模式)、关键关系。便于用户理解大库,或在生成前对齐 LLM 的 mental model。
构建代码生成所需的完整模板上下文(不写盘,不渲染)。这是原子代码生成工作流的第一步,后续 codegen_render_* 工具的输入。返回的 context dict 可被 LLM 检视或修改,再传给后续工具。
渲染 REST Controller(@RestController + Bean Validation)。需要先调用 codegen_build_context 获取 context。
Output schemas not documented for codegen_render_* tools (entity, dao, service, controller, dto, mapper). Tools return 'files' array but return type structure is not declared in source. LLMs cannot plan downstream operations or extract relevant fields without knowing the shape of the response.
Schema algorithm tools (schema_topo_order, schema_cluster_tables, schema_check_cycles) have minimal descriptions (<60 chars visible). Descriptions do not explain WHEN to call them or what problem they solve relative to each other. LLMs cannot distinguish use cases.
Error handling is not visible in tool implementations (sample code shows schema validation but no recovery guidance). Tools return errors but do not include actionable next steps. E.g., if ai_infer_business_names fails because ANTHROPIC_API_KEY is missing and prefer_llm=true, the error should suggest 'Set ANTHROPIC_API_KEY or set prefer_llm=false' instead of a bare exception.
| Scored | Grade | Overall | Spec posture | Rubric |
|---|---|---|---|---|
| 2026-09-22 | C | 62 | 2026-07-28+ | v2 |
| 2026-03-09 | F | 32 | - | v1 |
渲染 DAO/Repository 层(JpaRepository 或 BaseMapper)。需要先调用 codegen_build_context 获取 context。
渲染 sb35-java21 的 Java record DTO。需要先调用 codegen_build_context 获取 context;其他模板分类不生成 DTO。
渲染 Entity 层(JPA @Entity / MybatisPlus @TableName)。需要先调用 codegen_build_context 获取 context。返回单个 java 文件源码。
渲染 MyBatis XML mapper 或 MapStruct mapper。适用模板: Default(mapper.xml) / MybatisPlus-Mixed(mapper) / 含 useMapStruct(mapstruct_mapper)。sb35-java21 分类不需要 mapper,会返回空 files 列表。
渲染 Service 接口 + ServiceImpl 实现。需要先调用 codegen_build_context 获取 context。返回 2 个 java 文件。
Detect FK cycles in schema (anti-pattern). Returns cycles list and safe boolean. Self-references not reported as cycles.
Group tables into business clusters via Union-Find on FK connectivity. Returns clusters with suggested names (common prefix or central table).
Topologically sort tables by FK dependencies. Returns order safe for DDL creation or Service injection. Detects cycles via unresolved list.
按关键词搜索可用 MCP 工具,用于渐进式发现 (Progressive Discovery)。当用户提到的操作不在当前可见工具列表中时,先用此工具搜索,再调用返回的工具。示例: query='render dao' → 返回 codegen_render_dao + 相关工具。传空 query 列出所有 always_visible 工具。
返回 server 健康状态: Python 版本、mcp SDK 版本、核心模块导入是否成功、DB 连接活跃数、OS 信息。用于部署后冒烟检查。
返回 DBJavaGenix MCP server 的运行时指标: uptime、每个工具的调用次数 / 平均时延 / 错误率。轻量级 in-process,不依赖 Prometheus。
codegen_render_* tools accept a 'context' parameter described as 'dict' with informal inline documentation (e.g. 'LLM 应原样传递,可在传入前修改字段'). The context dict structure is not formally specified as a JSON Schema. Without formal schema, LLMs cannot validate inputs before sending, risking runtime failures.
ai_metrics and server_metrics tools have 'reset' parameter with default false, but no guidance on side effects. Calling with reset=true after metrics retrieval permanently clears counters, an irreversible operation. Description should warn of this consequence and explain when to use reset.
ai_tools.py shows Anthropic API key is checked via environment variable (ANTHROPIC_API_KEY), which is correct. However, the tool description does not explicitly state that this environment variable must be set when prefer_llm=true, risking silent fallback to rules without user awareness.