Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

update_row

Modify existing database records by specifying the table, primary key value, and new column data to update.

Instructions

Update an existing row by primary key.

Args:
    table: Table name (schema.table or just table).
    id_value: Primary key value.
    data: Column names and new values.
    id_column: Name of the ID column (default: 'id').
    returning: Columns to return from updated row.

Returns:
    Update result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes
id_valueYes
dataYes
id_columnNoid
returningNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler implementing the update_row tool. Validates table and data, constructs UPDATE SQL query with optional RETURNING clause, executes via connection manager, and returns success/error response.
    async def update_row(
        table: str,
        id_value: str | int,
        data: dict[str, Any],
        id_column: str = "id",
        returning: list[str] | None = None,
    ) -> dict[str, Any]:
        """Update an existing row by primary key.
    
        Args:
            table: Table name (schema.table or just table).
            id_value: Primary key value.
            data: Column names and new values.
            id_column: Name of the ID column (default: 'id').
            returning: Columns to return from updated row.
    
        Returns:
            Update result.
        """
        # Check read-only mode
        if settings.read_only:
            return {"status": "error", "error": "Server is in read-only mode"}
    
        # Validate table name
        valid, error = _validate_table_name(table)
        if not valid:
            return {"status": "error", "error": error}
    
        if not data:
            return {"status": "error", "error": "No data provided"}
    
        schema, table_name = _parse_table_name(table)
    
        # Validate column names
        for col in data.keys():
            if not re.match(r"^[\w]+$", col):
                return {"status": "error", "error": f"Invalid column name: {col}"}
    
        # Build UPDATE query
        set_clauses = [f"{col} = %s" for col in data.keys()]
        set_clause = ", ".join(set_clauses)
        values = list(data.values())
        values.append(id_value)
    
        query = f"UPDATE {schema}.{table_name} SET {set_clause} WHERE {id_column} = %s"
    
        # Add RETURNING clause
        if returning:
            for col in returning:
                if not re.match(r"^[\w]+$", col):
                    return {"status": "error", "error": f"Invalid column name in returning: {col}"}
            query += f" RETURNING {', '.join(returning)}"
    
        conn = await connection_manager.ensure_connected()
    
        try:
            async with conn.cursor() as cur:
                await cur.execute(query, tuple(values))
    
                if returning:
                    row = await cur.fetchone()
                    return {
                        "status": "success",
                        "table": f"{schema}.{table_name}",
                        "action": "updated",
                        "id": id_value,
                        "returning": row,
                    }
                else:
                    return {
                        "status": "success",
                        "table": f"{schema}.{table_name}",
                        "action": "updated",
                        "id": id_value,
                        "rows_affected": cur.rowcount,
                    }
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • MCP tool registration for 'update_row' using @mcp.tool() decorator. Thin wrapper that delegates to the core crud.update_row implementation and handles exceptions.
    @mcp.tool()
    async def update_row(
        table: str,
        id_value: str | int,
        data: dict[str, Any],
        id_column: str = "id",
        returning: list[str] | None = None,
    ) -> dict[str, Any]:
        """Update an existing row by primary key.
    
        Args:
            table: Table name (schema.table or just table).
            id_value: Primary key value.
            data: Column names and new values.
            id_column: Name of the ID column (default: 'id').
            returning: Columns to return from updated row.
    
        Returns:
            Update result.
        """
        try:
            return await crud.update_row(table, id_value, data, id_column, returning)
        except Exception as e:
            return {"status": "error", "error": str(e)}
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states this is an update operation, implying mutation, but doesn't disclose behavioral traits like whether it requires write permissions, what happens on non-existent rows (e.g., error vs. no-op), if it's atomic, or any rate limits. The description is minimal and lacks critical context for a mutation tool.

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

Conciseness4/5

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

The description is well-structured and appropriately sized. It front-loads the purpose in one sentence, then lists parameters and returns in clear sections. Every sentence earns its place, with no redundant information. It could be slightly more concise by integrating the 'Args' and 'Returns' into the main text, but it's efficient.

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

Completeness3/5

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

Given the tool's complexity (mutation with 5 parameters, nested objects) and no annotations, the description is moderately complete. It covers parameters well and mentions a return value, but lacks behavioral context (e.g., error handling, permissions). The presence of an output schema reduces the need to detail return values, but overall gaps remain for safe usage.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It provides clear semantics for all 5 parameters in the 'Args' section, explaining each parameter's purpose (e.g., 'table: Table name', 'data: Column names and new values'). This adds significant value beyond the bare schema, though it doesn't cover edge cases or examples.

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: 'Update an existing row by primary key.' It specifies the verb ('Update'), resource ('row'), and mechanism ('by primary key'). However, it doesn't explicitly differentiate from sibling tools like 'upsert_row' or 'delete_row' beyond the basic operation name.

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 doesn't mention sibling tools like 'upsert_row' (for insert-or-update), 'delete_row', or 'insert_row', nor does it specify prerequisites like requiring an existing row or transaction context. Usage is implied by the name but not explicitly stated.

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

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