| 1 | package plugin |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http" |
| 6 | ) |
| 7 | |
| 8 | func writeOAuthMCPFixtureResponse(w http.ResponseWriter, r *http.Request) { |
| 9 | switch r.Method { |
| 10 | case http.MethodGet: |
| 11 | w.WriteHeader(http.StatusMethodNotAllowed) |
| 12 | return |
| 13 | case http.MethodDelete: |
| 14 | w.WriteHeader(http.StatusOK) |
| 15 | return |
| 16 | } |
| 17 | var request struct { |
| 18 | ID json.RawMessage `json:"id"` |
| 19 | Method string `json:"method"` |
| 20 | } |
| 21 | if err := json.NewDecoder(r.Body).Decode(&request); err != nil { |
| 22 | http.Error(w, "bad MCP request", http.StatusBadRequest) |
| 23 | return |
| 24 | } |
| 25 | if len(request.ID) == 0 { |
| 26 | w.WriteHeader(http.StatusAccepted) |
| 27 | return |
| 28 | } |
| 29 | response := map[string]any{"jsonrpc": "2.0", "id": request.ID} |
| 30 | switch request.Method { |
| 31 | case "server/discover": |
| 32 | response["error"] = map[string]any{"code": -32601, "message": "Method not found"} |
| 33 | case "initialize": |
| 34 | response["result"] = map[string]any{ |
| 35 | "protocolVersion": testLegacyProtocolVersion, |
| 36 | "serverInfo": map[string]any{"name": "oauth-fixture", "version": "1"}, |
| 37 | "capabilities": map[string]any{}, |
| 38 | } |
| 39 | case "ping": |
| 40 | response["result"] = map[string]any{} |
| 41 | default: |
| 42 | response["error"] = map[string]any{"code": -32601, "message": "Method not found"} |
| 43 | } |
| 44 | w.Header().Set("Content-Type", "application/json") |
| 45 | _ = json.NewEncoder(w).Encode(response) |
| 46 | } |
| 47 |