11import type { BaseConnector } from './connectors/base.js'
2- import { logger } from './logging.js'
32
43export class MCPSession {
54 readonly connector : BaseConnector
65 private autoConnect : boolean
7- private _sessionInfo : Record < string , any > | null = null
8- private _tools : Record < string , any > [ ] = [ ]
96
107 constructor ( connector : BaseConnector , autoConnect = true ) {
118 this . connector = connector
129 this . autoConnect = autoConnect
1310 }
1411
15- async open ( ) : Promise < this> {
16- await this . connect ( )
17- return this
18- }
19-
20- async close ( ) : Promise < void > {
21- await this . disconnect ( )
22- }
23-
2412 async connect ( ) : Promise < void > {
2513 await this . connector . connect ( )
2614 }
@@ -29,38 +17,14 @@ export class MCPSession {
2917 await this . connector . disconnect ( )
3018 }
3119
32- async initialize ( ) : Promise < Record < string , any > > {
20+ async initialize ( ) : Promise < void > {
3321 if ( ! this . isConnected && this . autoConnect ) {
3422 await this . connect ( )
3523 }
36-
37- this . _sessionInfo = await this . connector . initialize ( ) ?? { }
38- await this . discoverTools ( )
39- return this . _sessionInfo
24+ await this . connector . initialize ( )
4025 }
4126
4227 get isConnected ( ) : boolean {
4328 return this . connector && this . connector . isClientConnected
4429 }
45-
46- get sessionInfo ( ) : Record < string , any > | null {
47- return this . _sessionInfo
48- }
49-
50- get tools ( ) : Record < string , any > [ ] {
51- return this . _tools
52- }
53-
54- async discoverTools ( ) : Promise < Record < string , any > [ ] > {
55- this . _tools = this . connector . tools
56- return this . _tools
57- }
58-
59- async callTool ( name : string , args : Record < string , any > ) : Promise < any > {
60- if ( ! this . isConnected && this . autoConnect ) {
61- await this . connect ( )
62- }
63- logger . debug ( `MCPSession calling tool '${ name } '` )
64- return await this . connector . callTool ( name , args )
65- }
6630}
0 commit comments