File tree Expand file tree Collapse file tree 2 files changed +11
-15
lines changed
Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -132,10 +132,13 @@ func (h *AuthHandler) routesForPattern(pattern string) []string {
132132}
133133
134134// GetEffectiveResourcePath returns the resource path for OAuth protected resource URLs.
135- // It uses the request's URL path directly. For deployments where a prefix like /mcp
136- // is stripped by a proxy, the proxy should set the BaseURL config appropriately .
135+ // Since proxies may strip the /mcp prefix before forwarding requests, this function
136+ // restores the prefix for the external-facing URL .
137137func GetEffectiveResourcePath (r * http.Request ) string {
138- return r .URL .Path
138+ if r .URL .Path == "/" {
139+ return "/mcp"
140+ }
141+ return "/mcp" + r .URL .Path
139142}
140143
141144// GetProtectedResourceData builds the OAuth protected resource data for a request.
Original file line number Diff line number Diff line change @@ -185,30 +185,23 @@ func TestGetEffectiveResourcePath(t *testing.T) {
185185 expectedPath string
186186 }{
187187 {
188- name : "root path" ,
188+ name : "root path restores /mcp prefix " ,
189189 setupRequest : func () * http.Request {
190190 return httptest .NewRequest (http .MethodGet , "/" , nil )
191191 },
192- expectedPath : "/" ,
193- },
194- {
195- name : "mcp path" ,
196- setupRequest : func () * http.Request {
197- return httptest .NewRequest (http .MethodGet , "/mcp" , nil )
198- },
199192 expectedPath : "/mcp" ,
200193 },
201194 {
202- name : "readonly path" ,
195+ name : "non-root path adds /mcp prefix " ,
203196 setupRequest : func () * http.Request {
204197 return httptest .NewRequest (http .MethodGet , "/readonly" , nil )
205198 },
206- expectedPath : "/readonly" ,
199+ expectedPath : "/mcp/ readonly" ,
207200 },
208201 {
209- name : "nested path" ,
202+ name : "nested path adds /mcp prefix " ,
210203 setupRequest : func () * http.Request {
211- return httptest .NewRequest (http .MethodGet , "/mcp/ x/repos" , nil )
204+ return httptest .NewRequest (http .MethodGet , "/x/repos" , nil )
212205 },
213206 expectedPath : "/mcp/x/repos" ,
214207 },
You can’t perform that action at this time.
0 commit comments