Skip to main content
Glama
bpamiri

SQL Server MCP

by bpamiri

insert_row

Add new records to SQL Server tables by specifying column values. This tool inserts data into specified tables and returns the complete inserted row including generated identity columns.

Instructions

Insert a new row into a table.

Args:
    table: Table name (can include schema: 'dbo.Users' or 'Users')
    data: Dictionary of column names and values to insert

Returns:
    Dictionary with:
    - status: 'success' or error
    - table: Full table name
    - inserted: The inserted row (including generated identity columns)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes
dataYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `insert_row` tool handler function, decorated with `@mcp.tool()` for registration in the MCP server. Handles inserting a new row into a specified table using a parameterized INSERT query with OUTPUT clause to return the inserted data, including auto-generated columns. Includes safety checks for read-only mode and empty data.
    @mcp.tool()
    def insert_row(table: str, data: dict[str, Any]) -> dict[str, Any]:
        """Insert a new row into a table.
    
        Args:
            table: Table name (can include schema: 'dbo.Users' or 'Users')
            data: Dictionary of column names and values to insert
    
        Returns:
            Dictionary with:
            - status: 'success' or error
            - table: Full table name
            - inserted: The inserted row (including generated identity columns)
        """
        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 insert"}
    
            # Build INSERT statement with OUTPUT clause
            cols = ", ".join([f"[{k}]" for k in data])
            placeholders = ", ".join(["%s"] * len(data))
            values = tuple(data.values())
    
            query = f"""
                INSERT INTO [{schema}].[{table_name}] ({cols})
                OUTPUT INSERTED.*
                VALUES ({placeholders})
            """
    
            rows = manager.execute_query(query, values)
    
            # The OUTPUT clause returns the inserted row
            inserted = rows[0] if rows else data
    
            return {
                "status": "success",
                "table": f"{schema}.{table_name}",
                "inserted": inserted,
            }
    
        except QueryError as e:
            logger.error(f"Error inserting row into {table}: {e}")
            return {"error": str(e)}
        except Exception as e:
            logger.error(f"Unexpected error inserting row into {table}: {e}")
            return {"error": str(e)}
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It implies a write operation ('Insert') and describes the return structure, which is helpful. However, it doesn't cover critical aspects like permissions needed, error handling details, transactional behavior, or side effects (e.g., triggers), leaving gaps in transparency 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 with clear sections (Args, Returns) and uses bullet points for readability. It's concise with no wasted sentences, though the 'Returns' section could be slightly more detailed (e.g., explaining error cases). Overall, it's efficiently presented and front-loaded with the core purpose.

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

Completeness4/5

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

Given the tool's complexity (a mutation with 2 parameters), no annotations, and an output schema that documents the return structure, the description is reasonably complete. It covers the purpose, parameter semantics, and return values, though it could improve by adding usage guidelines and more behavioral context (e.g., permissions). The output schema reduces the need to explain returns in detail.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% description coverage. It explains that 'table' can include schema (e.g., 'dbo.Users') and that 'data' is a dictionary of column-value pairs. This clarifies the semantics and format of both parameters, fully compensating for the lack of schema descriptions.

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: 'Insert a new row into a table.' It specifies the verb ('Insert') and resource ('row into a table'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'update_row' or 'delete_row' beyond the basic action, which prevents a perfect score.

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 like 'update_row' or 'execute_query'. It lacks context about prerequisites (e.g., needing a connection or specific database), exclusions, or comparisons with sibling tools, leaving the agent to infer usage based on the tool name alone.

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