fix: fix bug of mcp server proxy (#1981)

This commit is contained in:
Jingze
2025-03-31 15:40:36 +08:00
committed by GitHub
parent 20dfc3d64f
commit 93e3b086ce
2 changed files with 7 additions and 4 deletions

View File

@@ -88,8 +88,8 @@ func (p *parser) Parse(any *anypb.Any, callbacks api.ConfigCallbackHandler) (int
conf.redisClient = redisClient
ssePathSuffix, ok := v.AsMap()["sse_path_suffix"].(string)
if !ok {
return nil, fmt.Errorf("sse path suffix is not set")
if !ok || ssePathSuffix == "" {
return nil, fmt.Errorf("sse path suffix is not set or empty")
}
conf.ssePathSuffix = ssePathSuffix

View File

@@ -24,6 +24,7 @@ type filter struct {
req *http.Request
serverName string
message bool
proxyURL *url.URL
}
type RequestURL struct {
@@ -54,6 +55,7 @@ func (f *filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.
// Check if request matches any rule in match_list
if !internal.IsMatch(f.config.matchList, url.host, f.path) {
api.LogDebugf("Request does not match any rule in match_list: %s", url.parsedURL.String())
return api.Continue
}
@@ -94,6 +96,7 @@ func (f *filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.
}
}
if !strings.HasSuffix(url.parsedURL.Path, f.config.ssePathSuffix) {
f.proxyURL = url.parsedURL
return api.Continue
}
@@ -154,8 +157,8 @@ func (f *filter) EncodeData(buffer api.BufferInstance, endStream bool) api.Statu
if !endStream {
return api.StopAndBuffer
}
if f.req != nil {
sessionID := f.req.URL.Query().Get("sessionId")
if f.proxyURL != nil {
sessionID := f.proxyURL.Query().Get("sessionId")
if sessionID != "" {
channel := internal.GetSSEChannelName(sessionID)
publishErr := f.config.redisClient.Publish(channel, buffer.String())