|
|
|
@ -84,6 +84,16 @@ public class McpServerRegistrar {
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向JSON Schema对象添加方法参数的属性定义
|
|
|
|
|
*
|
|
|
|
|
* @param schema JSON Schema对象,用于存储参数属性定义(包含类型、描述等元数据)
|
|
|
|
|
* @param parameter 方法参数对象,包含参数名称、类型及注解等元数据信息
|
|
|
|
|
* @note 核心处理逻辑:<br>
|
|
|
|
|
* 1. 若JSON Schema中不存在"properties"字段,则自动创建该对象<br>
|
|
|
|
|
* 2. 根据参数类型通过{@link #jsonTypeMapper(Parameter)}映射JSON Schema类型<br>
|
|
|
|
|
* 3. 为参数构建属性定义(包含类型和@P注解描述信息)并添加至"properties"字段
|
|
|
|
|
*/
|
|
|
|
|
private void putProperties(ObjectNode schema, Parameter parameter) {
|
|
|
|
|
// 处理参数
|
|
|
|
|
String typeName = jsonTypeMapper(parameter);
|
|
|
|
@ -100,6 +110,17 @@ public class McpServerRegistrar {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将Java方法参数类型映射为JSON Schema类型字符串
|
|
|
|
|
*
|
|
|
|
|
* @param parameter 方法参数对象,包含参数类型元数据信息
|
|
|
|
|
* @return 对应的JSON Schema类型字符串,如'boolean'、'number'、'string'、'array'或'object'
|
|
|
|
|
* @note 核心映射规则:<br>
|
|
|
|
|
* - 基础类型:boolean→'boolean',char→'string',数值型基础类型(int/long/float等)→'number'<br>
|
|
|
|
|
* - 包装类型:Number子类→'number',Boolean→'boolean',String→'string'<br>
|
|
|
|
|
* - 容器类型:数组/Collection→'array',Map→'object'<br>
|
|
|
|
|
* - 泛型类型:List/Set→'array',其余未明确匹配类型默认→'object'
|
|
|
|
|
*/
|
|
|
|
|
private String jsonTypeMapper(Parameter parameter) {
|
|
|
|
|
Class<?> paramType = parameter.getType();
|
|
|
|
|
Type genericType = parameter.getParameterizedType();
|
|
|
|
|