| 85 | } |
| 86 | |
| 87 | func (ps *ProjectService) ListFiles(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 88 | var path string |
| 89 | if args, ok := request.Params.Arguments.(map[string]any); ok { |
| 90 | path = args["path"].(string) |
| 91 | } |
| 92 | basePath := ps.config.CodeAudit.RepositoryPath |
| 93 | absPath := filepath.Join(basePath, path) |
| 94 | ps.LogCall("listFiles", path) |
| 95 | entries, err := os.ReadDir(absPath) |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | var nodes []FileNode |
| 100 | for _, entry := range entries { |
| 101 | nodes = append(nodes, FileNode{ |
| 102 | Name: entry.Name(), |
| 103 | IsDir: entry.IsDir(), |
| 104 | }) |
| 105 | } |
| 106 | res, err := json.Marshal(nodes) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | return &mcp.CallToolResult{ |
| 112 | Content: []mcp.Content{ |
| 113 | &mcp.TextContent{ |
| 114 | Type: "text", |
| 115 | Text: string(res), |
| 116 | }, |
| 117 | }, |
| 118 | }, nil |
| 119 | } |
| 120 | |
| 121 | func (ps *ProjectService) ReadFile(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 122 | var path string |