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.
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": "begin_transaction"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/cockroachdb_mcp/server.py:378-389 (registration)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)}