MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / callFSList

Method callFSList

server/mcp/fs_list.go:28–81  ·  view source on GitHub ↗
(c *gin.Context, raw json.RawMessage)

Source from the content-addressed store, hash-verified

26}
27
28func (s *Server) callFSList(c *gin.Context, raw json.RawMessage) (any, *rpcError) {
29 args, mcpErr := parseFSListArgs(raw)
30 if mcpErr != nil {
31 return nil, mcpErr
32 }
33
34 user, ok := c.Request.Context().Value(conf.UserKey).(*model.User)
35 if !ok || user == nil {
36 return nil, &rpcError{Code: -32603, Message: "missing user context"}
37 }
38 if user.IsGuest() && user.Disabled {
39 return nil, &rpcError{Code: -32001, Message: "guest user is disabled"}
40 }
41
42 reqPath, err := user.JoinPath(args.Path)
43 if err != nil {
44 return nil, &rpcError{Code: -32003, Message: err.Error()}
45 }
46
47 meta, err := op.GetNearestMeta(reqPath)
48 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
49 return nil, &rpcError{Code: -32603, Message: err.Error()}
50 }
51 if !common.CanAccess(user, meta, reqPath, args.Password) {
52 return nil, &rpcError{Code: -32003, Message: "password is incorrect or you have no permission"}
53 }
54
55 write := common.CanWrite(user, meta, reqPath)
56 writeContentBypass := common.CanWriteContentBypassUserPerms(meta, reqPath)
57 canWriteContentAtPath := write && (user.CanWriteContent() || writeContentBypass)
58 if args.Refresh && !canWriteContentAtPath {
59 return nil, &rpcError{Code: -32003, Message: "refresh without permission"}
60 }
61
62 ctx := context.WithValue(c.Request.Context(), conf.MetaKey, meta)
63 objs, err := fs.List(ctx, reqPath, &fs.ListArgs{
64 Refresh: args.Refresh,
65 WithStorageDetails: !user.IsGuest() && !setting.GetBool(conf.HideStorageDetails),
66 })
67 if err != nil {
68 return nil, &rpcError{Code: -32603, Message: err.Error()}
69 }
70
71 total, paged := paginateObjs(objs, args.Page, args.PerPage)
72 return handles.FsListResp{
73 Content: toObjResp(paged, reqPath, isEncrypt(meta, reqPath)),
74 Total: int64(total),
75 Write: write,
76 WriteContentBypass: writeContentBypass,
77 Provider: "unknown",
78 Readme: getReadme(meta, reqPath),
79 Header: getHeader(meta, reqPath),
80 }, nil
81}
82
83func parseFSListArgs(raw json.RawMessage) (*fsListArgs, *rpcError) {
84 args := &fsListArgs{

Callers 1

handleToolsCallMethod · 0.95

Calls 15

GetNearestMetaFunction · 0.92
CanAccessFunction · 0.92
CanWriteFunction · 0.92
ListFunction · 0.92
GetBoolFunction · 0.92
parseFSListArgsFunction · 0.85
paginateObjsFunction · 0.85
toObjRespFunction · 0.85
IsGuestMethod · 0.80
JoinPathMethod · 0.80
CanWriteContentMethod · 0.80

Tested by

no test coverage detected