Skip to main content
Glama

Generate a read-only SQL query from a question and a schema

sql_generate
Read-only

SQL from a question and a schema (CREATE TABLE statements or a JSON description of tables and columns), for postgres (default), mysql, sqlite or bigquery. The tables and columns used are checked against the schema; a query that does not match it is retried once, then refused. Writes (INSERT, UPDATE, DELETE, DDL) are refused unless allowWrite is true. The query is not run. Price: $0.003 per successful call, paid with x402 (USDC on Base, Solana and 10 more networks); failed calls are not charged.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "question": "<question>",
      "schema": "<schema>"
    },
    "name": "sql_generate"
  }
}

Input Schema

NameRequiredDescriptionDefault
schemaYesCREATE TABLE statements, or a JSON object of tables and column lists (max 20,000 characters)
dialectNopostgres (default), mysql, sqlite or bigquery
questionYesQuestion in plain language (max 1,000 characters)
allowWriteNoAllow INSERT, UPDATE, DELETE or DDL (default false)

Output Schema

NameRequiredDescriptionDefault
sqlNo
noteNo
tablesNo
columnsNo
dialectNo
readOnlyNo
checkedAtNo
explanationNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed8 schema fields changed
    • addedOutput schema / properties / checkedAt
      Added value: +{}
    • addedOutput schema / properties / columns
      Added value: +{}
    • addedOutput schema / properties / dialect
      Added value: +{}
    • addedOutput schema / properties / explanation
      Added value: +{}
    • addedOutput schema / properties / note
      Added value: +{}
    • addedOutput schema / properties / readOnly
      Added value: +{}
    • addedOutput schema / properties / sql
      Added value: +{}
    • addedOutput schema / properties / tables
      Added value: +{}
  2. Added

TDQS

A4.6/5.0
Behavior5/5

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

Beyond readOnlyHint/openWorldHint, the description discloses the validation loop (tables and columns are checked, one retry, then refusal), the write-refusal policy, the fact that no query is executed, and the exact billing model ($0.003 per successful call via x402, failures free). readOnlyHint=true is not contradicted by allowWrite because the tool only emits text and never runs it.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four dense sentences with the core purpose front-loaded and no filler, and the pricing caveat placed last where it belongs. It is compact to the point of being slightly packed, but every sentence carries information.

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

Completeness5/5

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

For a four-parameter, non-executing generator with an output schema already covering the return value, the description supplies everything an agent needs: dialects, validation/refusal semantics, write policy, execution boundary, and cost. No material gap remains.

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?

Schema coverage is already 100%, so the baseline is 3; the description earns above that by explaining the effect of allowWrite (writes are refused without it) rather than just restating its type, and by noting that the schema argument is used to validate the generated tables and columns. Dialect and question add little beyond their schema entries.

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 opening clause names the exact transformation (question + schema -> SQL) plus the supported dialects, which is enough to distinguish it from the other generate-style siblings such as regex_generate or address_parse. It also states the inputs in the same sentence, so the agent knows what it produces without opening the schema.

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?

It gives real selection context: "The query is not run" tells the agent this is a generation step, not an execution step, and the allowWrite/default-false rule says when write SQL is in scope. What is missing is an explicit pointer to the sibling that would execute the returned query, so the boundary is implied rather than routed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources