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

Method handleToolsCall

server/mcp/call.go:20–88  ·  view source on GitHub ↗
(c *gin.Context, req request)

Source from the content-addressed store, hash-verified

18}
19
20func (s *Server) handleToolsCall(c *gin.Context, req request) (int, response) {
21 var params toolCallParams
22 if len(req.Params) == 0 {
23 return http.StatusBadRequest, response{
24 JSONRPC: "2.0",
25 ID: req.ID,
26 Error: &rpcError{Code: -32602, Message: "invalid tools/call params"},
27 }
28 }
29 if err := json.Unmarshal(req.Params, &params); err != nil || params.Name == "" {
30 return http.StatusBadRequest, response{
31 JSONRPC: "2.0",
32 ID: req.ID,
33 Error: &rpcError{Code: -32602, Message: "invalid tools/call params"},
34 }
35 }
36
37 var (
38 result any
39 err *rpcError
40 )
41 switch params.Name {
42 case "openlist.fs.list":
43 result, err = s.callFSList(c, params.Arguments)
44 case "openlist.fs.get":
45 result, err = s.callFSGet(c, params.Arguments)
46 case "openlist.fs.link":
47 result, err = s.callFSLink(c, params.Arguments)
48 default:
49 return http.StatusOK, response{
50 JSONRPC: "2.0",
51 ID: req.ID,
52 Error: &rpcError{Code: -32601, Message: "unknown tool"},
53 }
54 }
55
56 if err != nil {
57 return http.StatusOK, response{
58 JSONRPC: "2.0",
59 ID: req.ID,
60 Result: map[string]any{
61 "content": []toolResultContent{
62 {Type: "text", Text: err.Message},
63 },
64 "isError": true,
65 },
66 }
67 }
68
69 resultJSON, marshalErr := json.Marshal(result)
70 if marshalErr != nil {
71 return http.StatusInternalServerError, response{
72 JSONRPC: "2.0",
73 ID: req.ID,
74 Error: &rpcError{Code: -32603, Message: "failed to encode tool result"},
75 }
76 }
77

Callers 1

handlePostMethod · 0.95

Calls 4

callFSListMethod · 0.95
callFSGetMethod · 0.95
callFSLinkMethod · 0.95
UnmarshalMethod · 0.45

Tested by

no test coverage detected