feat: invoke tool in hrp server

This commit is contained in:
lilong.129
2025-04-01 21:55:58 +08:00
parent 0c80e3d872
commit 86d0555074
5 changed files with 109 additions and 4 deletions

View File

@@ -71,3 +71,43 @@ func TestTapHandler(t *testing.T) {
})
}
}
func TestInvokeToolHandler(t *testing.T) {
router := NewRouter()
router.InitMCPHub("../internal/mcp/test.mcp.json")
tests := []struct {
name string
path string
toolReq ToolRequest
wantStatus int
}{
{
name: "invoke tool",
path: "/api/v1/tool/invoke",
toolReq: ToolRequest{
ServerName: "weather",
ToolName: "get_alerts",
Args: map[string]interface{}{"state": "CA"},
},
wantStatus: http.StatusOK,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reqBody, _ := json.Marshal(tt.toolReq)
req := httptest.NewRequest(http.MethodPost, tt.path, bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
assert.Equal(t, tt.wantStatus, w.Code)
var got HttpResponse
err := json.Unmarshal(w.Body.Bytes(), &got)
assert.NoError(t, err)
})
}
}