Skip to content

Commit 9df778f

Browse files
author
piexlMax(奇淼
committed
fix: 增加默认值属性
1 parent b6c8c50 commit 9df778f

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

server/model/system/request/sys_auto_code_mcp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type AutoMcpTool struct {
88
Description string `json:"description" form:"description" binding:"required"`
99
Type string `json:"type" form:"type" binding:"required"` // string, number, boolean, object, array
1010
Required bool `json:"required" form:"required"`
11+
Default string `json:"default" form:"default"`
1112
} `json:"params" form:"params"`
1213
Response []struct {
1314
Type string `json:"type" form:"type" binding:"required"` // text, image

server/resource/mcp/tools.tpl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package mcpTool
2+
3+
import (
4+
"context"
5+
"github.com/mark3labs/mcp-go/mcp"
6+
"time"
7+
)
8+
9+
func init() {
10+
RegisterTool(&{{.Name | title}}{})
11+
}
12+
13+
type {{.Name | title}} struct {
14+
}
15+
16+
// {{.Description}}
17+
func (t *{{.Name | title}}) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
18+
// TODO: 实现工具逻辑
19+
// 参数示例:
20+
// {{- range .Params}}
21+
// {{.Name}} := request.Params["{{.Name}}"]
22+
// {{- end}}
23+
return &mcp.CallToolResult{
24+
Content: []mcp.Content{
25+
{{- range .Response}}
26+
mcp.{{.Type | title}}Content{
27+
Type: "{{.Type}}",
28+
// TODO: 填充{{.Type}}内容
29+
},
30+
{{- end}}
31+
},
32+
}, nil
33+
}
34+
35+
func (t *{{.Name | title}}) New() mcp.Tool {
36+
return mcp.NewTool("{{.Name}}",
37+
mcp.WithDescription("{{.Description}}"),
38+
{{- range .Params}}
39+
mcp.With{{.Type | title}}("{{.Name}}",
40+
{{- if .Required}}mcp.Required(),{{end}}
41+
mcp.Description("{{.Description}}"),
42+
{{- if .Default}}
43+
{{- if eq .Type "string"}}
44+
mcp.DefaultString("{{.Default}}"),
45+
{{- else if eq .Type "number"}}
46+
mcp.DefaultNumber({{.Default}}),
47+
{{- else if eq .Type "boolean"}}
48+
mcp.DefaultBoolean({{if or (eq .Default "true") (eq .Default "True")}}true{{else}}false{{end}}),
49+
{{- else if eq .Type "array"}}
50+
// 注意:数组默认值需要在后端代码中预处理为正确的格式
51+
// mcp.DefaultArray({{.Default}}),
52+
{{- end}}
53+
{{- end}}
54+
),
55+
{{- end}}
56+
)
57+
}

web/src/view/systemTools/autoCode/mcp.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
</el-select>
3131
</template>
3232
</el-table-column>
33+
<el-table-column label="默认值" width="300">
34+
<template #default="scope">
35+
<el-input :disabled="scope.row.type === 'object'" v-model="scope.row.default" />
36+
</template>
37+
</el-table-column>
3338
<el-table-column prop="required" label="必填" width="80">
3439
<template #default="scope">
3540
<el-checkbox v-model="scope.row.required" />

0 commit comments

Comments
 (0)