Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

insert_row

Add a new row to a CockroachDB table by specifying table name and column values, with optional return of inserted data.

Instructions

Insert a new row into a table.

Args:
    table: Table name (schema.table or just table).
    data: Column names and values to insert.
    returning: Columns to return from inserted row.

Returns:
    Insert result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYes
dataYes
returningNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'insert_row': registered with @mcp.tool() decorator, defines input schema via type hints and docstring, delegates execution to crud.insert_row with error handling.
    @mcp.tool()
    async def insert_row(
        table: str,
        data: dict[str, Any],
        returning: list[str] | None = None,
    ) -> dict[str, Any]:
        """Insert a new row into a table.
    
        Args:
            table: Table name (schema.table or just table).
            data: Column names and values to insert.
            returning: Columns to return from inserted row.
    
        Returns:
            Insert result.
        """
        try:
            return await crud.insert_row(table, data, returning)
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Core helper function implementing the insert_row logic: input validation, dynamic SQL INSERT query construction with optional RETURNING, database execution, and result formatting.
    async def insert_row(
        table: str,
        data: dict[str, Any],
        returning: list[str] | None = None,
    ) -> dict[str, Any]:
        """Insert a new row into a table.
    
        Args:
            table: Table name (schema.table or just table).
            data: Column names and values to insert.
            returning: Columns to return from inserted row.
    
        Returns:
            Insert 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 INSERT query
        columns = list(data.keys())
        placeholders = ", ".join(["%s"] * len(columns))
        col_list = ", ".join(columns)
        values = list(data.values())
    
        query = f"INSERT INTO {schema}.{table_name} ({col_list}) VALUES ({placeholders})"
    
        # 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": "inserted",
                        "returning": row,
                    }
                else:
                    return {
                        "status": "success",
                        "table": f"{schema}.{table_name}",
                        "action": "inserted",
                        "rows_affected": cur.rowcount,
                    }
        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?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it correctly identifies this as a write operation ('Insert'), it doesn't mention important behavioral aspects like whether it requires specific permissions, what happens on constraint violations, whether it's transactional by default, or any rate limits. The description is minimal and lacks crucial operational context.

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 perfectly structured and concise. It begins with a clear purpose statement, then provides organized parameter explanations in bullet-like format, and ends with a returns statement. Every sentence earns its place with no wasted words, and the information is front-loaded appropriately.

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 that this is a write operation with no annotations and 3 parameters, the description is somewhat complete but has gaps. The presence of an output schema means the description doesn't need to explain return values, which it correctly avoids. However, for a database mutation tool, it should ideally mention transactional behavior, error conditions, or relationship to sibling tools like 'begin_transaction'.

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?

The description provides clear semantic explanations for all three parameters beyond what the schema offers. The schema has 0% description coverage (only titles), but the description explains that 'table' accepts 'schema.table or just table', 'data' contains 'column names and values to insert', and 'returning' specifies 'columns to return from inserted row'. This adds significant value over the bare schema.

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 action ('Insert a new row') and resource ('into a table'), making the purpose immediately understandable. It distinguishes itself from siblings like 'update_row' or 'upsert_row' by focusing on insertion rather than modification. However, it doesn't explicitly differentiate from 'upsert_row' which might also insert rows under certain conditions.

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 'upsert_row' or 'update_row'. It doesn't mention prerequisites such as needing an active connection or transaction context, nor does it specify when this tool should be avoided (e.g., for bulk inserts). The context is implied 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