Skip to main content
Glama
l1806858547
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'] } } ] }));

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