Skip to main content
Glama
isaacgounton

SQLite MCP Server

read_query

Execute read-only SQL queries (SELECT, WITH, EXPLAIN) to fetch data from a SQLite database without modifications.

Instructions

Execute a read-only SQL query (SELECT, WITH/CTE, or EXPLAIN). Use this for fetching data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SELECT SQL query to execute

Implementation Reference

  • src/index.ts:199-209 (registration)
    Tool registration of 'read_query' with input schema requiring a 'query' string property.
    {
      name: 'read_query',
      description: 'Execute a read-only SQL query (SELECT, WITH/CTE, or EXPLAIN). Use this for fetching data.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          query: { type: 'string', description: 'The SELECT SQL query to execute' },
        },
        required: ['query'],
      },
    },
  • Handler for the 'read_query' tool: extracts the query, validates it, executes it via db.all(), and returns results as JSON text.
    case 'read_query': {
      const { query } = toolArgs as { query: string };
      validateReadQuery(query);
      const rows = db.all(query);
      return { content: [{ type: 'text', text: JSON.stringify(rows, null, 2) }] };
    }
  • Validation helper ensuring read_query only accepts SELECT, WITH, or EXPLAIN queries and rejects multiple statements.
    function validateReadQuery(query: string): void {
      const normalized = query.trim().toLowerCase();
      if (!normalized.startsWith('select') && !normalized.startsWith('with') && !normalized.startsWith('explain')) {
        throw new McpError(ErrorCode.InvalidParams, 'Only SELECT, WITH (CTE), and EXPLAIN queries are allowed for read_query');
      }
      if (queryHasMultipleStatements(query)) {
        throw new McpError(ErrorCode.InvalidParams, 'Multiple statements are not allowed');
      }
    }
  • Helper used by validateReadQuery (and others) to detect multiple SQL statements by stripping strings, comments, and checking for semicolons.
    function queryHasMultipleStatements(query: string): boolean {
      const stripped = query
        .replace(/'[^']*'/g, '')           // remove single-quoted strings
        .replace(/"[^"]*"/g, '')           // remove double-quoted identifiers
        .replace(/--[^\n]*/g, '')          // remove line comments
        .replace(/\/\*[\s\S]*?\*\//g, '')  // remove block comments
        .trim()
        .replace(/;$/, '');                // remove trailing semicolon
      return stripped.includes(';');
    }
Behavior3/5

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

No annotations were provided, so the description carries the full burden. It explicitly states 'read-only,' which is critical. However, it does not disclose any other behavioral traits like result format, error handling, or limitations, which would be helpful given no output schema.

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 two sentences long, front-loading the purpose and usage. Every sentence adds value, with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter tool with no annotations or output schema, the description provides sufficient context: read-only, allowed SQL types, and fetching purpose. It lacks details on return format but is otherwise adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema covers 100% of parameters (just 'query'). The description adds meaning by specifying allowed SQL types (SELECT, WITH/CTE, EXPLAIN), which goes beyond the schema's simple 'The SELECT SQL query to execute.'

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Execute a read-only SQL query (SELECT, WITH/CTE, or EXPLAIN). Use this for fetching data.' It specifies the verb (execute), the resource (SQL query), and the read-only scope, differentiating it from sibling write tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description says 'Use this for fetching data,' which implies usage context. It does not explicitly mention when not to use or name alternatives, but the presence of sibling tool 'write_query' provides contrast.

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/isaacgounton/sqlite-mcp-server'

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