Skip to main content
Glama
sam2332

SQLite MCP Server

by sam2332

query_data

Execute SELECT queries on SQLite databases to retrieve and analyze data, enabling AI assistants to interact with database content through structured queries.

Instructions

Execute a SELECT query on the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSQL SELECT query to execute
limitNoMaximum number of rows to return

Implementation Reference

  • The handler function that executes SELECT queries on the SQLite database, enforces SELECT-only, applies LIMIT if missing, formats results as a markdown-like table, and returns as CallToolResult.
    private async queryData(args: { query: string; limit?: number }): Promise<CallToolResult> {
      if (!this.db) {
        throw new Error("No database connected. Use connect_database first.");
      }
    
      try {
        // Ensure it's a SELECT query
        const trimmedQuery = args.query.trim().toLowerCase();
        if (!trimmedQuery.startsWith("select")) {
          throw new Error("Only SELECT queries are allowed with query_data. Use execute_query for other operations.");
        }
    
        const limit = args.limit || 100;
        const queryWithLimit = args.query.toLowerCase().includes("limit") 
          ? args.query 
          : `${args.query} LIMIT ${limit}`;
    
        const results = this.db.prepare(queryWithLimit).all();
        
        if (results.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: "Query executed successfully. No rows returned.",
              } satisfies TextContent,
            ],
          };
        }
    
        // Format results as a table
        const headers = Object.keys(results[0] as Record<string, unknown>);
        const rows = results.map((row) => 
          headers.map(header => String((row as Record<string, unknown>)[header] ?? "NULL")).join(" | ")
        );
        
        const headerRow = headers.join(" | ");
        const separator = headers.map(h => "-".repeat(h.length)).join("-|-");
        const table = [headerRow, separator, ...rows].join("\n");
    
        return {
          content: [
            {
              type: "text",
              text: `Query results (${results.length} rows):\n\n${table}`,
            } satisfies TextContent,
          ],
        };
      } catch (error) {
        throw new Error(`Query failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Input schema definition for the query_data tool, specifying 'query' as required string and optional 'limit' number.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "SQL SELECT query to execute",
        },
        limit: {
          type: "number",
          description: "Maximum number of rows to return",
          default: 100,
        },
      },
      required: ["query"],
    },
  • src/index.ts:101-118 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
      name: "query_data",
      description: "Execute a SELECT query on the database",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "SQL SELECT query to execute",
          },
          limit: {
            type: "number",
            description: "Maximum number of rows to return",
            default: 100,
          },
        },
        required: ["query"],
      },
    },
  • src/index.ts:171-172 (registration)
    Dispatcher in callToolRequestHandler switch statement that routes query_data calls to the queryData handler method.
    case "query_data":
      return await this.queryData(args as { query: string; limit?: number });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose critical behavioral traits like whether this requires authentication, what happens with malformed queries, if there are rate limits, or what the return format looks like. The description is minimal and lacks operational context.

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 that directly states the tool's purpose with zero wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 insufficient. It doesn't explain what gets returned (structure, format), error conditions, or dependencies on other tools like 'connect_database'. Given the complexity of SQL execution and lack of structured metadata, more context is needed.

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?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning about parameters beyond what's in the schema (e.g., no examples of valid SQL syntax, no explanation of how limit interacts with query). Baseline 3 is appropriate when schema does the heavy lifting.

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') and target ('SELECT query on the database'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'execute_query', which appears to have overlapping functionality based on naming alone.

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 'execute_query' or 'describe_table'. It lacks any context about prerequisites (e.g., database connection status) or limitations (e.g., query types supported).

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/sam2332/mcp-quick-sqlite3'

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