Skip to main content
Glama
alittleyellowkevin

MySQL MCP Server

update_data

Execute SQL UPDATE statements to modify existing records in MySQL database tables, enabling data correction and maintenance operations.

Instructions

更新 MySQL 数据库表中的数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes要执行的 SQL UPDATE 语句

Implementation Reference

  • The handleUpdateData method implements the core logic for the 'update_data' tool: validates the input arguments, ensures the query is an UPDATE statement, executes it using the MySQL connection pool, logs the transaction, and returns a formatted success or error response.
    private async handleUpdateData(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'SQL 查询参数无效。'
        );
      }
    
      const query = request.params.arguments.query;
    
      if (!isUpdateQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'update_data 工具仅允许 UPDATE 查询。'
        );
      }
    
      console.error(`[${transactionId}] 执行 UPDATE 查询: ${query}`);
    
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] 数据更新成功`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: '数据更新成功',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] 查询出错:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL 错误: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
  • The inputSchema defines the expected parameters for the 'update_data' tool: an object with a required 'query' string property containing the SQL UPDATE statement.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: '要执行的 SQL UPDATE 语句',
        },
      },
      required: ['query'],
  • src/index.ts:144-157 (registration)
    The tool descriptor for 'update_data' is registered in the ListTools response, providing the name, description, and input schema.
    {
      name: 'update_data',
      description: '更新 MySQL 数据库表中的数据',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '要执行的 SQL UPDATE 语句',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:202-203 (registration)
    Dispatch in the CallToolRequestSchema handler routes 'update_data' calls to the handleUpdateData method.
    case 'update_data':
      return this.handleUpdateData(request, transactionId);
  • Helper function that checks if a given SQL query starts with 'update' (case-insensitive), used for validation in the update_data handler.
    const isUpdateQuery = (query: string): boolean =>
      query.trim().toLowerCase().startsWith('update');
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. It states the tool updates data, implying a mutation operation, but does not disclose critical traits such as whether it requires specific database permissions, if changes are reversible, potential side effects on related data, or error handling. This leaves significant gaps in understanding the tool's behavior beyond the basic action.

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 a single, concise sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and efficiently communicates the core functionality, making it easy to understand at a glance while avoiding redundancy or fluff.

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?

For a mutation tool with no annotations and no output schema, the description is insufficient. It does not explain what the tool returns (e.g., success status, affected rows), error conditions, or behavioral nuances like transaction handling. Given the complexity of database updates and the lack of structured data, more context is needed to ensure safe and effective use.

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 100% description coverage, with the 'query' parameter clearly documented as '要执行的 SQL UPDATE 语句' (the SQL UPDATE statement to execute). The description does not add any meaning beyond what the schema provides, as it only reiterates the general purpose without detailing parameter usage or constraints. Given the high schema coverage, a baseline score of 3 is appropriate.

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 ('更新' meaning 'update') and the target resource ('MySQL 数据库表中的数据' meaning 'data in MySQL database tables'), providing a specific verb+resource combination. However, it does not distinguish this tool from its sibling 'execute_sql' or 'run_sql_query', which could also potentially update data, leaving some ambiguity about its unique role.

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 'execute_sql' or 'delete_data'. It lacks explicit instructions on prerequisites, such as requiring a valid SQL UPDATE statement, or context for when it is appropriate compared to other data manipulation tools in the sibling list.

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/alittleyellowkevin/Mysql-MCP'

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