admin/server/resource/mcp/tools.tpl
2025-06-19 21:53:00 +08:00

57 lines
1.5 KiB
Smarty
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package mcpTool
import (
"context"
"github.com/mark3labs/mcp-go/mcp"
)
func init() {
RegisterTool(&{{.Name | title}}{})
}
type {{.Name | title}} struct {
}
// {{.Description}}
func (t *{{.Name | title}}) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
// TODO:
// :
// {{- range .Params}}
// {{.Name}} := request.GetArguments()["{{.Name}}"]
// {{- end}}
return &mcp.CallToolResult{
Content: []mcp.Content{
{{- range .Response}}
mcp.{{.Type | title}}Content{
Type: "{{.Type}}",
// TODO: {{.Type}}
},
{{- end}}
},
}, nil
}
func (t *{{.Name | title}}) New() mcp.Tool {
return mcp.NewTool("{{.Name}}",
mcp.WithDescription("{{.Description}}"),
{{- range .Params}}
mcp.With{{.Type | title}}("{{.Name}}",
{{- if .Required}}mcp.Required(),{{end}}
mcp.Description("{{.Description}}"),
{{- if .Default}}
{{- if eq .Type "string"}}
mcp.DefaultString("{{.Default}}"),
{{- else if eq .Type "number"}}
mcp.DefaultNumber({{.Default}}),
{{- else if eq .Type "boolean"}}
mcp.DefaultBoolean({{if or (eq .Default "true") (eq .Default "True")}}true{{else}}false{{end}}),
{{- else if eq .Type "array"}}
//
// mcp.DefaultArray({{.Default}}),
{{- end}}
{{- end}}
),
{{- end}}
)
}