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 conf.redisClient = redisClient
ssePathSuffix, ok := v.AsMap()["sse_path_suffix"].(string) ssePathSuffix, ok := v.AsMap()["sse_path_suffix"].(string)
if !ok { if !ok || ssePathSuffix == "" {
return nil, fmt.Errorf("sse path suffix is not set") return nil, fmt.Errorf("sse path suffix is not set or empty")
} }
conf.ssePathSuffix = ssePathSuffix conf.ssePathSuffix = ssePathSuffix

View File

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