@@ -30,6 +30,7 @@ import { useInspectorClient } from "@modelcontextprotocol/inspector-core/react/u
3030import {
3131 InspectorClient ,
3232 type InspectorClientOptions ,
33+ type MessageEntry ,
3334} from "@modelcontextprotocol/inspector-core/mcp/index.js" ;
3435import {
3536 createWebEnvironment ,
@@ -121,6 +122,11 @@ const filterReservedMetadata = (
121122 ) ;
122123} ;
123124
125+ // Shared predicates for history/notifications views; used for both getMessages (display) and clearMessages (clear)
126+ const notificationsMessagePredicate = ( m : MessageEntry ) =>
127+ m . direction === "notification" ;
128+ const historyMessagePredicate = ( m : MessageEntry ) => m . direction === "request" ;
129+
124130const App = ( ) => {
125131 const [ resourceContent , setResourceContent ] = useState < string > ( "" ) ;
126132 const [ resourceContentMap , setResourceContentMap ] = useState <
@@ -553,13 +559,13 @@ const App = () => {
553559 }
554560 } , [ ensureInspectorClient , toast ] ) ;
555561
556- // Extract server notifications from messages
557- // Use useMemo to stabilize the array reference and prevent infinite loops
562+ // Extract server notifications from messages (same predicate as clearMessages for this view)
558563 const extractedNotifications = useMemo ( ( ) => {
559- return inspectorMessages
560- . filter ( ( msg ) => msg . direction === "notification" && msg . message )
564+ if ( ! inspectorClient ) return [ ] ;
565+ return inspectorClient
566+ . getMessages ( notificationsMessagePredicate )
561567 . map ( ( msg ) => msg . message as ServerNotification ) ;
562- } , [ inspectorMessages ] ) ;
568+ } , [ inspectorClient , inspectorMessages ] ) ;
563569
564570 // Use ref to track previous serialized value to prevent infinite loops
565571 const previousNotificationsRef = useRef < string > ( "[]" ) ;
@@ -731,21 +737,20 @@ const App = () => {
731737 serverCapabilities ?. completions !== undefined &&
732738 serverCapabilities . completions !== null ;
733739
734- // Map MCP protocol messages (requests/responses) to requestHistory format
735- // Filter out notifications - those go in the Notifications tab
740+ // Request history (same predicate as clearMessages for this view)
736741 const requestHistory = useMemo ( ( ) => {
737- return inspectorMessages
738- . filter ( ( msg ) => msg . direction === "request" )
739- . map ( ( msg ) => ( {
740- request : JSON . stringify ( msg . message ) ,
741- response : msg . response ? JSON . stringify ( msg . response ) : undefined ,
742- } ) ) ;
743- } , [ inspectorMessages ] ) ;
742+ if ( ! inspectorClient ) return [ ] ;
743+ return inspectorClient . getMessages ( historyMessagePredicate ) . map ( ( msg ) => ( {
744+ request : JSON . stringify ( msg . message ) ,
745+ response : msg . response ? JSON . stringify ( msg . response ) : undefined ,
746+ } ) ) ;
747+ } , [ inspectorClient , inspectorMessages ] ) ;
744748
745749 const clearRequestHistory = useCallback ( ( ) => {
746- // InspectorClient doesn't have a clear method, so this is a no-op
747- // The history is managed internally by InspectorClient
748- } , [ ] ) ;
750+ if ( inspectorClient ) {
751+ inspectorClient . clearMessages ( historyMessagePredicate ) ;
752+ }
753+ } , [ inspectorClient ] ) ;
749754
750755 useEffect ( ( ) => {
751756 if ( serverCapabilities ) {
@@ -1498,7 +1503,11 @@ const App = () => {
14981503 } ;
14991504
15001505 const handleClearNotifications = ( ) => {
1501- setNotifications ( [ ] ) ;
1506+ if ( inspectorClient ) {
1507+ inspectorClient . clearMessages ( notificationsMessagePredicate ) ;
1508+ } else {
1509+ setNotifications ( [ ] ) ;
1510+ }
15021511 } ;
15031512
15041513 const sendLogLevelRequest = async ( level : LoggingLevel ) => {
0 commit comments