Skip to main content
Glama
melihbirim

PostgreSQL MCP Server

by melihbirim

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

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}`,
              },
            ],
          };
        }
      }
    );
  • 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}`,
            },
          ],
        };
      }
    }
  • Empty input schema object, indicating the tool takes no input parameters.
    {},
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/melihbirim/pg-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server