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

Method Execute

pkg/middleware/filesystem_tools.go:239–277  ·  view source on GitHub ↗
(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

237}
238
239func (t *GlobTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) {
240 pattern, _ := input["pattern"].(string)
241 path := "."
242 if p, ok := input["path"].(string); ok {
243 path = p
244 }
245
246 // 路径安全验证
247 if t.middleware != nil {
248 validatedPath, err := t.middleware.validatePath(path)
249 if err != nil {
250 return map[string]any{
251 "ok": false,
252 "error": fmt.Sprintf("path validation failed: %v", err),
253 }, nil
254 }
255 path = validatedPath
256 }
257
258 results, err := t.backend.GlobInfo(ctx, pattern, path)
259 if err != nil {
260 return map[string]any{
261 "ok": false,
262 "error": fmt.Sprintf("failed to glob: %v", err),
263 }, nil
264 }
265
266 files := make([]string, 0, len(results))
267 for _, info := range results {
268 files = append(files, info.Path)
269 }
270
271 return map[string]any{
272 "ok": true,
273 "pattern": pattern,
274 "files": files,
275 "count": len(files),
276 }, nil
277}
278
279func (t *GlobTool) Prompt() string {
280 return `Use this tool to find files matching glob patterns.

Callers

nothing calls this directly

Calls 2

GlobInfoMethod · 0.65
validatePathMethod · 0.45

Tested by

no test coverage detected