@@ -255,11 +255,15 @@ func TestServePOST_InitializeRequest(t *testing.T) {
255255 require .NoError (t , err )
256256 require .ElementsMatch (t , []filterapi.MCPBackendName {"backend1" }, slices .Collect (maps .Keys (perBackendSessions )))
257257
258- count , sum := testotel .GetHistogramValues (t , mr , "mcp.initialization.duration" , attribute .NewSet ())
258+ // backend1 is the only backend that successfully initialized.
259+ count , sum := testotel .GetHistogramValues (t , mr , "mcp.initialization.duration" , attribute .NewSet (
260+ attribute .String ("mcp.backend" , "backend1" ),
261+ ))
259262 require .Equal (t , 1 , int (count )) // nolint: gosec
260263 require .Greater (t , sum , 0.0 )
261264
262265 capaCount := testotel .GetCounterValue (t , mr , "mcp.capabilities.negotiated" , attribute .NewSet (
266+ attribute .String ("mcp.backend" , "backend1" ),
263267 attribute .String ("capability.type" , "tools" ),
264268 attribute .String ("capability.side" , "server" )))
265269 require .Equal (t , 1 , int (capaCount ))
@@ -616,16 +620,23 @@ func TestServePOST_ToolsCallRequest(t *testing.T) {
616620 var countAttrs , durationAttrs attribute.Set
617621 if tt .wantStatus == http .StatusOK {
618622 countAttrs = attribute .NewSet (
623+ attribute .String ("mcp.backend" , tt .wantBackend ),
619624 attribute .String ("mcp.method.name" , "tools/call" ),
620625 attribute .String ("status" , "success" ),
621626 )
622- durationAttrs = attribute .NewSet ()
627+ durationAttrs = attribute .NewSet (
628+ attribute .String ("mcp.backend" , tt .wantBackend ),
629+ )
623630 } else {
624631 countAttrs = attribute .NewSet (
632+ attribute .String ("mcp.backend" , tt .wantBackend ),
625633 attribute .String ("mcp.method.name" , "tools/call" ),
626634 attribute .String ("status" , "error" ),
627635 )
628- durationAttrs = attribute .NewSet (attribute .String ("error.type" , string (metrics .MCPErrorInvalidParam )))
636+ durationAttrs = attribute .NewSet (
637+ attribute .String ("mcp.backend" , tt .wantBackend ),
638+ attribute .String ("error.type" , string (metrics .MCPErrorInvalidParam )),
639+ )
629640 }
630641
631642 methodCount := testotel .GetCounterValue (t , mr , "mcp.method.count" , countAttrs )
@@ -688,7 +699,7 @@ func TestHandleToolCallRequest_UnknownBackend(t *testing.T) {
688699 httpReq := httptest .NewRequest (http .MethodPost , "/mcp" , nil )
689700 rr := httptest .NewRecorder ()
690701
691- err := proxy .handleToolCallRequest (t .Context (), s , rr , & jsonrpc.Request {}, params , nil , httpReq )
702+ _ , err := proxy .handleToolCallRequest (t .Context (), s , rr , & jsonrpc.Request {}, params , nil , httpReq )
692703 require .Error (t , err )
693704
694705 require .Equal (t , http .StatusNotFound , rr .Code )
@@ -719,7 +730,7 @@ func TestHandleToolCallRequest_BackendError(t *testing.T) {
719730 httpReq := httptest .NewRequest (http .MethodPost , "/mcp" , nil )
720731 rr := httptest .NewRecorder ()
721732
722- err := proxy .handleToolCallRequest (t .Context (), s , rr , & jsonrpc.Request {}, params , nil , httpReq )
733+ _ , err := proxy .handleToolCallRequest (t .Context (), s , rr , & jsonrpc.Request {}, params , nil , httpReq )
723734 require .Error (t , err )
724735
725736 require .Equal (t , http .StatusInternalServerError , rr .Code )
@@ -776,7 +787,7 @@ func TestHandleToolCallRequest_InvalidToolName(t *testing.T) {
776787 id := mustJSONRPCRequestID ()
777788 req := & jsonrpc.Request {ID : id , Method : "tools/call" }
778789
779- err := reqCtx .handleToolCallRequest (t .Context (), s , rr , req , params , nil , httpReq )
790+ _ , err := reqCtx .handleToolCallRequest (t .Context (), s , rr , req , params , nil , httpReq )
780791 // JSON-RPC errors are application-level errors that should be returned for proper metrics tracking,
781792 // but they're not treated as span exceptions since the protocol worked correctly.
782793 require .Error (t , err )
@@ -840,7 +851,7 @@ func TestHandleToolCallRequest_ToolResultWithIsError(t *testing.T) {
840851 id := mustJSONRPCRequestID ()
841852 req := & jsonrpc.Request {ID : id , Method : "tools/call" }
842853
843- err := proxy .handleToolCallRequest (t .Context (), s , rr , req , params , nil , httpReq )
854+ _ , err := proxy .handleToolCallRequest (t .Context (), s , rr , req , params , nil , httpReq )
844855 // isError: true means the tool executed successfully but returned an error result.
845856 // An error is returned for proper metrics tracking, but it's treated as an application-level
846857 // error (not a span exception) since the protocol worked correctly and the LLM needs to see these errors.
@@ -1365,7 +1376,7 @@ func TestMCPProxy_handleCompletionComplete(t *testing.T) {
13651376 },
13661377 } {
13671378 rr := httptest .NewRecorder ()
1368- err := proxy .handleCompletionComplete (t .Context (), & session {
1379+ _ , err := proxy .handleCompletionComplete (t .Context (), & session {
13691380 reqCtx : proxy ,
13701381 perBackendSessions : map [filterapi.MCPBackendName ]* compositeSessionEntry {
13711382 "backend1" : {sessionID : "test-session" },
@@ -1421,7 +1432,7 @@ func TestMCPPRoxy_handleResourceReadRequest(t *testing.T) {
14211432 t .Run ("invalid resource name" , func (t * testing.T ) {
14221433 proxy := newTestMCPProxy ()
14231434 rr := httptest .NewRecorder ()
1424- err := proxy .handleResourceReadRequest (t .Context (), nil , rr ,
1435+ _ , err := proxy .handleResourceReadRequest (t .Context (), nil , rr ,
14251436 & jsonrpc.Request {Method : "resources/subscribe" }, & mcp.ReadResourceParams {
14261437 URI : "invalid-form" ,
14271438 },
@@ -1450,7 +1461,7 @@ func TestMCPPRoxy_handleResourceReadRequest(t *testing.T) {
14501461 perBackendSessions : map [filterapi.MCPBackendName ]* compositeSessionEntry {"backend1" : {sessionID : "test-session" }},
14511462 route : "test-route" ,
14521463 }
1453- err := proxy .handleResourceReadRequest (t .Context (), s , rr , & jsonrpc.Request {ID : reqID , Method : "resources/read" }, & mcp.ReadResourceParams {
1464+ _ , err := proxy .handleResourceReadRequest (t .Context (), s , rr , & jsonrpc.Request {ID : reqID , Method : "resources/read" }, & mcp.ReadResourceParams {
14541465 URI : downstreamResourceURI ("file://foo-resource" , "backend1" ),
14551466 })
14561467 require .NoError (t , err )
@@ -1535,7 +1546,7 @@ func TestMCPProxy_handleClientToServerNotificationsProgress(t *testing.T) {
15351546 route : "test-route" ,
15361547 }
15371548 params := & mcp.ProgressNotificationParams {ProgressToken : tc .inputProgressToken }
1538- err := proxy .handleClientToServerNotificationsProgress (t .Context (), s , rr ,
1549+ _ , err := proxy .handleClientToServerNotificationsProgress (t .Context (), s , rr ,
15391550 & jsonrpc.Request {Method : "notifications/progress" }, params , nil )
15401551 if rr .Code != http .StatusOK {
15411552 require .Error (t , err )
@@ -1632,23 +1643,23 @@ func TestMCPProxy_handleClientToServerResponse(t *testing.T) {
16321643 t .Run ("invalid IDs" , func (t * testing.T ) {
16331644 proxy := newTestMCPProxy ()
16341645 rr := httptest .NewRecorder ()
1635- err := proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {})
1646+ _ , err := proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {})
16361647 require .Error (t , err )
16371648 require .Equal (t , http .StatusBadRequest , rr .Code )
16381649 require .Contains (t , rr .Body .String (), "invalid response ID type: <nil>" )
16391650
16401651 invalidID , err := jsonrpc .MakeID ("invalidformatid" )
16411652 require .NoError (t , err )
16421653 rr = httptest .NewRecorder ()
1643- err = proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {ID : invalidID })
1654+ _ , err = proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {ID : invalidID })
16441655 require .Error (t , err )
16451656 require .Equal (t , http .StatusBadRequest , rr .Code )
16461657 require .Contains (t , rr .Body .String (), "invalid response ID format: invalidformatid" )
16471658
16481659 invalidID2 , err := jsonrpc .MakeID ("__foo__" )
16491660 require .NoError (t , err )
16501661 rr = httptest .NewRecorder ()
1651- err = proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {ID : invalidID2 })
1662+ _ , err = proxy .handleClientToServerResponse (t .Context (), nil , rr , & jsonrpc.Response {ID : invalidID2 })
16521663 require .ErrorContains (t , err , `invalid response ID type identifier: foo` )
16531664 require .Equal (t , http .StatusBadRequest , rr .Code )
16541665 require .Contains (t , rr .Body .String (), `invalid response ID type identifier` )
@@ -1719,7 +1730,7 @@ func TestMCPProxy_handleClientToServerResponse(t *testing.T) {
17191730 proxy .backendListenerAddr = testServer .URL
17201731
17211732 rr := httptest .NewRecorder ()
1722- err := proxy .handleClientToServerResponse (t .Context (), & session {
1733+ _ , err := proxy .handleClientToServerResponse (t .Context (), & session {
17231734 reqCtx : proxy ,
17241735 perBackendSessions : map [filterapi.MCPBackendName ]* compositeSessionEntry {"backend1" : {sessionID : "test-session" }},
17251736 route : "test-route" ,
@@ -1818,9 +1829,9 @@ func TestMCPServer_handleResourcesSubscriptionRequest(t *testing.T) {
18181829 }
18191830 switch pp := tc .p .(type ) {
18201831 case * mcp.SubscribeParams :
1821- err = proxy .handleResourcesSubscribeRequest (t .Context (), s , rr , req , pp , nil )
1832+ _ , err = proxy .handleResourcesSubscribeRequest (t .Context (), s , rr , req , pp , nil )
18221833 case * mcp.UnsubscribeParams :
1823- err = proxy .handleResourcesUnsubscribeRequest (t .Context (), s , rr , req , pp , nil )
1834+ _ , err = proxy .handleResourcesUnsubscribeRequest (t .Context (), s , rr , req , pp , nil )
18241835 }
18251836 require .NoError (t , err )
18261837 require .Equal (t , http .StatusOK , rr .Code )
@@ -1837,7 +1848,7 @@ func Test_sendToAllBackendsAndAggregateResponsesImpl(t *testing.T) {
18371848 type testData struct {
18381849 Value string `json:"value"`
18391850 }
1840- events := make (chan * sseEvent )
1851+ events := make (chan * backendEvent )
18411852 go func () {
18421853 for _ , msg := range []jsonrpc.Message {
18431854 & jsonrpc.Response {ID : reqID , Result : []byte (`{"value": "foo"}` )},
@@ -1850,13 +1861,15 @@ func Test_sendToAllBackendsAndAggregateResponsesImpl(t *testing.T) {
18501861 // Error should be logged and ignored, not blocking the response.
18511862 & jsonrpc.Response {ID : reqID , Error : errors .New ("some error" )},
18521863 } {
1853- events <- & sseEvent {backend : "a" , messages : []jsonrpc.Message {msg }}
1864+ events <- & backendEvent { sseEvent : & sseEvent {backend : "a" , messages : []jsonrpc.Message {msg } }}
18541865 }
18551866 close (events )
18561867 }()
18571868
18581869 rr := httptest .NewRecorder ()
1870+ var testParams * mcp.ListToolsParams
18591871 err = sendToAllBackendsAndAggregateResponsesImpl (t .Context (), events , proxy , rr , s , & jsonrpc.Request {ID : reqID , Method : "test" },
1872+ testParams ,
18601873 func (_ * session , res []broadCastResponse [testData ]) testData {
18611874 var combined testData
18621875 for _ , r := range res {
0 commit comments