fix: The mcp to rest capability of the mcp server supports returning status without returning a body from the backend, and instead responds via sse (#2445)

This commit is contained in:
澄潭
2025-06-17 21:26:38 +08:00
committed by GitHub
parent 1daaa4b880
commit 69bc800198
19 changed files with 66 additions and 57 deletions

View File

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