Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

update_row

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

Instructions

Update an existing row by primary key.

Args:
    table: Table name (can include schema: 'dbo.Users' or 'Users')
    id: Primary key value of the row to update
    data: Dictionary of column names and new values

Returns:
    Dictionary with:
    - status: 'success' or error
    - table: Full table name
    - updated: The updated row

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes
idYes
dataYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'update_row' tool, decorated with @mcp.tool() which registers it in the MCP system. It performs an SQL UPDATE on the specified table row by primary key, using OUTPUT to return the updated row.
    @mcp.tool()
    def update_row(table: str, id: Any, data: dict[str, Any]) -> dict[str, Any]:
        """Update an existing row by primary key.
    
        Args:
            table: Table name (can include schema: 'dbo.Users' or 'Users')
            id: Primary key value of the row to update
            data: Dictionary of column names and new values
    
        Returns:
            Dictionary with:
            - status: 'success' or error
            - table: Full table name
            - updated: The updated row
        """
        try:
            manager = get_connection_manager()
            config = manager.config
    
            # Check read-only mode
            if config.read_only:
                return {"error": "Write operations disabled in read-only mode"}
    
            schema, table_name = parse_table_name(table)
    
            if not data:
                return {"error": "No data provided for update"}
    
            # Get primary key column
            pk_cols = _get_primary_key_columns(schema, table_name)
            if not pk_cols:
                return {"error": f"No primary key found for table {schema}.{table_name}"}
    
            # Build UPDATE statement with OUTPUT clause
            set_clauses = ", ".join([f"[{k}] = %s" for k in data])
            params = tuple(data.values()) + (id,)
    
            query = f"""
                UPDATE [{schema}].[{table_name}]
                SET {set_clauses}
                OUTPUT INSERTED.*
                WHERE [{pk_cols[0]}] = %s
            """
    
            rows = manager.execute_query(query, params)
    
            if not rows:
                return {
                    "error": f"No row found with {pk_cols[0]} = {id}",
                    "table": f"{schema}.{table_name}",
                }
    
            return {
                "status": "success",
                "table": f"{schema}.{table_name}",
                "updated": rows[0],
            }
    
        except QueryError as e:
            logger.error(f"Error updating row in {table}: {e}")
            return {"error": str(e)}
        except Exception as e:
            logger.error(f"Unexpected error updating row in {table}: {e}")
            return {"error": str(e)}
Behavior2/5

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

With no annotations provided, the description carries full burden but only covers basic operation. It doesn't disclose critical behavioral traits like required permissions, whether updates are atomic/reversible, error handling beyond status codes, or constraints (e.g., data validation, triggers). The return format is described, but mutation risks and side effects are omitted.

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 efficiently structured with a clear purpose statement followed by organized sections for Args and Returns. Each sentence adds value: the first defines the operation, subsequent lines explain parameters, and the last details output. No redundant or verbose content.

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?

For a mutation tool with 3 parameters, 0% schema coverage, no annotations, but an output schema, the description is partially complete. It covers parameters and return structure adequately, but lacks context on safety, error conditions, and operational constraints, leaving gaps for an agent to use it correctly in complex scenarios.

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%, but the description adds meaningful context: 'table' can include schema prefixes, 'id' is the primary key value, and 'data' is a dictionary of column-value pairs. This clarifies parameter roles beyond schema types, though it doesn't detail data format constraints or id type expectations.

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

Purpose5/5

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

The description clearly states the specific action ('Update an existing row'), target resource ('by primary key'), and distinguishes from siblings like 'insert_row' (creates new) and 'delete_row' (removes). It uses precise terminology that differentiates its function within the database operation toolset.

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

Usage Guidelines3/5

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

The description implies usage for modifying existing rows identified by primary key, but doesn't explicitly state when to use this vs. alternatives like 'insert_row' for new rows or 'execute_query' for complex updates. No guidance on prerequisites (e.g., connection state) or exclusions is provided.

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/mssql-mcp'

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