@@ -45,6 +45,7 @@ import {
45
45
} from "@/utils/configUtils" ;
46
46
import { getMCPServerRequestTimeout } from "@/utils/configUtils" ;
47
47
import { InspectorConfig } from "../configurationTypes" ;
48
+ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
48
49
49
50
interface UseConnectionOptions {
50
51
transportType : "stdio" | "sse" | "streamable-http" ;
@@ -83,6 +84,9 @@ export function useConnection({
83
84
const [ serverCapabilities , setServerCapabilities ] =
84
85
useState < ServerCapabilities | null > ( null ) ;
85
86
const [ mcpClient , setMcpClient ] = useState < Client | null > ( null ) ;
87
+ const [ clientTransport , setClientTransport ] = useState < Transport | null > (
88
+ null ,
89
+ ) ;
86
90
const [ requestHistory , setRequestHistory ] = useState <
87
91
{ request : string ; response ?: string } [ ]
88
92
> ( [ ] ) ;
@@ -384,14 +388,6 @@ export function useConnection({
384
388
transportType ,
385
389
) ;
386
390
387
- const clientTransport =
388
- transportType === "streamable-http"
389
- ? new StreamableHTTPClientTransport ( mcpProxyServerUrl as URL , {
390
- sessionId : undefined ,
391
- ...transportOptions ,
392
- } )
393
- : new SSEClientTransport ( mcpProxyServerUrl as URL , transportOptions ) ;
394
-
395
391
if ( onNotification ) {
396
392
[
397
393
CancelledNotificationSchema ,
@@ -421,7 +417,20 @@ export function useConnection({
421
417
422
418
let capabilities ;
423
419
try {
424
- await client . connect ( clientTransport ) ;
420
+ const transport =
421
+ transportType === "streamable-http"
422
+ ? new StreamableHTTPClientTransport ( mcpProxyServerUrl as URL , {
423
+ sessionId : undefined ,
424
+ ...transportOptions ,
425
+ } )
426
+ : new SSEClientTransport (
427
+ mcpProxyServerUrl as URL ,
428
+ transportOptions ,
429
+ ) ;
430
+
431
+ await client . connect ( transport as Transport ) ;
432
+
433
+ setClientTransport ( transport ) ;
425
434
426
435
capabilities = client . getServerCapabilities ( ) ;
427
436
const initializeRequest = {
@@ -475,10 +484,15 @@ export function useConnection({
475
484
} ;
476
485
477
486
const disconnect = async ( ) => {
487
+ if ( transportType === "streamable-http" )
488
+ await (
489
+ clientTransport as StreamableHTTPClientTransport
490
+ ) . terminateSession ( ) ;
478
491
await mcpClient ?. close ( ) ;
479
492
const authProvider = new InspectorOAuthClientProvider ( sseUrl ) ;
480
493
authProvider . clear ( ) ;
481
494
setMcpClient ( null ) ;
495
+ setClientTransport ( null ) ;
482
496
setConnectionStatus ( "disconnected" ) ;
483
497
setCompletionsSupported ( false ) ;
484
498
setServerCapabilities ( null ) ;
0 commit comments