Skip to main content
Glama
Liu-creators

MySQL MCP

by Liu-creators

delete_data

Delete rows from a MySQL table by specifying a table name and a WHERE condition. Supports parameterized queries for safe, injection-free data removal, with optional database configuration.

Instructions

从表中删除数据

Args:
    table_name: 表名
    condition: WHERE条件子句
    params: 条件参数列表
    db_config: 数据库连接配置参数,如果为None则使用默认配置
    
Returns:
    包含删除结果的字典

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
conditionYes
paramsNo
db_configNo

Implementation Reference

  • mysql-mcp.py:409-410 (registration)
    Tool registration via @mcp.tool() decorator on the delete_data function
    @mcp.tool()
    async def delete_data(table_name: str, condition: str, params: Optional[List[Any]] = None, db_config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
  • Core handler for delete_data tool - accepts table_name, condition, params, and optional db_config, executes DELETE SQL with parameterized WHERE clause, and returns affected_rows count
    async def delete_data(table_name: str, condition: str, params: Optional[List[Any]] = None, db_config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        """从表中删除数据
        
        Args:
            table_name: 表名
            condition: WHERE条件子句
            params: 条件参数列表
            db_config: 数据库连接配置参数,如果为None则使用默认配置
            
        Returns:
            包含删除结果的字典
        """
        if not table_name or not condition:
            return {"error": "表名和条件不能为空"}
        
        if params is None:
            params = []
            
        try:
            conn = get_connection(db_config)
            cursor = conn.cursor()
            
            delete_sql = f"DELETE FROM {table_name} WHERE {condition}"
            cursor.execute(delete_sql, params)
            conn.commit()
            
            return {
                "success": True,
                "affected_rows": cursor.rowcount,
                "message": f"从表 {table_name} 中删除数据成功"
            }
        except Error as e:
            error_message = f"删除数据失败: {str(e)}"
            if "doesn't exist" in str(e):
                error_message += f"\n原因:表 {table_name} 不存在"
            elif "syntax error" in str(e).lower():
                error_message += f"\n原因:WHERE条件 '{condition}' 存在语法错误" 
            elif "foreign key constraint fails" in str(e):
                error_message += "\n原因:删除操作违反了外键约束"
            return {"error": error_message}
        except Exception as e:
            return {"error": f"删除数据时发生未知错误: {str(e)}"}
        finally:
            if 'conn' in locals() and conn.is_connected():
                cursor.close()
                conn.close()
Behavior2/5

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

No annotations are provided, and the description only states it deletes data and returns a dictionary. It does not disclose destructive behavior, authorization needs, rollback possibilities, or rate limits. For a delete operation, this is insufficient.

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 concise with a purpose sentence followed by a parameter list and return statement. It is front-loaded and contains no unnecessary words. However, it could be more structured with a clear use-case sentence.

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

Completeness2/5

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

Given the tool is destructive (delete) with 4 parameters, no output schema, and no annotations, the description lacks critical details: return dictionary keys, safety warnings, and when to use this vs siblings like update_data. It is incomplete for a production tool.

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

Parameters3/5

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

The input schema has 0% description coverage, so the description must compensate. It provides brief Chinese explanations for each parameter (e.g., table_name: '表名', condition: 'WHERE条件子句'). These add some meaning beyond the schema's types, but are minimal and lack details like format or examples.

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 tool deletes data from a table. It uses the specific verb 'delete' and resource 'data from table'. This distinguishes it from siblings like insert_data, update_data, and create_table.

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 does not provide any guidance on when to use this tool versus alternatives like update_data or execute_query. It lacks prerequisites, warnings about irreversible deletion, or examples.

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/Liu-creators/mysql-mcp'

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