@@ -824,19 +824,23 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
824824 } ) ) ;
825825 } catch ( error ) {
826826 if ( error instanceof ProtocolError ) {
827- const message = error . message ;
828- if ( message . includes ( 'Unauthorized' ) ) {
827+ if ( error . code === ProtocolErrorCode . Unauthorized ) {
829828 const response = this . createJsonErrorResponse ( 401 , error . code , 'Unauthorized' , { headers : { 'WWW-Authenticate' : 'Bearer' } } ) ;
830829 this . _streamMapping . delete ( streamId ) ;
831830 return response ;
832831 }
833- if ( message . includes ( ' Forbidden' ) ) {
834- const response = this . createJsonErrorResponse ( 403 , error . code , message ) ;
832+ if ( error . code === ProtocolErrorCode . Forbidden ) {
833+ const response = this . createJsonErrorResponse ( 403 , error . code , error . message ) ;
835834 this . _streamMapping . delete ( streamId ) ;
836835 return response ;
837836 }
837+ if ( error . code === ProtocolErrorCode . UrlElicitationRequired ) {
838+ throw error ;
839+ }
838840 }
839841 console . error ( 'Transport caught error in onmessage:' , error ) ;
842+ // Standard tools should return a CallToolResult with isError: true.
843+ // For onmessage we only rethrow auth-related errors and UrlElicitationRequired.
840844 throw error ;
841845 }
842846 }
@@ -846,13 +850,11 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
846850 return new Response ( readable , { status : 200 , headers } ) ;
847851 } catch ( error ) {
848852 if ( error instanceof ProtocolError ) {
849- const message = error . message ;
850- if ( message . includes ( 'Unauthorized' ) ) {
853+ if ( error . code === ProtocolErrorCode . Unauthorized ) {
851854 return this . createJsonErrorResponse ( 401 , error . code , 'Unauthorized' , { headers : { 'WWW-Authenticate' : 'Bearer' } } ) ;
852855 }
853- if ( message . includes ( 'Forbidden' ) ) {
854- console . log ( '[Transport] Mapping Forbidden to 403' ) ;
855- return this . createJsonErrorResponse ( 403 , error . code , message ) ;
856+ if ( error . code === ProtocolErrorCode . Forbidden ) {
857+ return this . createJsonErrorResponse ( 403 , error . code , error . message ) ;
856858 }
857859 }
858860 // return JSON-RPC formatted error
0 commit comments