connection-status
Verify the current database connection status on MSSQL MCP Server to ensure stable and reliable interactions with Microsoft SQL Server databases.
Instructions
檢查目前的資料庫連接狀態
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:437-474 (handler)Handler function that implements the logic for the 'connection-status' tool: checks connection status, current database, tests the connection, and returns a text response with the status.async () => { try { const isConnected = mssqlManager.isConnected() const currentDb = mssqlManager.getCurrentDatabase() if (!isConnected) { return { content: [ { type: 'text' as const, text: '狀態: 未連接到資料庫伺服器' } ] } } const testResult = await mssqlManager.testConnection() const status = testResult ? '已連接且運作正常' : '連接異常' return { content: [ { type: 'text' as const, text: `狀態: ${status}${currentDb ? `\n目前資料庫: ${currentDb}` : '\n未選擇資料庫'}` } ] } } catch (error) { return { content: [ { type: 'text' as const, text: `檢查連接狀態失敗: ${error instanceof Error ? error.message : String(error)}` } ] } } }
- src/index.ts:432-475 (registration)Registers the 'connection-status' tool with the MCP server, providing title, description, and the inline handler function.'connection-status', { title: '連接狀態', description: '檢查目前的資料庫連接狀態' }, async () => { try { const isConnected = mssqlManager.isConnected() const currentDb = mssqlManager.getCurrentDatabase() if (!isConnected) { return { content: [ { type: 'text' as const, text: '狀態: 未連接到資料庫伺服器' } ] } } const testResult = await mssqlManager.testConnection() const status = testResult ? '已連接且運作正常' : '連接異常' return { content: [ { type: 'text' as const, text: `狀態: ${status}${currentDb ? `\n目前資料庫: ${currentDb}` : '\n未選擇資料庫'}` } ] } } catch (error) { return { content: [ { type: 'text' as const, text: `檢查連接狀態失敗: ${error instanceof Error ? error.message : String(error)}` } ] } } } )