Skip to main content
Glama
l1806858547

TiDB MCP Server

by l1806858547

tidb_query

Execute SQL queries on TiDB databases through the MCP server, enabling SELECT, INSERT, UPDATE, and DELETE operations for efficient data management.

Instructions

Execute SQL queries against TiDB

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL query to execute

Implementation Reference

  • Registers and implements the handler for CallToolRequestSchema, specifically handling 'tidb_query' by executing SQL queries on TiDB with permission checks for INSERT/UPDATE/DELETE.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== 'tidb_query') {
        throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
      }
    
      if (!request.params.arguments || typeof request.params.arguments.sql !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'SQL query is required and must be a string');
      }
    
      try {
        const sql = request.params.arguments.sql.trim().toLowerCase();
        const sqlType = sql.split(' ')[0];
        
        // 检查操作权限
        if (sqlType === 'insert' && process.env.ALLOW_INSERT_OPERATION !== 'true') {
          throw new McpError(ErrorCode.InvalidRequest, 'INSERT operations are not allowed');
        }
        if (sqlType === 'update' && process.env.ALLOW_UPDATE_OPERATION !== 'true') {
          throw new McpError(ErrorCode.InvalidRequest, 'UPDATE operations are not allowed');
        }
        if (sqlType === 'delete' && process.env.ALLOW_DELETE_OPERATION !== 'true') {
          throw new McpError(ErrorCode.InvalidRequest, 'DELETE operations are not allowed');
        }
        
        const [rows] = await this.pool.query(sql);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(rows, null, 2)
          }]
        };
      } catch (error) {
        if (error instanceof Error) {
          return {
            content: [{
              type: 'text',
              text: `TiDB query error: ${error.message}`
            }],
            isError: true
          };
        }
        throw error;
      }
    });
  • Defines the input schema for the tidb_query tool, requiring a 'sql' string property.
    inputSchema: {
      type: 'object',
      properties: {
        sql: {
          type: 'string',
          description: 'The SQL query to execute'
        }
      },
      required: ['sql']
    }
  • src/index.ts:73-88 (registration)
    Registers the 'tidb_query' tool in the ListToolsRequestSchema response, including name, description, and input schema.
        {
          name: 'tidb_query',
          description: 'Execute SQL queries against TiDB',
          inputSchema: {
            type: 'object',
            properties: {
              sql: {
                type: 'string',
                description: 'The SQL query to execute'
              }
            },
            required: ['sql']
          }
        }
      ]
    }));
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 but only states the basic action without details on permissions, side effects, rate limits, or response format. It fails to address critical aspects like whether queries are read-only, transactional, or have other constraints.

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, efficient sentence with zero waste, clearly front-loading the tool's purpose. It is appropriately sized for a simple tool with one parameter and no complex context.

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 lack of annotations and output schema, the description is incomplete for a tool that executes SQL queries. It omits essential context like return value format, error handling, or behavioral traits, leaving significant gaps for an AI agent to understand the tool fully.

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 schema description coverage is 100%, so the input schema already documents the 'sql' parameter fully. The description does not add any meaning beyond what the schema provides, such as SQL dialect specifics or query limitations, resulting in a baseline score.

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 ('Execute SQL queries') and target resource ('against TiDB'), providing a specific verb+resource combination. It distinguishes the tool's function effectively, though there are no sibling tools to differentiate from, 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, prerequisites, or context for its application. It lacks explicit usage instructions, making it minimally helpful for decision-making in a broader toolset.

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

Related 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/l1806858547/tidb-server'

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