MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

pkg/tools/builtin/skillcall.go:50–100  ·  view source on GitHub ↗
(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

48}
49
50func (t *SkillTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) {
51 // 获取 Runtime
52 if tc == nil || tc.Services == nil {
53 return nil, errors.New("skill_call: ToolContext.Services is nil; skills runtime not available")
54 }
55
56 rtAny, ok := tc.Services["skills_runtime"]
57 if !ok {
58 return nil, errors.New("skill_call: skills runtime not found in ToolContext.Services (key: \"skills_runtime\")")
59 }
60
61 rt, ok := rtAny.(*skills.Runtime)
62 if !ok || rt == nil {
63 return nil, errors.New("skill_call: invalid skills runtime type in ToolContext.Services")
64 }
65
66 // 解析输入
67 skillName, ok := input["skill"].(string)
68 if !ok || skillName == "" {
69 return nil, errors.New("skill_call: \"skill\" must be a non-empty string")
70 }
71
72 // params 期望为 map[string]string,但 JSON 反序列化会是 map[string]any
73 params := make(map[string]string)
74 if rawParams, ok := input["params"].(map[string]any); ok {
75 for k, v := range rawParams {
76 if s, ok := v.(string); ok {
77 params[k] = s
78 }
79 }
80 }
81
82 // 执行 Skill
83 res, err := rt.Execute(ctx, skillName, params)
84 if err != nil {
85 return map[string]any{
86 "ok": false,
87 "error": err.Error(),
88 }, nil
89 }
90
91 return map[string]any{
92 "ok": res.ExitCode == 0,
93 "skill": res.SkillName,
94 "command": res.Command,
95 "exit_code": res.ExitCode,
96 "stdout": res.Stdout,
97 "stderr": res.Stderr,
98 "duration": res.Duration.String(),
99 }, nil
100}
101
102func (t *SkillTool) Prompt() string {
103 return `Use this tool to execute an executable Skill by name.

Callers

nothing calls this directly

Calls 3

ExecuteMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected