Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

begin_transaction

Start a database transaction to group multiple operations for atomic execution, ensuring data consistency and integrity in CockroachDB.

Instructions

Begin a database transaction.

Returns:
    Transaction status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration of the 'begin_transaction' MCP tool using @mcp.tool() decorator. Thin handler that delegates to connection_manager and handles exceptions.
    @mcp.tool()
    async def begin_transaction() -> dict[str, Any]:
        """Begin a database transaction.
    
        Returns:
            Transaction status.
        """
        try:
            return await connection_manager.begin_transaction()
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Core implementation of begin_transaction in ConnectionManager class: ensures connection, checks for existing transaction, disables autocommit, updates state.
    async def begin_transaction(self) -> dict[str, Any]:
        """Begin a database transaction.
    
        Returns:
            Transaction status.
        """
        conn = await self.ensure_connected()
    
        if self._state.in_transaction:
            return {"status": "error", "error": "Transaction already in progress"}
    
        try:
            # Disable autocommit for transaction
            await conn.set_autocommit(False)
            self._state.in_transaction = True
            return {"status": "started", "message": "Transaction started"}
        except Exception as e:
            return {"status": "error", "error": str(e)}

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/bpamiri/cockroachdb-mcp'

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