Skip to content

refactor(module): 消费 pub.ihub.module:ihub-module-core 替代自有双实现模型 - #6

Merged
henry-hub merged 1 commit into
mainfrom
refactor/use-module-core
Aug 23, 2026
Merged

henry-hub merged 1 commit into
mainfrom
refactor/use-module-core

Conversation

@henry-hub

Copy link
Copy Markdown
Member

变更概要

审计缺口 #7:消除 agents 与 modules 的 ModuleDescriptor 双实现,两仓模型统一。

背景

agents mcp-server 自带 ModuleDescriptor / ModuleCapability / McpToolDefinition 三个 record,
与 modules ihub-module-core:0.3.0 模型结构相同但代码独立——schema 漏进同一处则两仓都得改、
且 agents 侧没有 @JsonIgnoreProperties,解析真实 iam descriptor(含 $schema)会炸。

前置合并(已完成)

  • modules #377:module-core 加 @JsonIgnoreProperties(ignoreUnknown = true) + 契约测试,发 0.3.1(已上 Central)

变更

  • 删除 mcp-server/.../module/ModuleDescriptor.java(含内部 ModuleCapability/McpToolDefinition)
  • mcp-server/build.gradle.kts:加 implementation("pub.ihub.module:ihub-module-core:0.3.1")
  • ModuleService:import 改为 pub.ihub.module.core.ModuleDescriptor
  • ModuleTools:import ModuleDescriptor / McpToolDefinition(均为 module-core top-level record);
    m.status() 从 String→enum → .name() 序列化为 JSON 字符串

验证

  • ./gradlew build ✓(本地 JDK 25,0.3.1 从 Central 解析)

契约保障

  • modules 侧已有 ModuleDescriptorContractTest(解析真实 iam descriptor + 未来未知字段容错)——
    agents 不需要单独加测试,consumption 隐式受此契约保护

- 删除 agents 自有 ModuleDescriptor/ModuleCapability/McpToolDefinition(3 个 record),改用
  pub.ihub.module:ihub-module-core 0.3.1(modules 发布,加了 @JsonIgnoreProperties 容错)
- ModuleService/ModuleTools import 变更:pub.ihub.module.core.* 替代自有包
- m.status() 从 String 变 enum → ModuleTools 用 .name() 序列化为 JSON 字符串
- 0.3.1 的容错反序列化(忽略 /required 等模型外字段)是本次依赖切换的前提(见 modules #377)
- 消除双实现:两仓模型统一,未来 schema 演进只改 module-core 一处
Copilot AI lite review requested due to automatic review settings August 23, 2026 14:16
@ihub-bot ihub-bot Bot added this to the 0.1.0 milestone Aug 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 通过直接依赖 pub.ihub.module:ihub-module-core:0.3.1 来统一 agents 与 modules 两仓的 ModuleDescriptor / McpToolDefinition 等模型,消除 agents 侧自维护的重复实现,并修复解析真实 descriptor(含未知字段如 $schema)时的兼容性问题。

Changes:

  • 删除 mcp-server 内自有的 ModuleDescriptor(及内嵌 ModuleCapability/McpToolDefinition)实现,改为消费 ihub-module-core 的模型。
  • ModuleService/ModuleTools 替换为 pub.ihub.module.core.* 的类型引用,并调整模块工具列表返回类型。
  • mcp-server 增加 ihub-module-core:0.3.1 依赖;status 输出由 String 迁移到 enum 后显式序列化为字符串。

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
mcp-server/src/main/java/pub/ihub/agent/mcp/tools/ModuleTools.java 切换到 module-core 的 ModuleDescriptor/McpToolDefinition,并调整 status 输出与工具列表类型。
mcp-server/src/main/java/pub/ihub/agent/mcp/module/ModuleService.java 使用 module-core 的 ModuleDescriptor 反序列化并返回 module-core 的工具定义列表。
mcp-server/src/main/java/pub/ihub/agent/mcp/module/ModuleDescriptor.java 删除 agents 自有重复模型实现(由 module-core 替代)。
mcp-server/build.gradle.kts 添加 ihub-module-core:0.3.1 依赖以消费统一模型。
Suppressed comments (1)

mcp-server/src/main/java/pub/ihub/agent/mcp/tools/ModuleTools.java:91

  • Same as above: .name() can change the externally visible status string (and bypass any @JsonValue / toString() mapping) and can NPE if status is null. Prefer passing the enum through to JSON serialization.
        map.put("status", m.status().name());

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

detail.put("version", m.version());
detail.put("domain", m.domain());
detail.put("status", m.status());
detail.put("status", m.status().name());
Comment on lines +81 to 84
public List<pub.ihub.module.core.McpToolDefinition> listTools(String moduleId) {
return findById(moduleId)
.map(m -> m.mcpTools() != null ? m.mcpTools() : List.<ModuleDescriptor.McpToolDefinition>of())
.map(m -> m.mcpTools() != null ? m.mcpTools() : List.<pub.ihub.module.core.McpToolDefinition>of())
.orElse(List.of());
implementation(libs.spring.boot.starter.web)
implementation(libs.spring.ai.starter.mcp.server)
implementation(libs.ihub.migrate.analyzer)
implementation("pub.ihub.module:ihub-module-core:0.3.1")
@henry-hub
henry-hub merged commit 1c0333b into main Aug 23, 2026
5 checks passed
@henry-hub
henry-hub deleted the refactor/use-module-core branch August 23, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants