From 2b4ad00cb5f79b0d540f2a5575b714e9e7029c7a Mon Sep 17 00:00:00 2001 From: Zan <37948383+zandko@users.noreply.github.com> Date: Mon, 2 Jun 2025 22:57:45 +0800 Subject: [PATCH] refactor: Simplify MCPSession by removing unused properties and methods --- src/session.ts | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/src/session.ts b/src/session.ts index 58ad4fd8..172a5e3c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1,26 +1,14 @@ import type { BaseConnector } from './connectors/base.js' -import { logger } from './logging.js' export class MCPSession { readonly connector: BaseConnector private autoConnect: boolean - private _sessionInfo: Record | null = null - private _tools: Record[] = [] constructor(connector: BaseConnector, autoConnect = true) { this.connector = connector this.autoConnect = autoConnect } - async open(): Promise { - await this.connect() - return this - } - - async close(): Promise { - await this.disconnect() - } - async connect(): Promise { await this.connector.connect() } @@ -29,38 +17,14 @@ export class MCPSession { await this.connector.disconnect() } - async initialize(): Promise> { + async initialize(): Promise { if (!this.isConnected && this.autoConnect) { await this.connect() } - - this._sessionInfo = await this.connector.initialize() ?? {} - await this.discoverTools() - return this._sessionInfo + await this.connector.initialize() } get isConnected(): boolean { return this.connector && this.connector.isClientConnected } - - get sessionInfo(): Record | null { - return this._sessionInfo - } - - get tools(): Record[] { - return this._tools - } - - async discoverTools(): Promise[]> { - this._tools = this.connector.tools - return this._tools - } - - async callTool(name: string, args: Record): Promise { - if (!this.isConnected && this.autoConnect) { - await this.connect() - } - logger.debug(`MCPSession calling tool '${name}'`) - return await this.connector.callTool(name, args) - } }