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

Function TestToolsCallInvalidParams

server/mcp/call_test.go:140–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func 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
175func decodeResponse(t *testing.T, w *httptest.ResponseRecorder) response {
176 t.Helper()

Callers

nothing calls this directly

Calls 6

GinAppendValuesFunction · 0.92
newTestServerFunction · 0.85
decodeResponseFunction · 0.85
handlePostMethod · 0.80
ServeHTTPMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected