refactor route call in mcp-server

This commit is contained in:
johnlanni
2025-05-07 20:36:41 +08:00
parent 0a2fb35ae2
commit 40402e7dbd
19 changed files with 57 additions and 55 deletions

View File

@@ -56,11 +56,11 @@ func (t ReGeocodeRequest) Call(ctx server.HttpContext, s server.Server) error {
url := fmt.Sprintf("http://restapi.amap.com/v3/geocode/regeo?location=%s&key=%s&source=ts_mcp", url.QueryEscape(t.Location), serverConfig.ApiKey)
return ctx.RouteCall(http.MethodGet, url,
[][2]string{{"Accept", "application/json"}}, nil, func(statusCode int, responseHeaders http.Header, responseBody []byte) {
[][2]string{{"Accept", "application/json"}}, nil, func(sendDirectly bool, statusCode int, responseHeaders [][2]string, responseBody []byte) {
if statusCode != http.StatusOK {
utils.OnMCPToolCallError(ctx, fmt.Errorf("regeocode call failed, status: %d", statusCode))
utils.OnMCPToolCallError(sendDirectly, ctx, fmt.Errorf("regeocode call failed, status: %d", statusCode))
return
}
utils.SendMCPToolTextResult(ctx, string(responseBody))
utils.SendMCPToolTextResult(sendDirectly, ctx, string(responseBody))
})
}