@@ -20,6 +20,7 @@ import {
2020 ServerNotification ,
2121 Tool ,
2222 CompatibilityCallToolResult ,
23+ ClientNotification ,
2324} from "@modelcontextprotocol/sdk/types.js" ;
2425import { useEffect , useRef , useState } from "react" ;
2526
@@ -90,7 +91,7 @@ const App = () => {
9091 const [ url , setUrl ] = useState < string > ( "http://localhost:3001/sse" ) ;
9192 const [ transportType , setTransportType ] = useState < "stdio" | "sse" > ( "stdio" ) ;
9293 const [ requestHistory , setRequestHistory ] = useState <
93- { request : string ; response : string } [ ]
94+ { request : string ; response ? : string } [ ]
9495 > ( [ ] ) ;
9596 const [ mcpClient , setMcpClient ] = useState < Client | null > ( null ) ;
9697 const [ notifications , setNotifications ] = useState < ServerNotification [ ] > ( [ ] ) ;
@@ -158,10 +159,13 @@ const App = () => {
158159 ) ;
159160 } , [ ] ) ;
160161
161- const pushHistory = ( request : object , response : object ) => {
162+ const pushHistory = ( request : object , response ? : object ) => {
162163 setRequestHistory ( ( prev ) => [
163164 ...prev ,
164- { request : JSON . stringify ( request ) , response : JSON . stringify ( response ) } ,
165+ {
166+ request : JSON . stringify ( request ) ,
167+ response : response !== undefined ? JSON . stringify ( response ) : undefined ,
168+ } ,
165169 ] ) ;
166170 } ;
167171
@@ -183,6 +187,20 @@ const App = () => {
183187 }
184188 } ;
185189
190+ const sendNotification = async ( notification : ClientNotification ) => {
191+ if ( ! mcpClient ) {
192+ throw new Error ( "MCP client not connected" ) ;
193+ }
194+
195+ try {
196+ await mcpClient . notification ( notification ) ;
197+ pushHistory ( notification ) ;
198+ } catch ( e : unknown ) {
199+ setError ( ( e as Error ) . message ) ;
200+ throw e ;
201+ }
202+ } ;
203+
186204 const listResources = async ( ) => {
187205 const response = await makeRequest (
188206 {
@@ -275,13 +293,7 @@ const App = () => {
275293 } ;
276294
277295 const handleRootsChange = async ( ) => {
278- if ( mcpClient ) {
279- try {
280- await mcpClient . sendRootsListChanged ( ) ;
281- } catch ( e ) {
282- console . error ( "Failed to send roots list changed notification:" , e ) ;
283- }
284- }
296+ sendNotification ( { method : "notifications/roots/list_changed" } ) ;
285297 } ;
286298
287299 const connectMcpServer = async ( ) => {
0 commit comments