UNPKG

fu-orm-code-generator

Version:

A Model Context Protocol (MCP) server for MyBatis code generation with enterprise-grade layered architecture

118 lines (87 loc) โ€ข 3.55 kB
# Fu ORM Code Generator A Model Context Protocol (MCP) server for MyBatis code generation with enterprise-grade layered architecture. ## Features - ๐Ÿš€ **Batch Code Generation**: Generate ORM code for multiple database tables at once - ๐Ÿ—๏ธ **Enterprise Architecture**: Built with layered architecture and dependency injection - ๐Ÿ”„ **Smart Conversion**: Automatically converts database field names (snake_case) to Java property names (camelCase) - ๐Ÿ“‹ **Template Support**: Multiple code generation templates including MyBatis Plus and enterprise patterns - ๐ŸŽฏ **Type Mapping**: Comprehensive database type to Java type mapping - ๐Ÿ“ **Rich Documentation**: Generated code includes complete Javadoc comments ## Installation ```bash npm install -g fu-orm-code-generator ``` ## Usage This MCP server provides tools for generating MyBatis ORM code. It's designed to work with MCP-compatible clients like Claude Desktop. ### Available Tools 1. **generate_orm_code**: Batch generate ORM code from database table structures 2. **visit_online_templates**: Browse available online templates 3. **download_online_template**: Download templates from remote server 4. **choose_local_template**: Select a local template for code generation 5. **visit_local_templates**: View locally available templates 6. **set_user_info**: Configure user information for code comments 7. **get_user_info**: View current user configuration ### Example Usage ```javascript // Generate ORM code for multiple tables { "basePackage": "com.example.project", "mainSourceDirectory": "/path/to/project/src/main/java", "tables": [ { "tableName": "user_info", "remark": "User information table", "fields": [ { "fieldName": "id", "dataType": "BIGINT", "remark": "User ID" }, { "fieldName": "user_name", "dataType": "VARCHAR", "remark": "Username" } ] } ] } ``` ## Generated Code Structure For a table named `user_info`, the generator creates: - Entity: `com.example.entity.UserInfo.java` - Mapper: `com.example.mapper.UserInfoMapper.java` - Repository: `com.example.repository.IUserInfoRepository.java` - Service: `com.example.service.IUserInfoService.java` - Controller: `com.example.controller.UserInfoController.java` ## Type Mappings | Database Type | Java Type | |---------------|-----------| | TINYINT, SMALLINT, INT, INTEGER | java.lang.Integer | | BIGINT | java.lang.Long | | FLOAT, DOUBLE, DECIMAL, NUMERIC | java.math.BigDecimal | | CHAR, VARCHAR, TEXT, etc. | java.lang.String | | DATE, TIME, DATETIME, TIMESTAMP | java.lang.String | | BOOLEAN, BOOL, BIT | java.lang.Boolean | ## Configuration The server stores configuration in `data/config.json` and supports: - Template selection - User information (author name and email) - Custom template directories ## Templates Two built-in templates are available: 1. **mybatis_plus**: Standard MyBatis Plus template 2. **ๆœŸ่ดง็ฎก็†ๅนณๅฐ(ๆ— ้œ€ๅฎกๆ‰น)**: Enterprise futures management platform template ## Architecture The project follows a clean layered architecture: - **Presentation Layer**: MCP tool handlers - **Application Layer**: Business logic services - **Domain Layer**: Core entities and repository interfaces - **Infrastructure Layer**: Concrete implementations ## Requirements - Node.js >= 16.0.0 - MCP-compatible client (e.g., Claude Desktop) ## License MIT ## Contributing Contributions are welcome! Please feel free to submit a Pull Request.