Skip to main content

Text to SQL -- MCP Tool Specification

Version: v1.1.9 | Status: Active | Last Updated: March 2026

Overview​

This document defines the MCP tools exposed by the text_to_sql module. These tools are auto-discovered by the PAI MCP bridge via the @mcp_tool decorator in mcp_tools.py and surfaced as part of the ~303 dynamic tools available to Claude.

Auto-Discovery​

PropertyValue
Discovery method@mcp_tool decorator scan
Namespacetext_to_sql
Trust defaultSafe
PAI bridgesrc/codomyrmex/agents/pai/mcp/

Tool Reference​

text_to_sql_generate​

Description: Generate a SQL query from a natural language question. Trust Level: Safe Category: generation

Parameters:

ParameterTypeRequiredDefaultDescription
questionstrYes--Natural language question about the data
tablesdictYes--Schema dict mapping table names to column lists, e.g. {"users": ["id", "name", "email"]}
primary_keysdictNoNoneOptional dict mapping table names to primary key columns

Returns: dict -- Dictionary with query (str), confidence (float), tables_used (list), valid (bool), error (str or None).

Example:

from codomyrmex.text_to_sql.mcp_tools import text_to_sql_generate

result = text_to_sql_generate(
question="How many users signed up in 2025?",
tables={"users": ["id", "name", "email", "created_at"]},
primary_keys={"users": "id"},
)

text_to_sql_validate​

Description: Validate a SQL query for safety and basic syntax. Trust Level: Safe Category: analysis

Parameters:

ParameterTypeRequiredDefaultDescription
sqlstrYes--SQL query string to validate

Returns: dict -- Dictionary with valid (bool) and error (str or None).

Example:

from codomyrmex.text_to_sql.mcp_tools import text_to_sql_validate

result = text_to_sql_validate(sql="SELECT COUNT(*) FROM users WHERE created_at > '2025-01-01'")

Integration Notes​

  • Auto-discovered: Yes (via @mcp_tool in mcp_tools.py)
  • Trust Gateway: All tools are safe -- query generation and validation only, no execution
  • PAI Phases: BUILD (query generation), VERIFY (query validation)
  • Dependencies: Internal engine module (SQLSchema, TextToSQLEngine, SQLValidator)