disconnect
Terminates active database connections on MSSQL MCP Server, ensuring secure session closure and efficient resource management for Microsoft SQL Server environments.
Instructions
斷開資料庫連接
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "disconnect"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:484-506 (handler)The handler function for the 'disconnect' MCP tool. It calls the MSSQLManager.disconnect() method and returns a success or error text message.
async () => { try { await mssqlManager.disconnect() return { content: [ { type: 'text' as const, text: '已成功斷開資料庫連接。' } ] } } catch (error) { return { content: [ { type: 'text' as const, text: `斷開連接失敗: ${error instanceof Error ? error.message : String(error)}` } ] } } } - src/index.ts:478-507 (registration)Registration of the 'disconnect' tool using server.registerTool(), including title, description (schema metadata), and the handler function.
server.registerTool( 'disconnect', { title: '斷開連接', description: '斷開資料庫連接' }, async () => { try { await mssqlManager.disconnect() return { content: [ { type: 'text' as const, text: '已成功斷開資料庫連接。' } ] } } catch (error) { return { content: [ { type: 'text' as const, text: `斷開連接失敗: ${error instanceof Error ? error.message : String(error)}` } ] } } } ) - src/database.ts:50-56 (helper)The MSSQLManager class method that actually disconnects by closing the SQL connection pool. Called by the tool handler.
async disconnect(): Promise<void> { if (this.pool) { await this.pool.close() this.pool = null console.log('已斷開資料庫連接') } }