disconnect_database
Terminates the active connection to a PostgreSQL database, ensuring secure disengagement for read-only AI assistant interactions managed by the Postgre MCP Server.
Instructions
Disconnect from the current PostgreSQL database
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_database"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:445-484 (registration)Registers the 'disconnect_database' tool with server.tool. Includes empty input schema, description, and an inline async handler that disconnects the PostgreSQL database by calling dbClient.end() if connected, handling success, no-connection, and error cases.
server.tool( "disconnect_database", "Disconnect from the current PostgreSQL database", {}, async () => { try { if (dbClient) { await dbClient.end(); dbClient = null; return { content: [ { type: "text", text: "Successfully disconnected from database.", }, ], }; } else { return { content: [ { type: "text", text: "No active database connection to disconnect.", }, ], }; } } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error"; return { content: [ { type: "text", text: `Error disconnecting from database: ${errorMessage}`, }, ], }; } } ); - src/index.ts:449-483 (handler)Inline handler function for disconnect_database tool. Checks if dbClient exists, ends the connection, sets to null, and returns appropriate text response. Handles no connection and errors gracefully.
async () => { try { if (dbClient) { await dbClient.end(); dbClient = null; return { content: [ { type: "text", text: "Successfully disconnected from database.", }, ], }; } else { return { content: [ { type: "text", text: "No active database connection to disconnect.", }, ], }; } } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error"; return { content: [ { type: "text", text: `Error disconnecting from database: ${errorMessage}`, }, ], }; } } - src/index.ts:448-448 (schema)Empty input schema object, indicating the tool takes no input parameters.
{},