query
Execute read-only SQL queries to retrieve data from a MySQL database, enabling database interaction through JSON commands.
Instructions
Executes a read-only SQL query.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
Implementation Reference
- src/index.ts:88-96 (handler)The handler for the 'query' tool executes a read-only SQL query on the MySQL database and returns the result rows as a formatted JSON string.case "query": { const sql = request.params.arguments?.sql as string; await connection.query('START TRANSACTION READ ONLY'); const [rows] = await connection.query(sql); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }], isError: false, }; }
- src/index.ts:42-48 (schema)Input schema definition for the 'query' tool, specifying an object with a required 'sql' string property.inputSchema: { type: "object", properties: { sql: { type: "string" }, }, required: ["sql"], },
- src/index.ts:39-49 (registration)Registration of the 'query' tool in the tools list returned by the ListToolsRequestHandler.{ name: "query", description: "Executes a read-only SQL query.", inputSchema: { type: "object", properties: { sql: { type: "string" }, }, required: ["sql"], }, },