Skip to main content
Glama
devopam

MCPg - Production-grade PostgreSQL MCP Server

Translate NL to SQL

translate_nl_to_sql
Read-only

Convert natural-language questions into read-only SQL queries for a given PostgreSQL schema, with optional safe execution.

Instructions

Translate a natural-language question into a read-only PostgreSQL query against schema. The LLM provider (anthropic / openai / gemini / deepseek / qwen / openrouter / perplexity, plus any operator-declared custom OpenAI-compatible provider) sees a compact brief of the schema (tables, columns, foreign keys) and is instructed to return JSON with sql and explanation. When execute=true, the generated SQL goes through the SAME safety allowlist as run_select before running — writes / DDL / multi-statement input are rejected even if the model produced them. Returns the SQL, model rationale, and (when executed) rows / columns / row_count. table_filter narrows the brief to a known subset when the question is clearly scoped. provider, when supplied, selects which configured LLM provider to call (use this to route between the configured vendors per-call when multiple are configured); when omitted, MCPg uses the default (MCPG_NL2SQL_PROVIDER, otherwise the first available in preference order anthropic → openai → gemini → deepseek → qwen → openrouter → perplexity). Call get_server_info to see which providers are configured.

Example: translate_nl_to_sql(question='top 10 customers by revenue last month', schema='public', execute=true)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYes
executeNo
databaseNoOptional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids.
max_rowsNo
providerNo
questionYes
table_filterNo
explain_preflightNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
rowsYes
errorYes
modelYes
columnsYes
refusedNo
executedYes
providerYes
row_countYes
tokens_inNo
tokens_outNo
explanationYes
refusal_reasonNo
Behavior5/5

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

Despite annotations already marking readOnlyHint=true, the description adds substantial behavioral detail: LLM provider sees a compact schema brief, returns JSON with sql/explanation, SQL passes through a safety allowlist rejecting writes/DDL/multi-statement, and return values include SQL, model rationale, and rows/columns/row_count. It also explains provider routing and default order.

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?

The description is a dense paragraph with an example, front-loaded with the core purpose and followed by specific behavior, parameter details, and a usage example. It is longer than ideal but every sentence adds value, and the structure is logical despite the lack of bullet points.

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 complex tool with 8 parameters and an output schema, the description covers the main purpose, safety constraints, provider routing, table_filter, return values, and a concrete example. It does not explain max_rows or explain_preflight, but the overall picture is complete enough for an agent to invoke the tool correctly.

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 description coverage is only 13%, but the description compensates by explaining `question`, `schema`, `execute`, `table_filter`, and `provider` (including default selection order). It does not cover `max_rows` or `explain_preflight`, but the added detail for the most important parameters is significant.

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 the tool translates a natural-language question into a read-only PostgreSQL query against a schema, with a specific verb ('Translate') and resource ('schema'). It distinguishes itself from sibling query tools by noting it uses LLM providers and the same safety allowlist as run_select.

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 provides clear context for when to use the tool (natural-language-to-SQL translation) and mentions using get_server_info to check configured providers. It also explains the execute flag and table_filter scoping, but does not explicitly exclude alternatives or state when not to use it.

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/devopam/MCPg'

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