query_table
Execute SQL queries on tables within SingleStore databases using the MCP Server, enabling efficient data retrieval and management with SSL security and TypeScript support.
Instructions
Execute a query on a table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL query to execute |
Input Schema (JSON Schema)
{
"properties": {
"query": {
"description": "SQL query to execute",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/index.ts:1462-1487 (handler)The handler for the 'query_table' tool. Validates the input query parameter, executes the SQL query on the SingleStore database connection, serializes the results to JSON, and returns them as text content. Includes error handling for invalid params and query execution errors.case 'query_table': { if (!request.params.arguments || typeof request.params.arguments.query !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'Query parameter must be a string' ); } try { const [rows] = await conn.query(request.params.arguments.query) as [mysql.RowDataPacket[], mysql.FieldPacket[]]; return { content: [ { type: 'text', text: JSON.stringify(rows, null, 2), }, ], }; } catch (error: unknown) { const err = error as Error; throw new McpError( ErrorCode.InternalError, `Query error: ${err.message}` ); } }
- src/index.ts:1195-1207 (schema)The input schema definition for the 'query_table' tool, registered in the ListToolsRequestSchema handler. Defines the expected input as an object with a required 'query' string field.{ name: 'query_table', description: 'Execute a query on a table', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'SQL query to execute', }, }, required: ['query'], },
- src/index.ts:1175-1208 (registration)The tool is registered by including it in the tools array returned by the ListToolsRequestSchema handler in setupToolHandlers method.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'generate_er_diagram', description: 'Generate a Mermaid ER diagram of the database schema', inputSchema: { type: 'object', properties: {}, required: [], }, }, { name: 'list_tables', description: 'List all tables in the database', inputSchema: { type: 'object', properties: {}, required: [], }, }, { name: 'query_table', description: 'Execute a query on a table', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'SQL query to execute', }, }, required: ['query'], }, },