Skip to main content
Glama
itsalfredakku

Postgres MCP Server

transactions

Manage PostgreSQL database transactions with actions to begin, commit, rollback, and control savepoints for reliable data operations.

Instructions

Transaction management: begin, commit, rollback, savepoints

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: begin (start transaction), commit (commit transaction), rollback (rollback transaction), savepoint (create savepoint), rollback_to (rollback to savepoint), release (release savepoint), status (transaction status)
transactionIdNoTransaction ID (required for commit, rollback, and operations within transaction)
savepointNameNoSavepoint name (required for savepoint, rollback_to, release)
readOnlyNoStart read-only transaction (for begin action)
isolationLevelNoTransaction isolation level (for begin action)

Implementation Reference

  • Schema definition for the 'transactions' MCP tool, including input parameters and actions (begin, commit, rollback, status, etc.)
    {
      name: 'transactions',
      description: 'Transaction management: begin, commit, rollback, savepoints',
      inputSchema: {
        type: 'object',
        properties: {
          action: {
            type: 'string',
            enum: ['begin', 'commit', 'rollback', 'savepoint', 'rollback_to', 'release', 'status'],
            description: 'Action: begin (start transaction), commit (commit transaction), rollback (rollback transaction), savepoint (create savepoint), rollback_to (rollback to savepoint), release (release savepoint), status (transaction status)'
          },
          transactionId: {
            type: 'string',
            description: 'Transaction ID (required for commit, rollback, and operations within transaction)'
          },
          savepointName: {
            type: 'string',
            description: 'Savepoint name (required for savepoint, rollback_to, release)'
          },
          readOnly: {
            type: 'boolean',
            description: 'Start read-only transaction (for begin action)',
            default: false
          },
          isolationLevel: {
            type: 'string',
            enum: ['READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ', 'SERIALIZABLE'],
            description: 'Transaction isolation level (for begin action)'
          }
        },
        required: ['action']
      }
    },
  • src/index.ts:634-637 (registration)
    Registration of the 'transactions' tool via the toolDefinitions array returned in ListToolsRequestSchema handler
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: toolDefinitions,
    }));
  • Primary handler function for 'transactions' tool calls, handling begin/commit/rollback/status actions by delegating to DatabaseConnectionManager
    private async handleTransactions(args: any) {
      const { action, transactionId, readOnly, isolationLevel } = args;
    
      switch (action) {
        case 'begin':
          const txId = await this.dbManager.beginTransaction(readOnly);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ transactionId: txId, status: 'started' }, null, 2)
            }]
          };
    
        case 'commit':
          ParameterValidator.validateRequired(transactionId, 'transactionId');
          await this.dbManager.commitTransaction(transactionId);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ transactionId, status: 'committed' }, null, 2)
            }]
          };
    
        case 'rollback':
          ParameterValidator.validateRequired(transactionId, 'transactionId');
          await this.dbManager.rollbackTransaction(transactionId);
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ transactionId, status: 'rolled_back' }, null, 2)
            }]
          };
    
        case 'status':
          return {
            content: [{
              type: 'text',
              text: JSON.stringify(this.dbManager.getOperationalStats(), null, 2)
            }]
          };
    
        default:
          throw new Error(`Unknown transaction action: ${action}`);
      }
    }
  • Core beginTransaction helper method that creates a new transaction context, supports read-only mode, and tracks active transactions
    async beginTransaction(readOnly: boolean = false): Promise<string> {
      const transactionId = uuidv4();
      const client = await this.pool.connect();
      
      try {
        if (readOnly) {
          await client.query('BEGIN READ ONLY');
        } else {
          if (this.config.isReadOnlyMode()) {
            throw new Error('Write transactions are not allowed in read-only mode');
          }
          await client.query('BEGIN');
        }
        
        const context: TransactionContext = {
          id: transactionId,
          client,
          startTime: Date.now(),
          readOnly
        };
        
        this.activeTransactions.set(transactionId, context);
        this.connectionStats.totalTransactions++;
        
        logConnection('transaction_started', { 
          transactionId, 
          readOnly,
          activeTransactions: this.activeTransactions.size 
        });
        
        return transactionId;
      } catch (error) {
        client.release();
        throw error;
      }
    }
  • Core commitTransaction helper method that commits the transaction and cleans up the context
    async commitTransaction(transactionId: string): Promise<void> {
      const context = this.activeTransactions.get(transactionId);
      if (!context) {
        throw new Error(`Transaction ${transactionId} not found`);
      }
    
      try {
        await context.client.query('COMMIT');
        const duration = Date.now() - context.startTime;
        
        logConnection('transaction_committed', { 
          transactionId, 
          duration: `${duration}ms` 
        });
      } finally {
        context.client.release();
        this.activeTransactions.delete(transactionId);
      }
    }
  • Core rollbackTransaction helper method that rolls back the transaction and cleans up the context
    async rollbackTransaction(transactionId: string): Promise<void> {
      const context = this.activeTransactions.get(transactionId);
      if (!context) {
        throw new Error(`Transaction ${transactionId} not found`);
      }
    
      try {
        await context.client.query('ROLLBACK');
        const duration = Date.now() - context.startTime;
        
        logConnection('transaction_rolled_back', { 
          transactionId, 
          duration: `${duration}ms` 
        });
      } finally {
        context.client.release();
        this.activeTransactions.delete(transactionId);
      }
    }
  • getOperationalStats helper method providing transaction status and statistics used by 'status' action
    getOperationalStats() {
      return {
        ...this.connectionStats,
        activeTransactions: this.activeTransactions.size,
        poolStats: this.getPoolStats()
      };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions actions but doesn't describe side effects (e.g., 'commit' permanently changes data, 'rollback' reverts changes), error handling, concurrency implications, or resource usage. For a transaction management tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded with a single phrase that captures the essence. Every word earns its place by listing key actions without redundancy. It's appropriately sized for a tool with a well-documented schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of transaction management (with mutating actions like commit/rollback), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects, return values, error conditions, or integration with other tools. For a 5-parameter tool handling critical database operations, this is inadequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly with descriptions and enums. The description lists action types but doesn't add meaning beyond what the schema provides (e.g., it doesn't explain transaction lifecycle or savepoint usage). Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Transaction management' with specific actions listed (begin, commit, rollback, savepoints). It uses a verb+resource structure ('management' of 'transactions'), though it doesn't explicitly differentiate from sibling tools like 'query' or 'data' which might also involve transaction operations. The description is specific but lacks sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It lists actions but doesn't indicate context, prerequisites, or relationships with sibling tools like 'query' (which might execute queries within transactions) or 'data' (which might handle data manipulation). There's no mention of when to begin/commit transactions versus using other tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/itsalfredakku/postgres-mcp'

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