disconnect_database
Close database connections to free up resources and manage connection pooling in the MCP Universal DB Client. Use this tool to terminate specific database sessions when they are no longer needed.
Instructions
Disconnect from a database using connection ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionID | Yes | The connection ID to disconnect |
Input Schema (JSON Schema)
{
"properties": {
"connectionID": {
"description": "The connection ID to disconnect",
"type": "string"
}
},
"required": [
"connectionID"
],
"type": "object"
}
Implementation Reference
- src/index.ts:73-84 (handler)The async handler function for the 'disconnect_database' tool. It retrieves the connection ID from input, calls deleteConnection on the DatabaseConnections instance, and returns a text content confirming the disconnection.async (input) => { databaseConnections.deleteConnection(input.connectionID); return { content: [ { type: "text", text: `Disconnected connection ID: ${input.connectionID}`, }, ], }; }
- src/index.ts:69-71 (schema)Inline input schema for the 'disconnect_database' tool, using Zod to validate the 'connectionID' string parameter.inputSchema: { connectionID: z.string().describe("The connection ID to disconnect"), },
- src/index.ts:64-85 (registration)Registration of the 'disconnect_database' tool on the MCP server, specifying title, description, input schema, and handler function.mcpServer.registerTool( "disconnect_database", { title: "Disconnect Database", description: "Disconnect from a database using connection ID", inputSchema: { connectionID: z.string().describe("The connection ID to disconnect"), }, }, async (input) => { databaseConnections.deleteConnection(input.connectionID); return { content: [ { type: "text", text: `Disconnected connection ID: ${input.connectionID}`, }, ], }; } );
- src/connection.ts:89-97 (helper)The 'deleteConnection' method in the DatabaseConnections class, which finds the connection, calls destroy() on its Kysely instance to disconnect, removes it from the internal map, and returns boolean success.public deleteConnection(name: string) { const conn = this.connections.get(name); if (conn) { conn.instance.destroy(); this.connections.delete(name); return true; } return false; }