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

Method Exec

pkg/sandbox/cloud/volcengine.go:116–148  ·  view source on GitHub ↗

Exec 执行命令

(ctx context.Context, cmd string, opts *sandbox.ExecOptions)

Source from the content-addressed store, hash-verified

114
115// Exec 执行命令
116func (vs *VolcengineSandbox) Exec(ctx context.Context, cmd string, opts *sandbox.ExecOptions) (*sandbox.ExecResult, error) {
117 timeout := vs.config.Timeout.Milliseconds()
118 if opts != nil && opts.Timeout > 0 {
119 timeout = opts.Timeout.Milliseconds()
120 }
121
122 // 火山引擎使用 computer_exec 工具
123 result, err := vs.mcpClient.CallTool(ctx, "computer_exec", map[string]any{
124 "session_id": vs.sessionID,
125 "command": cmd,
126 "timeout": timeout,
127 })
128 if err != nil {
129 return nil, fmt.Errorf("exec command: %w", err)
130 }
131
132 // 解析结果
133 var execResult struct {
134 Stdout string `json:"stdout"`
135 Stderr string `json:"stderr"`
136 ExitCode int `json:"exit_code"`
137 }
138
139 if err := json.Unmarshal(result, &execResult); err != nil {
140 return nil, fmt.Errorf("parse exec result: %w", err)
141 }
142
143 return &sandbox.ExecResult{
144 Code: execResult.ExitCode,
145 Stdout: execResult.Stdout,
146 Stderr: execResult.Stderr,
147 }, nil
148}
149
150// FS 返回文件系统接口
151func (vs *VolcengineSandbox) FS() sandbox.SandboxFS {

Callers 1

testVolcengineFunction · 0.95

Calls 1

CallToolMethod · 0.45

Tested by

no test coverage detected