(t *testing.T)
| 138 | } |
| 139 | |
| 140 | func TestToolsCallInvalidParams(t *testing.T) { |
| 141 | gin.SetMode(gin.TestMode) |
| 142 | srv := newTestServer(map[string]*session{ |
| 143 | "s4": {id: "s4", userID: 1, initialized: true}, |
| 144 | }) |
| 145 | |
| 146 | r := gin.New() |
| 147 | r.POST("/mcp", func(c *gin.Context) { |
| 148 | common.GinAppendValues(c, conf.UserKey, &model.User{ID: 1, Role: model.ADMIN}) |
| 149 | srv.handlePost(c) |
| 150 | }) |
| 151 | |
| 152 | req := httptest.NewRequest(http.MethodPost, "http://example.com/mcp", strings.NewReader(`{ |
| 153 | "jsonrpc":"2.0", |
| 154 | "id":4, |
| 155 | "method":"tools/call", |
| 156 | "params":{"name":"openlist.fs.list","arguments":"bad"} |
| 157 | }`)) |
| 158 | req.Header.Set("Accept", "application/json, text/event-stream") |
| 159 | req.Header.Set("Origin", "http://example.com") |
| 160 | req.Header.Set(ProtocolVersionHeader, ProtocolVersion) |
| 161 | req.Header.Set(SessionHeader, "s4") |
| 162 | |
| 163 | w := httptest.NewRecorder() |
| 164 | r.ServeHTTP(w, req) |
| 165 | |
| 166 | if w.Code != http.StatusOK { |
| 167 | t.Fatalf("unexpected status: got %d want %d", w.Code, http.StatusOK) |
| 168 | } |
| 169 | resp := decodeResponse(t, w) |
| 170 | if resp.Error != nil { |
| 171 | t.Fatalf("expected tool error result, got protocol error: %+v", resp.Error) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func decodeResponse(t *testing.T, w *httptest.ResponseRecorder) response { |
| 176 | t.Helper() |
nothing calls this directly
no test coverage detected