Skip to main content
Glama
nbbaier

MCP-Turso

query_database

Execute SELECT queries to retrieve data from Turso-hosted LibSQL databases. Use this tool to read database information by providing SQL statements.

Instructions

Execute a SELECT query to read data from the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL query to execute

Implementation Reference

  • The execute handler for the "query_database" tool. It logs the query, calls the `query` helper function with the provided SQL and database client, formats the result as JSON content, or returns an error message if execution fails.
    execute: async ({ sql }) => {
    	try {
    		logger.info(`Executing query: ${sql}`);
    		const result = await query(sql, db);
    		return content(JSON.stringify(result, null, 2));
    	} catch (error) {
    		logger.error("Failed to execute query", error);
    		return content(
    			`Error executing query: ${error instanceof Error ? error.message : String(error)}`,
    			true,
    		);
    	}
    },
  • Zod input schema for the tool, defining a required non-empty string parameter 'sql' for the SQL query.
    parameters: z.object({
    	sql: z
    		.string()
    		.describe("SQL query to execute")
    		.min(1, "SQL query is required"),
    }),
  • src/index.ts:107-129 (registration)
    Registration of the "query_database" tool using FastMCP's server.addTool method, including name, description, input schema, and inline execute handler.
    server.addTool({
    	name: "query_database",
    	description: "Execute a SELECT query to read data from the database",
    	parameters: z.object({
    		sql: z
    			.string()
    			.describe("SQL query to execute")
    			.min(1, "SQL query is required"),
    	}),
    	execute: async ({ sql }) => {
    		try {
    			logger.info(`Executing query: ${sql}`);
    			const result = await query(sql, db);
    			return content(JSON.stringify(result, null, 2));
    		} catch (error) {
    			logger.error("Failed to execute query", error);
    			return content(
    				`Error executing query: ${error instanceof Error ? error.message : String(error)}`,
    				true,
    			);
    		}
    	},
    });
  • Core helper function `query` that performs the actual database query execution. Validates that the query starts with SELECT, executes it using the libsql client with no args, and returns structured response with columns, rows, and count.
    export async function query<T = Record<string, unknown>>(
    	sql: string,
    	client: Client,
    ): Promise<{
    	columns: string[];
    	rows: T[];
    	rowCount: number;
    }> {
    	const trimmedQuery = sql.trim().toUpperCase();
    	if (!trimmedQuery.startsWith("SELECT")) {
    		throw new Error("Only SELECT queries are allowed for safety reasons");
    	}
    
    	const result = await client.execute({
    		sql,
    		args: [],
    	});
    
    	return {
    		columns: result.columns,
    		rows: result.rows as T[],
    		rowCount: result.rows.length,
    	};
    }
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 this is for 'read data' operations, which implies non-destructive behavior, but doesn't clarify important aspects like authentication requirements, rate limits, error handling, or result format. The description is too minimal to provide adequate transparency for a database query tool.

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 extremely concise - a single sentence that communicates the essential purpose without any wasted words. It's front-loaded with the core functionality and uses precise technical language ('SELECT query', 'read data'). Every word earns its place in this minimal but complete statement.

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 database query tool with no annotations and no output schema, the description is insufficiently complete. It doesn't address critical context like what happens with invalid SQL, whether transactions are supported, what the return format looks like, or any performance considerations. The description covers only the most basic purpose without addressing the operational complexity of database interactions.

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 description adds no parameter-specific information beyond what's already in the schema (which has 100% coverage). The schema fully documents the single 'sql' parameter with its type and constraints. The description doesn't provide additional context about SQL syntax requirements, supported SQL features, or query limitations. Baseline score of 3 is appropriate when schema coverage is complete.

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 a SELECT query') and resource ('read data from the database'), making the purpose immediately understandable. It distinguishes from siblings like 'describe_table' or 'list_tables' by focusing on query execution rather than metadata retrieval. However, it doesn't explicitly mention what type of database or data is involved, 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 like 'get_db_schema' or 'describe_table'. It doesn't mention prerequisites (e.g., needing valid SQL syntax) or constraints (e.g., read-only queries only). While the description implies usage for reading data, it lacks explicit when-to-use or when-not-to-use instructions.

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/nbbaier/mcp-turso'

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