Skip to content

Commit 9737e20

Browse files
[tool] Upgrade tool compilation tool to adapt to mcp tool mode
1 parent 167f20b commit 9737e20

File tree

3 files changed

+58
-48
lines changed

3 files changed

+58
-48
lines changed

framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import modelengine.fel.tool.info.entity.ReturnPropertyEntity;
1515
import modelengine.fel.tool.info.entity.SchemaEntity;
1616
import modelengine.fitframework.annotation.Property;
17+
import modelengine.fitframework.util.StringUtils;
1718

1819
import net.bytebuddy.description.annotation.AnnotationDescription;
1920
import net.bytebuddy.description.method.MethodDescription;
@@ -77,8 +78,8 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
7778
if (returnPropertyEntity.getConvertor() != null) {
7879
returnProperty.put("convertor", returnPropertyEntity.getConvertor());
7980
}
80-
if (returnPropertyEntity.getExamples() != null) {
81-
returnProperty.put("examples", returnPropertyEntity.getExamples());
81+
if (StringUtils.isNotBlank(returnPropertyEntity.getExample())) {
82+
returnProperty.put("example", returnPropertyEntity.getExample());
8283
}
8384
return returnProperty;
8485
}
@@ -92,7 +93,7 @@ private static ParameterEntity parseParameter(MethodDescription methodDescriptio
9293
String methodName = parameterDescription.getName();
9394
PropertyEntity property = parseProperty(parameterDescription);
9495
properties.put(methodName, property);
95-
if (property.isRequired()) {
96+
if (property.isNeed()) {
9697
required.add(methodName);
9798
}
9899
}
@@ -112,9 +113,9 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
112113
if (paramAnnotation != null) {
113114
Property property = paramAnnotation.load();
114115
entity.setDescription(property.description());
115-
entity.setRequired(property.required());
116+
entity.setNeed(property.required());
116117
entity.setDefaultValue(property.defaultValue());
117-
entity.setExamples(property.example());
118+
entity.setExample(property.example());
118119
}
119120
return entity;
120121
}
@@ -127,7 +128,7 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
127128
Property property = returnAnnotation.load();
128129
returnPropertyEntity.setName(property.name());
129130
returnPropertyEntity.setDescription(property.description());
130-
returnPropertyEntity.setExamples(property.example());
131+
returnPropertyEntity.setExample(property.example());
131132
}
132133
notNull(methodDescription.getReturnType(), "The return type cannot be null.");
133134
JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType());
@@ -142,14 +143,16 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
142143

143144
private static void setPropertyType(PropertyEntity returnPropertyEntity, JsonNode jsonNode) {
144145
returnPropertyEntity.setType(jsonNode.get("type").asText());
145-
returnPropertyEntity.setItems(null);
146-
returnPropertyEntity.setProperties(null);
147146
if (Objects.equals(returnPropertyEntity.getType(), "array")) {
148147
returnPropertyEntity.setItems(jsonNode.get("items"));
149148
}
150149
if (Objects.equals(returnPropertyEntity.getType(), "object")) {
151150
if (jsonNode.get("properties") != null) {
152151
returnPropertyEntity.setProperties(jsonNode.get("properties"));
152+
// 为对象类型添加required数组,包含所有属性名
153+
List<String> requiredFields = new LinkedList<>();
154+
jsonNode.get("properties").fieldNames().forEachRemaining(requiredFields::add);
155+
returnPropertyEntity.setRequired(requiredFields);
153156
}
154157
}
155158
}

framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
"description" : "查询地点",
1818
"name" : "location",
1919
"type" : "string",
20-
"examples" : "",
21-
"required" : true
20+
"example" : ""
2221
},
2322
"date" : {
2423
"defaultValue" : "",
2524
"description" : "查询日期",
2625
"name" : "date",
2726
"type" : "string",
28-
"examples" : "",
29-
"required" : true
27+
"example" : ""
3028
}
3129
},
3230
"required" : [ "location", "date" ]
@@ -46,13 +44,11 @@
4644
"properties" : {
4745
"location" : {
4846
"name" : "location",
49-
"type" : "string",
50-
"required" : false
47+
"type" : "string"
5148
},
5249
"date" : {
5350
"name" : "date",
54-
"type" : "string",
55-
"required" : false
51+
"type" : "string"
5652
}
5753
},
5854
"required" : [ ]
@@ -84,13 +80,11 @@
8480
"properties" : {
8581
"location" : {
8682
"name" : "location",
87-
"type" : "string",
88-
"required" : false
83+
"type" : "string"
8984
},
9085
"date" : {
9186
"name" : "date",
92-
"type" : "string",
93-
"required" : false
87+
"type" : "string"
9488
}
9589
},
9690
"required" : [ ]
@@ -100,8 +94,7 @@
10094
"name" : "",
10195
"description" : "获取今日下雨信息的结果",
10296
"type" : "string",
103-
"convertor" : "",
104-
"examples" : ""
97+
"convertor" : ""
10598
}
10699
},
107100
"runnables" : {
@@ -124,13 +117,11 @@
124117
"properties" : {
125118
"location" : {
126119
"name" : "location",
127-
"type" : "string",
128-
"required" : false
120+
"type" : "string"
129121
},
130122
"date" : {
131123
"name" : "date",
132-
"type" : "string",
133-
"required" : false
124+
"type" : "string"
134125
}
135126
},
136127
"required" : [ ]
@@ -140,8 +131,7 @@
140131
"name" : "",
141132
"description" : "获取明日下雨信息的结果",
142133
"type" : "string",
143-
"convertor" : "",
144-
"examples" : ""
134+
"convertor" : ""
145135
}
146136
},
147137
"runnables" : {
@@ -171,13 +161,11 @@
171161
"properties" : {
172162
"location" : {
173163
"name" : "location",
174-
"type" : "string",
175-
"required" : false
164+
"type" : "string"
176165
},
177166
"date" : {
178167
"name" : "date",
179-
"type" : "string",
180-
"required" : false
168+
"type" : "string"
181169
}
182170
},
183171
"required" : [ ]
@@ -208,13 +196,11 @@
208196
"properties" : {
209197
"location" : {
210198
"name" : "location",
211-
"type" : "string",
212-
"required" : false
199+
"type" : "string"
213200
},
214201
"date" : {
215202
"name" : "date",
216-
"type" : "string",
217-
"required" : false
203+
"type" : "string"
218204
}
219205
},
220206
"required" : [ ]

framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package modelengine.fel.tool.info.entity;
88

9+
import java.util.List;
10+
911
/**
1012
* 表示参数属性的实体类。
1113
*
@@ -20,8 +22,9 @@ public class PropertyEntity {
2022
private String type;
2123
private Object items;
2224
private Object properties;
23-
private String examples;
24-
private boolean required;
25+
private String example;
26+
private List<String> required;
27+
private transient boolean need;
2528

2629
/**
2730
* 获取参数的默认值。
@@ -59,22 +62,40 @@ public void setDescription(String description) {
5962
this.description = description;
6063
}
6164

65+
/**
66+
* 获取对象类型的必填字段列表。
67+
*
68+
* @return 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。
69+
*/
70+
public List<String> getRequired() {
71+
return this.required;
72+
}
73+
74+
/**
75+
* 设置对象类型的必填字段列表。
76+
*
77+
* @param required 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。
78+
*/
79+
public void setRequired(List<String> required) {
80+
this.required = required;
81+
}
82+
6283
/**
6384
* 获取参数是否是必需的标志。
6485
*
6586
* @return 如果参数是必需的,则返回 {@code true},否则返回 {@code false}。
6687
*/
67-
public boolean isRequired() {
68-
return this.required;
88+
public boolean isNeed() {
89+
return need;
6990
}
7091

7192
/**
7293
* 设置参数是否是必需的标志。
7394
*
74-
* @param required 表示参数是否是必需的 {@link boolean}。
95+
* @param need 表示参数是否是必需的 {@link boolean}。
7596
*/
76-
public void setRequired(boolean required) {
77-
this.required = required;
97+
public void setNeed(boolean need) {
98+
this.need = need;
7899
}
79100

80101
/**
@@ -154,16 +175,16 @@ public void setProperties(Object properties) {
154175
*
155176
* @return 表示参数的示例值的 {@link String}。
156177
*/
157-
public String getExamples() {
158-
return this.examples;
178+
public String getExample() {
179+
return this.example;
159180
}
160181

161182
/**
162183
* 设置参数的示例值。
163184
*
164-
* @param examples 表示参数的示例值的 {@link String}。
185+
* @param example 表示参数的示例值的 {@link String}。
165186
*/
166-
public void setExamples(String examples) {
167-
this.examples = examples;
187+
public void setExample(String example) {
188+
this.example = example;
168189
}
169190
}

0 commit comments

Comments
 (0)