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

Method handleToolsList

pkg/mcpserver/server.go:90–119  ·  view source on GitHub ↗

handleToolsList 处理 tools/list 请求

(w http.ResponseWriter, ctx context.Context, req *cloud.MCPRequest)

Source from the content-addressed store, hash-verified

88
89// handleToolsList 处理 tools/list 请求
90func (s *Server) handleToolsList(w http.ResponseWriter, ctx context.Context, req *cloud.MCPRequest) {
91 names := s.registry.List()
92 toolsResp := make([]cloud.MCPTool, 0, len(names))
93
94 for _, name := range names {
95 tool, err := s.registry.Create(name, nil)
96 if err != nil {
97 continue
98 }
99 toolsResp = append(toolsResp, cloud.MCPTool{
100 Name: name,
101 Description: tool.Description(),
102 InputSchema: tool.InputSchema(),
103 })
104 }
105
106 resp := struct {
107 JSONRPC string `json:"jsonrpc"`
108 ID int64 `json:"id"`
109 Result struct {
110 Tools []cloud.MCPTool `json:"tools"`
111 } `json:"result"`
112 }{
113 JSONRPC: "2.0",
114 ID: req.ID,
115 }
116 resp.Result.Tools = toolsResp
117
118 writeJSON(w, http.StatusOK, resp)
119}
120
121// handleToolsCall 处理 tools/call 请求
122func (s *Server) handleToolsCall(w http.ResponseWriter, ctx context.Context, req *cloud.MCPRequest) {

Callers 1

HandlerMethod · 0.95

Calls 5

writeJSONFunction · 0.70
ListMethod · 0.65
CreateMethod · 0.65
DescriptionMethod · 0.65
InputSchemaMethod · 0.65

Tested by

no test coverage detected