@@ -30,7 +30,7 @@ import (
3030 "github.com/envoyproxy/ai-gateway/internal/internalapi"
3131 "github.com/envoyproxy/ai-gateway/internal/json"
3232 "github.com/envoyproxy/ai-gateway/internal/metrics"
33- tracing "github.com/envoyproxy/ai-gateway/internal/tracing/api "
33+ "github.com/envoyproxy/ai-gateway/internal/tracing/tracingapi "
3434 "github.com/envoyproxy/ai-gateway/internal/version"
3535)
3636
@@ -185,7 +185,7 @@ func (m *MCPProxy) servePOST(w http.ResponseWriter, r *http.Request) {
185185 err error
186186 errType metrics.MCPErrorType
187187 requestMethod string
188- span tracing .MCPSpan
188+ span tracingapi .MCPSpan
189189 params mcp.Params
190190 applicationError bool
191191 )
@@ -493,7 +493,7 @@ func errorType(err error) metrics.MCPErrorType {
493493}
494494
495495// handleInitializeRequest handles the "initialize" JSON-RPC method.
496- func (m * MCPProxy ) handleInitializeRequest (ctx context.Context , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.InitializeParams , route , subject string , span tracing .MCPSpan ) error {
496+ func (m * MCPProxy ) handleInitializeRequest (ctx context.Context , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.InitializeParams , route , subject string , span tracingapi .MCPSpan ) error {
497497 m .metrics .RecordClientCapabilities (ctx , p .Capabilities , p )
498498 s , err := m .newSession (ctx , p , route , subject , span )
499499 if err != nil {
@@ -635,7 +635,7 @@ func (m *MCPProxy) handleClientToServerResponse(ctx context.Context, s *session,
635635 return m .proxyResponseBody (ctx , s , w , resp , nil , backend )
636636}
637637
638- func (m * MCPProxy ) handleToolCallRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.CallToolParams , span tracing .MCPSpan , r * http.Request ) error {
638+ func (m * MCPProxy ) handleToolCallRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.CallToolParams , span tracingapi .MCPSpan , r * http.Request ) error {
639639 backendName , toolName , err := upstreamResourceName (p .Name )
640640 if err != nil {
641641 onErrorResponse (w , http .StatusBadRequest , fmt .Sprintf ("invalid tool name %s: %v" , p .Name , err ))
@@ -1054,18 +1054,18 @@ func (m *MCPProxy) handleResourceReadRequest(ctx context.Context, s *session, w
10541054}
10551055
10561056// handleResourcesSubscribeRequest handles the "resources/subscribe" JSON-RPC method.
1057- func (m * MCPProxy ) handleResourcesSubscribeRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.SubscribeParams , span tracing .MCPSpan ) error {
1057+ func (m * MCPProxy ) handleResourcesSubscribeRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.SubscribeParams , span tracingapi .MCPSpan ) error {
10581058 return m .handleResourcesSubscriptionRequest (ctx , s , w , req , p , span )
10591059}
10601060
10611061// handleResourcesUnsubscribeRequest handles the "resources/unsubscribe" JSON-RPC method.
1062- func (m * MCPProxy ) handleResourcesUnsubscribeRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.UnsubscribeParams , span tracing .MCPSpan ) error {
1062+ func (m * MCPProxy ) handleResourcesUnsubscribeRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.UnsubscribeParams , span tracingapi .MCPSpan ) error {
10631063 return m .handleResourcesSubscriptionRequest (ctx , s , w , req , p , span )
10641064}
10651065
10661066func (m * MCPProxy ) handleResourcesSubscriptionRequest (ctx context.Context , s * session , w http.ResponseWriter ,
10671067 req * jsonrpc.Request , p interface {}, // *mcp.SubscribeParams or *mcp.UnsubscribeParams.
1068- span tracing .MCPSpan ,
1068+ span tracingapi .MCPSpan ,
10691069) error {
10701070 var uri string
10711071 switch v := p .(type ) {
@@ -1217,7 +1217,7 @@ func (m *MCPProxy) handlePromptGetRequest(ctx context.Context, s *session, w htt
12171217 return m .invokeAndProxyResponse (ctx , s , w , backend , cse , req )
12181218}
12191219
1220- func (m * MCPProxy ) handleCompletionComplete (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , param * mcp.CompleteParams , span tracing .MCPSpan ) error {
1220+ func (m * MCPProxy ) handleCompletionComplete (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , param * mcp.CompleteParams , span tracingapi .MCPSpan ) error {
12211221 // Either one of Name or URI is non-empty, depending on the Ref.Type.
12221222 // https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion#reference-types
12231223 var (
@@ -1255,7 +1255,7 @@ func (m *MCPProxy) handleCompletionComplete(ctx context.Context, s *session, w h
12551255// handleClientToServerNotificationsProgress handles client-to-server progress notifications that require routing to a specific backend.
12561256//
12571257// The progressToken contains the backend name and path prefix, so we can use that to route the notification to the correct backend.
1258- func (m * MCPProxy ) handleClientToServerNotificationsProgress (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ProgressNotificationParams , span tracing .MCPSpan ) error {
1258+ func (m * MCPProxy ) handleClientToServerNotificationsProgress (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ProgressNotificationParams , span tracingapi .MCPSpan ) error {
12591259 pt , ok := p .ProgressToken .(string )
12601260 if ! ok {
12611261 onErrorResponse (w , http .StatusBadRequest , fmt .Sprintf ("invalid progressToken type %T" , p .ProgressToken ))
@@ -1380,7 +1380,7 @@ type (
13801380// JSON-RPC methods that require sending the request to all backends and aggregating the responses.
13811381//
13821382// The mergeFn is used to merge the responses from all backends into a single response that will be sent back to the client.
1383- func sendToAllBackendsAndAggregateResponses [responseType any , paramsType mcp.Params ](ctx context.Context , m * MCPProxy , w http.ResponseWriter , s * session , request * jsonrpc.Request , p paramsType , mergeFn broadCastResponseMergeFn [responseType ], span tracing .MCPSpan ) error {
1383+ func sendToAllBackendsAndAggregateResponses [responseType any , paramsType mcp.Params ](ctx context.Context , m * MCPProxy , w http.ResponseWriter , s * session , request * jsonrpc.Request , p paramsType , mergeFn broadCastResponseMergeFn [responseType ], span tracingapi .MCPSpan ) error {
13841384 encoded , _ := json .Marshal (p )
13851385 request .Params = encoded
13861386 backendMsgs := s .sendToAllBackends (ctx , http .MethodPost , request , span )
@@ -1464,7 +1464,7 @@ func sendToAllBackendsAndAggregateResponsesImpl[responseType any](ctx context.Co
14641464}
14651465
14661466// parseParamsAndMaybeStartSpan parses the params from the JSON-RPC request and starts a tracing span if params is non-nil.
1467- func parseParamsAndMaybeStartSpan [paramType mcp.Params ](ctx context.Context , m * MCPProxy , req * jsonrpc.Request , p paramType , headers http.Header ) (tracing .MCPSpan , error ) {
1467+ func parseParamsAndMaybeStartSpan [paramType mcp.Params ](ctx context.Context , m * MCPProxy , req * jsonrpc.Request , p paramType , headers http.Header ) (tracingapi .MCPSpan , error ) {
14681468 if req .Params == nil {
14691469 return nil , nil
14701470 }
@@ -1481,33 +1481,33 @@ func parseParamsAndMaybeStartSpan[paramType mcp.Params](ctx context.Context, m *
14811481// handleToolsListRequest handles the "tools/list" JSON-RPC method.
14821482//
14831483// This aggregates and returns the list of tools from all backends.
1484- func (m * MCPProxy ) handleToolsListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListToolsParams , span tracing .MCPSpan ) error {
1484+ func (m * MCPProxy ) handleToolsListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListToolsParams , span tracingapi .MCPSpan ) error {
14851485 // TODO: use cursor for pagination, but in spec it's "SHOULD" not "MUST".
14861486 return sendToAllBackendsAndAggregateResponses (ctx , m , w , s , req , p , m .mergeToolsList , span )
14871487}
14881488
14891489// handleResourceListRequest handles the "resources/list" JSON-RPC method.
14901490// This aggregates and returns the list of resources from all backends.
1491- func (m * MCPProxy ) handleResourceListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListResourcesParams , span tracing .MCPSpan ) error {
1491+ func (m * MCPProxy ) handleResourceListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListResourcesParams , span tracingapi .MCPSpan ) error {
14921492 // TODO: use cursor for pagination, but in spec it's "SHOULD" not "MUST".
14931493 return sendToAllBackendsAndAggregateResponses (ctx , m , w , s , req , p , m .mergeResourceList , span )
14941494}
14951495
14961496// handleResourcesTemplatesListRequest handles the "resources/templates/list" JSON-RPC method.
1497- func (m * MCPProxy ) handleResourcesTemplatesListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListResourceTemplatesParams , span tracing .MCPSpan ) error {
1497+ func (m * MCPProxy ) handleResourcesTemplatesListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListResourceTemplatesParams , span tracingapi .MCPSpan ) error {
14981498 // TODO: use cursor for pagination, but in spec it's "SHOULD" not "MUST".
14991499 return sendToAllBackendsAndAggregateResponses (ctx , m , w , s , req , p , m .mergeResourcesTemplateList , span )
15001500}
15011501
15021502// handlePromptListRequest handles the "prompts/list" JSON-RPC method.
15031503// This aggregates and returns the list of prompts from all backends.
1504- func (m * MCPProxy ) handlePromptListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListPromptsParams , span tracing .MCPSpan ) error {
1504+ func (m * MCPProxy ) handlePromptListRequest (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , p * mcp.ListPromptsParams , span tracingapi .MCPSpan ) error {
15051505 // TODO: use cursor for pagination, but in spec it's "SHOULD" not "MUST".
15061506 return sendToAllBackendsAndAggregateResponses (ctx , m , w , s , req , p , m .mergePromptsList , span )
15071507}
15081508
15091509// handleSetLoggingLevel handles the "logging/setLevel" JSON-RPC method.
1510- func (m * MCPProxy ) handleSetLoggingLevel (ctx context.Context , s * session , w http.ResponseWriter , originalRequest * jsonrpc.Request , p * mcp.SetLoggingLevelParams , span tracing .MCPSpan ) error {
1510+ func (m * MCPProxy ) handleSetLoggingLevel (ctx context.Context , s * session , w http.ResponseWriter , originalRequest * jsonrpc.Request , p * mcp.SetLoggingLevelParams , span tracingapi .MCPSpan ) error {
15111511 // TODO: maybe some backend doesn't support set logging level, so filter out such backends.
15121512 return sendToAllBackendsAndAggregateResponses (ctx , m , w , s , originalRequest , p , func (* session , []broadCastResponse [any ]) any {
15131513 return struct {}{}
@@ -1583,7 +1583,7 @@ func (m *MCPProxy) mergePromptsList(_ *session, responses []broadCastResponse[mc
15831583}
15841584
15851585// handleNotificationsRootsListChanged handles the "notifications/roots/list_changed" JSON-RPC method.
1586- func (m * MCPProxy ) handleNotificationsRootsListChanged (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , span tracing .MCPSpan ) error {
1586+ func (m * MCPProxy ) handleNotificationsRootsListChanged (ctx context.Context , s * session , w http.ResponseWriter , req * jsonrpc.Request , span tracingapi .MCPSpan ) error {
15871587 // Since notifications request doesn't expect a response, we can just send the request to all backends and return 202 Accepted per the spec.
15881588 eventChan := s .sendToAllBackends (ctx , http .MethodPost , req , span )
15891589 w .Header ().Set (sessionIDHeader , string (s .clientGatewaySessionID ()))
0 commit comments