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

Method Handler

pkg/mcpserver/server.go:65–87  ·  view source on GitHub ↗

Handler 返回一个 http.Handler, 处理 MCP JSON-RPC 请求。 典型挂载方式: mux.Handle("/mcp", mcpSrv.Handler())

()

Source from the content-addressed store, hash-verified

63//
64// mux.Handle("/mcp", mcpSrv.Handler())
65func (s *Server) Handler() http.Handler {
66 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
67 if r.Method != http.MethodPost {
68 http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
69 return
70 }
71
72 var req cloud.MCPRequest
73 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
74 writeError(w, req.ID, -32700, "invalid JSON", err)
75 return
76 }
77
78 switch req.Method {
79 case "tools/list":
80 s.handleToolsList(w, r.Context(), &req)
81 case "tools/call":
82 s.handleToolsCall(w, r.Context(), &req)
83 default:
84 writeError(w, req.ID, -32601, "method not found", nil)
85 }
86 })
87}
88
89// handleToolsList 处理 tools/list 请求
90func (s *Server) handleToolsList(w http.ResponseWriter, ctx context.Context, req *cloud.MCPRequest) {

Callers 2

runMCPServeFunction · 0.45
mainFunction · 0.45

Calls 5

handleToolsListMethod · 0.95
handleToolsCallMethod · 0.95
writeErrorFunction · 0.85
ErrorMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected